Skip to content

Commit 8dde5bc

Browse files
committed
adding test for NODE_AUTH_TOKEN overwritten
1 parent c6fd00c commit 8dde5bc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

__tests__/authutil.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,16 @@ describe('authutil tests', () => {
122122
let rc = readRcFile(rcFile);
123123
expect(rc['registry']).toBe('https://registry.npmjs.org/');
124124
expect(rc['always-auth']).toBe('true');
125-
});
125+
})
126+
it('It is already set the NODE_AUTH_TOKEN export it ', async ()=> {
127+
process.env.NODE_AUTH_TOKEN='foobar';
128+
await auth.configAuthentication('npm.pkg.github.com', 'false');
129+
expect(fs.statSync(rcFile)).toBeDefined();
130+
let rc = readRcFile(rcFile);
131+
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
132+
expect(rc['always-auth']).toBe('false');
133+
dbg(`${JSON.stringify(rc)}`);
134+
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
135+
136+
})
126137
});

src/authutil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ function writeRegistryToFile(
5454
fs.writeFileSync(fileLocation, newContents);
5555
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
5656
// Export empty node_auth_token so npm doesn't complain about not being able to find it
57-
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
57+
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX');
5858
}

0 commit comments

Comments
 (0)