Skip to content

Commit 8885b71

Browse files
updated tests
1 parent ecf0ce6 commit 8885b71

13 files changed

Lines changed: 4815 additions & 979 deletions

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Jest Tests on Nix",
9+
"type": "node",
10+
"request": "launch",
11+
"runtimeArgs": [
12+
"--inspect-brk",
13+
"${workspaceRoot}/node_modules/.bin/jest",
14+
"--runInBand"
15+
],
16+
"console": "integratedTerminal",
17+
"internalConsoleOptions": "neverOpen",
18+
"port": 9229
19+
}
20+
]
21+
}

__tests__/__snapshots__/authutil.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`installer tests Appends trailing slash to registry 1`] = `
3+
exports[`authutil tests Appends trailing slash to registry 1`] = `
44
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
55
registry=https://registry.npmjs.org/
66
always-auth=false"
77
`;
88

9-
exports[`installer tests Automatically configures GPR scope 1`] = `
9+
exports[`authutil tests Automatically configures GPR scope 1`] = `
1010
"npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}
1111
@ownername:registry=npm.pkg.github.com/
1212
always-auth=false"
1313
`;
1414

15-
exports[`installer tests Configures scoped npm registries 1`] = `
15+
exports[`authutil tests Configures scoped npm registries 1`] = `
1616
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
1717
@myscope:registry=https://registry.npmjs.org/
1818
always-auth=false"
1919
`;
2020

21-
exports[`installer tests Sets up npmrc for always-auth true 1`] = `
21+
exports[`authutil tests Sets up npmrc for always-auth true 1`] = `
2222
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
2323
registry=https://registry.npmjs.org/
2424
always-auth=true"
2525
`;
2626

27-
exports[`installer tests Sets up npmrc for npmjs 1`] = `
27+
exports[`authutil tests Sets up npmrc for npmjs 1`] = `
2828
"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}
2929
registry=https://registry.npmjs.org/
3030
always-auth=false"

__tests__/authutil.test.ts

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,95 @@
1-
import * as io from '@actions/io';
21
import * as fs from 'fs';
32
import * as path from 'path';
3+
import * as core from '@actions/core';
4+
import * as io from '@actions/io';
45
import * as auth from '../src/authutil';
56

67
let rcFile: string;
78

8-
describe('installer tests', () => {
9+
describe('authutil tests', () => {
10+
const _runnerDir = path.join(__dirname, 'runner');
11+
12+
let cnSpy: jest.SpyInstance;
13+
let logSpy: jest.SpyInstance;
14+
let dbgSpy: jest.SpyInstance;
15+
916
beforeAll(async () => {
10-
const tempDir = path.join(
11-
__dirname,
12-
'runner',
13-
path.join(
14-
Math.random()
15-
.toString(36)
16-
.substring(7)
17-
),
18-
'temp'
17+
const randPath = path.join(
18+
Math.random()
19+
.toString(36)
20+
.substring(7)
1921
);
22+
const tempDir = path.join(_runnerDir, randPath, 'temp');
2023
await io.rmRF(tempDir);
2124
await io.mkdirP(tempDir);
2225
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
2326
process.env['RUNNER_TEMP'] = tempDir;
2427
rcFile = path.join(tempDir, '.npmrc');
2528
}, 100000);
2629

27-
beforeEach(() => {
28-
if (fs.existsSync(rcFile)) {
29-
fs.unlinkSync(rcFile);
30-
}
30+
beforeEach(async () => {
31+
await io.rmRF(rcFile);
32+
// if (fs.existsSync(rcFile)) {
33+
// fs.unlinkSync(rcFile);
34+
// }
3135
process.env['INPUT_SCOPE'] = '';
32-
});
36+
37+
// writes
38+
cnSpy = jest.spyOn(process.stdout, 'write');
39+
logSpy = jest.spyOn(console, 'log');
40+
dbgSpy = jest.spyOn(core, 'debug');
41+
cnSpy.mockImplementation(line => {
42+
// uncomment to debug
43+
// process.stderr.write('write:' + line + '\n');
44+
});
45+
logSpy.mockImplementation(line => {
46+
// uncomment to debug
47+
// process.stderr.write('log:' + line + '\n');
48+
});
49+
dbgSpy.mockImplementation(msg => {
50+
// uncomment to see debug output
51+
// process.stderr.write(msg + '\n');
52+
});
53+
}, 100000);
54+
55+
afterAll(async () => {
56+
if (_runnerDir) {
57+
await io.rmRF(_runnerDir);
58+
}
59+
}, 100000);
3360

3461
it('Sets up npmrc for npmjs', async () => {
3562
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
36-
expect(fs.existsSync(rcFile)).toBe(true);
63+
64+
expect(fs.statSync(rcFile)).toBeDefined();
3765
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
3866
});
3967

4068
it('Appends trailing slash to registry', async () => {
4169
await auth.configAuthentication('https://registry.npmjs.org', 'false');
4270

43-
expect(fs.existsSync(rcFile)).toBe(true);
71+
expect(fs.statSync(rcFile)).toBeDefined();
4472
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
4573
});
4674

4775
it('Configures scoped npm registries', async () => {
4876
process.env['INPUT_SCOPE'] = 'myScope';
4977
await auth.configAuthentication('https://registry.npmjs.org', 'false');
5078

51-
expect(fs.existsSync(rcFile)).toBe(true);
79+
expect(fs.statSync(rcFile)).toBeDefined();
5280
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
5381
});
5482

5583
it('Automatically configures GPR scope', async () => {
5684
await auth.configAuthentication('npm.pkg.github.com', 'false');
5785

58-
expect(fs.existsSync(rcFile)).toBe(true);
86+
expect(fs.statSync(rcFile)).toBeDefined();
5987
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
6088
});
6189

6290
it('Sets up npmrc for always-auth true', async () => {
6391
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
64-
expect(fs.existsSync(rcFile)).toBe(true);
92+
expect(fs.statSync(rcFile)).toBeDefined();
6593
expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot();
6694
});
6795
});

0 commit comments

Comments
 (0)