From 8dde5bc0043686bf55f5e243c3756c418eb90398 Mon Sep 17 00:00:00 2001 From: Andres Vargas Date: Wed, 21 Oct 2020 18:14:34 -0500 Subject: [PATCH] adding test for NODE_AUTH_TOKEN overwritten --- __tests__/authutil.test.ts | 13 ++++++++++++- src/authutil.ts | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/__tests__/authutil.test.ts b/__tests__/authutil.test.ts index a57a3171..963ab8ff 100644 --- a/__tests__/authutil.test.ts +++ b/__tests__/authutil.test.ts @@ -122,5 +122,16 @@ describe('authutil tests', () => { let rc = readRcFile(rcFile); expect(rc['registry']).toBe('https://registry.npmjs.org/'); expect(rc['always-auth']).toBe('true'); - }); + }) + it('It is already set the NODE_AUTH_TOKEN export it ', async ()=> { + process.env.NODE_AUTH_TOKEN='foobar'; + await auth.configAuthentication('npm.pkg.github.com', 'false'); + expect(fs.statSync(rcFile)).toBeDefined(); + let rc = readRcFile(rcFile); + expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/'); + expect(rc['always-auth']).toBe('false'); + dbg(`${JSON.stringify(rc)}`); + expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar'); + + }) }); diff --git a/src/authutil.ts b/src/authutil.ts index 07e0b24c..fe7775a8 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -54,5 +54,5 @@ function writeRegistryToFile( fs.writeFileSync(fileLocation, newContents); core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); // Export empty node_auth_token so npm doesn't complain about not being able to find it - core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX'); + core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'); }