2020-03-10 15:51:57 +00:00
|
|
|
import * as io from '@actions/io';
|
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as path from 'path';
|
2019-08-06 23:26:04 +01:00
|
|
|
import * as auth from '../src/authutil';
|
|
|
|
|
2020-03-10 15:51:57 +00:00
|
|
|
let rcFile: string;
|
|
|
|
|
2019-08-06 23:26:04 +01:00
|
|
|
describe('installer tests', () => {
|
|
|
|
beforeAll(async () => {
|
2020-03-10 15:51:57 +00:00
|
|
|
const tempDir = path.join(
|
|
|
|
__dirname,
|
|
|
|
'runner',
|
|
|
|
path.join(
|
|
|
|
Math.random()
|
|
|
|
.toString(36)
|
|
|
|
.substring(7)
|
|
|
|
),
|
|
|
|
'temp'
|
|
|
|
);
|
2019-08-06 23:26:04 +01:00
|
|
|
await io.rmRF(tempDir);
|
|
|
|
await io.mkdirP(tempDir);
|
2020-03-10 15:51:57 +00:00
|
|
|
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
|
|
|
process.env['RUNNER_TEMP'] = tempDir;
|
|
|
|
rcFile = path.join(tempDir, '.npmrc');
|
2019-08-06 23:26:04 +01:00
|
|
|
}, 100000);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
if (fs.existsSync(rcFile)) {
|
|
|
|
fs.unlinkSync(rcFile);
|
|
|
|
}
|
|
|
|
process.env['INPUT_SCOPE'] = '';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Sets up npmrc for npmjs', async () => {
|
2019-09-03 15:57:45 +01:00
|
|
|
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
|
2019-08-06 23:26:04 +01:00
|
|
|
expect(fs.existsSync(rcFile)).toBe(true);
|
|
|
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Appends trailing slash to registry', async () => {
|
2019-09-03 15:57:45 +01:00
|
|
|
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
2019-08-06 23:26:04 +01:00
|
|
|
|
|
|
|
expect(fs.existsSync(rcFile)).toBe(true);
|
|
|
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Configures scoped npm registries', async () => {
|
|
|
|
process.env['INPUT_SCOPE'] = 'myScope';
|
2019-09-03 15:57:45 +01:00
|
|
|
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
2019-08-06 23:26:04 +01:00
|
|
|
|
|
|
|
expect(fs.existsSync(rcFile)).toBe(true);
|
|
|
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Automatically configures GPR scope', async () => {
|
2019-09-03 15:57:45 +01:00
|
|
|
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
2019-08-06 23:26:04 +01:00
|
|
|
|
|
|
|
expect(fs.existsSync(rcFile)).toBe(true);
|
|
|
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
|
|
|
});
|
2019-09-03 15:57:45 +01:00
|
|
|
|
|
|
|
it('Sets up npmrc for always-auth true', async () => {
|
|
|
|
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
|
|
|
expect(fs.existsSync(rcFile)).toBe(true);
|
|
|
|
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
|
|
|
|
});
|
2019-08-06 23:26:04 +01:00
|
|
|
});
|