mirror of
https://code.forgejo.org/actions/setup-node
synced 2025-06-21 02:48:00 +02:00
Refactor and test
This commit is contained in:
parent
473cb1b506
commit
55b7d827be
2 changed files with 25 additions and 2 deletions
|
@ -7,6 +7,7 @@ import * as auth from '../src/authutil';
|
|||
import * as cacheUtils from '../src/cache-utils';
|
||||
|
||||
let rcFile: string;
|
||||
let pkgJson: string;
|
||||
|
||||
describe('authutil tests', () => {
|
||||
const _runnerDir = path.join(__dirname, 'runner');
|
||||
|
@ -25,10 +26,12 @@ describe('authutil tests', () => {
|
|||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||
process.env['RUNNER_TEMP'] = tempDir;
|
||||
rcFile = path.join(tempDir, '.npmrc');
|
||||
pkgJson = path.join(tempDir, 'package.json');
|
||||
}, 100000);
|
||||
|
||||
beforeEach(async () => {
|
||||
await io.rmRF(rcFile);
|
||||
await io.rmRF(pkgJson);
|
||||
// if (fs.existsSync(rcFile)) {
|
||||
// fs.unlinkSync(rcFile);
|
||||
// }
|
||||
|
@ -113,6 +116,15 @@ describe('authutil tests', () => {
|
|||
expect(rc['always-auth']).toBe('false');
|
||||
});
|
||||
|
||||
it('Automatically configures npm scope from package.json', async () => {
|
||||
process.env['INPUT_SCOPE'] = '';
|
||||
fs.writeFileSync(pkgJson, '{"name":"@myscope/mypackage"}');
|
||||
await auth.configAuthentication('https://registry.npmjs.org', '');
|
||||
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/');
|
||||
});
|
||||
|
||||
it('Sets up npmrc for always-auth true', async () => {
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue