Skip to content

Commit 03b36f3

Browse files
committed
Add unit tests
1 parent d9d1b64 commit 03b36f3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

__tests__/authutil.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ describe('authutil tests', () => {
123123
expect(rc['registry']).toBe('https://registry.npmjs.org/');
124124
expect(rc['always-auth']).toBe('true');
125125
});
126+
126127
it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
127128
process.env.NODE_AUTH_TOKEN = 'foobar';
128129
await auth.configAuthentication('npm.pkg.github.com', 'false');
@@ -132,4 +133,29 @@ describe('authutil tests', () => {
132133
expect(rc['always-auth']).toBe('false');
133134
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
134135
});
136+
137+
it('configAuthentication should overwrite non-scoped registry', async () => {
138+
fs.writeFileSync(rcFile, 'registry=NNN');
139+
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
140+
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
141+
expect(contents).toContain('registry=https://registry.npmjs.org/');
142+
});
143+
144+
it('configAuthentication should overwrite non-scoped registry', async () => {
145+
fs.writeFileSync(rcFile, 'registry=NNN');
146+
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
147+
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
148+
expect(contents).toContain('registry=https://registry.npmjs.org/');
149+
expect(contents).not.toContain('registry=NNN');
150+
});
151+
152+
it('configAuthentication should overwrite scoped registry', async () => {
153+
process.env['INPUT_SCOPE'] = 'myScope';
154+
fs.writeFileSync(rcFile, `registry=MMM${os.EOL}@myscope:registry=NNN`);
155+
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
156+
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
157+
expect(contents).toContain('registry=MMM');
158+
expect(contents).toContain('@myscope:registry=https://registry.npmjs.org/');
159+
expect(contents).not.toContain('@myscope:registry=NNN');
160+
});
135161
});

0 commit comments

Comments
 (0)