Skip to content

Commit cc4b11c

Browse files
aduh95MoLow
andauthored
chore(test): migrate to node:test (#670)
Co-authored-by: Moshe Atlow <[email protected]>
1 parent 92d621e commit cc4b11c

20 files changed

+65
-24
lines changed

.github/workflows/nodejs.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ jobs:
3535
uses: actions/setup-node@v3
3636
with:
3737
node-version: ${{ matrix.node-version }}
38+
check-latest: true
3839
- name: Install dependencies
3940
run: npm install
4041
- name: Run tests
41-
run: npm run coverage-all
42+
if: matrix.node-version == '16.x'
43+
run: npm run test-unit
44+
- name: Run tests
45+
if: matrix.node-version != '16.x'
46+
run: npm run coverage:ci
4247
- name: Upload coverage report to Codecov
4348
uses: codecov/codecov-action@v3

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
},
1616
"scripts": {
1717
"test": "npm run test-unit && npm run lint",
18-
"test-unit": "mocha --timeout 60000 test/unit/*.test.js --exit",
19-
"test-all": "mocha --timeout 60000 test/**/*.test.js --exit",
18+
"test-unit": "node --test test/unit",
19+
"test:reporters": "node --test --test-reporter=spec --test-reporter-destination=stdout --test-reporter=@reporters/github --test-reporter-destination=stdout test/unit",
2020
"coverage": "c8 --reporter=html --reporter=text --reporter=text-summary npm test",
21-
"coverage-all": "c8 --reporter=lcov --reporter=text --reporter=text-summary npm run test-all",
21+
"coverage:ci": "c8 --reporter=lcov --reporter=text --reporter=text-summary npm run test:reporters",
2222
"lint": "eslint . --cache",
2323
"lint-fix": "eslint . --fix"
2424
},
@@ -55,13 +55,13 @@
5555
"yargs": "^17.7.1"
5656
},
5757
"devDependencies": {
58+
"@reporters/github": "^1.1.2",
5859
"c8": "^7.13.0",
5960
"eslint": "^8.35.0",
6061
"eslint-config-standard": "^17.0.0",
6162
"eslint-plugin-import": "^2.27.5",
6263
"eslint-plugin-n": "^15.6.1",
6364
"eslint-plugin-promise": "^6.1.1",
64-
"mocha": "^10.2.0",
6565
"sinon": "^15.0.1"
6666
}
6767
}

test/.eslintrc

-6
This file was deleted.

test/unit/auth.test.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import { spawn } from 'node:child_process';
23
import path from 'node:path';
34
import fs from 'node:fs';
@@ -18,39 +19,34 @@ const MOCKED_TOKEN = JSON.stringify({
1819

1920
describe('auth', async function() {
2021
it('asks for auth data if no ncurc is found', async function() {
21-
this.timeout(2000);
2222
await runAuthScript(
2323
undefined,
2424
[FIRST_TIME_MSG, MOCKED_TOKEN]
2525
);
2626
});
2727

2828
it('asks for auth data if ncurc is invalid json', async function() {
29-
this.timeout(2000);
3029
await runAuthScript(
3130
{ HOME: 'this is not json' },
3231
[FIRST_TIME_MSG, MOCKED_TOKEN]
3332
);
3433
});
3534

3635
it('returns ncurc data if valid in HOME', async function() {
37-
this.timeout(2000);
3836
await runAuthScript(
3937
{ HOME: { username: 'nyancat', token: '0123456789abcdef' } },
4038
[MOCKED_TOKEN]
4139
);
4240
});
4341

4442
it('returns ncurc data if valid in XDG_CONFIG_HOME', async function() {
45-
this.timeout(2000);
4643
await runAuthScript(
4744
{ HOME: { username: 'nyancat', token: '0123456789abcdef' } },
4845
[MOCKED_TOKEN]
4946
);
5047
});
5148

5249
it('prefers XDG_CONFIG_HOME/ncurc to HOME/.ncurc', async function() {
53-
this.timeout(2000);
5450
await runAuthScript(
5551
{
5652
HOME: { username: 'notnyancat', token: 'somewrongtoken' },
@@ -61,7 +57,6 @@ describe('auth', async function() {
6157
});
6258

6359
it("prints an error message if it can't generate a token", async function() {
64-
this.timeout(2000);
6560
await runAuthScript(
6661
{},
6762
[FIRST_TIME_MSG],
@@ -70,7 +65,6 @@ describe('auth', async function() {
7065
});
7166

7267
it('does not accept a non-string username', async function() {
73-
this.timeout(2000);
7468
await runAuthScript(
7569
{ HOME: { username: {}, token: '0123456789abcdef' } },
7670
[],
@@ -79,7 +73,6 @@ describe('auth', async function() {
7973
});
8074

8175
it('does not accept a non-string token', async function() {
82-
this.timeout(2000);
8376
await runAuthScript(
8477
{ HOME: { username: 'nyancat', token: 42 } },
8578
[],
@@ -88,7 +81,6 @@ describe('auth', async function() {
8881
});
8982

9083
it('does not accept an invalid username format', async function() {
91-
this.timeout(2000);
9284
await runAuthScript(
9385
{ HOME: { username: ' ^^^ ', token: '0123456789abcdef' } },
9486
[],
@@ -98,7 +90,6 @@ describe('auth', async function() {
9890
});
9991

10092
it('does not accept an invalid token format', async function() {
101-
this.timeout(2000);
10293
await runAuthScript(
10394
{ HOME: { username: 'nyancat', token: '@fhqwhgads' } },
10495
[],
@@ -107,15 +98,13 @@ describe('auth', async function() {
10798
});
10899

109100
it('permits capital letters in token format', async function() {
110-
this.timeout(2000);
111101
await runAuthScript(
112102
{ HOME: { username: 'nyancat', token: '0123456789ABCDEF' } },
113103
['{"github":"bnlhbmNhdDowMTIzNDU2Nzg5QUJDREVG"}']
114104
);
115105
});
116106

117107
it('permits underscores in token format', async function() {
118-
this.timeout(2000);
119108
await runAuthScript(
120109
{ HOME: { username: 'nyancat', token: 'ghp_0123456789ABCDEF' } },
121110
['{"github":"bnlhbmNhdDpnaHBfMDEyMzQ1Njc4OUFCQ0RFRg=="}']

test/unit/cache.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import path from 'node:path';
23
import fs from 'node:fs';
34
import assert from 'node:assert';

test/unit/ci_failure_parser.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23

34
import CIFailureParser from '../../lib/ci/ci_failure_parser.js';

test/unit/ci_result_parser.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23
import { fileURLToPath } from 'node:url';
34
import path from 'node:path';

test/unit/ci_start.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, before } from 'node:test';
12
import assert from 'assert';
23

34
import sinon from 'sinon';

test/unit/ci_type_parser.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23

34
import {

test/unit/cli.test.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, beforeEach, afterEach } from 'node:test';
12
import assert from 'node:assert';
23

34
import CLI from '../../lib/cli.js';
@@ -40,6 +41,8 @@ describe('cli', () => {
4041

4142
describe('spinners', () => {
4243
beforeEach(() => {
44+
stream = new LogStream();
45+
cli = new CLI(stream);
4346
cli.startSpinner('foo');
4447
});
4548

@@ -58,20 +61,34 @@ describe('cli', () => {
5861
});
5962

6063
describe('write', () => {
64+
beforeEach(() => {
65+
stream = new LogStream();
66+
cli = new CLI(stream);
67+
});
6168
it('should write in stream', () => {
69+
const stream = new LogStream();
70+
const cli = new CLI(stream);
6271
cli.write('Getting commits...');
63-
assert.strictEqual(logResult(), 'Getting commits...');
72+
assert.strictEqual(strip(stream.toString()), 'Getting commits...');
6473
});
6574
});
6675

6776
describe('log', () => {
77+
beforeEach(() => {
78+
stream = new LogStream();
79+
cli = new CLI(stream);
80+
});
6881
it('should write in stream', () => {
6982
cli.log('Getting commits...');
7083
assert.strictEqual(logResult(), 'Getting commits...\n');
7184
});
7285
});
7386

7487
describe('table', () => {
88+
beforeEach(() => {
89+
stream = new LogStream();
90+
cli = new CLI(stream);
91+
});
7592
it('should print the first element with bold style and padding', () => {
7693
cli.table('Title', 'description');
7794
assert.strictEqual(logResult(),
@@ -80,6 +97,10 @@ describe('cli', () => {
8097
});
8198

8299
describe('separator', () => {
100+
beforeEach(() => {
101+
stream = new LogStream();
102+
cli = new CLI(stream);
103+
});
83104
it('should print a separator line with the specified text', () => {
84105
cli.separator('Separator');
85106
assert.strictEqual(
@@ -105,6 +126,10 @@ describe('cli', () => {
105126
});
106127

107128
describe('ok', () => {
129+
beforeEach(() => {
130+
stream = new LogStream();
131+
cli = new CLI(stream);
132+
});
108133
it('should print a success message', () => {
109134
cli.ok('Perfect!');
110135
assert.strictEqual(logResult(), ` ${success} Perfect!\n`);
@@ -118,6 +143,10 @@ describe('cli', () => {
118143
});
119144

120145
describe('warn', () => {
146+
beforeEach(() => {
147+
stream = new LogStream();
148+
cli = new CLI(stream);
149+
});
121150
it('should print a warning message', () => {
122151
cli.warn('Warning!');
123152
assert.strictEqual(logResult(), ` ${warning} Warning!\n`);
@@ -131,6 +160,10 @@ describe('cli', () => {
131160
});
132161

133162
describe('info', () => {
163+
beforeEach(() => {
164+
stream = new LogStream();
165+
cli = new CLI(stream);
166+
});
134167
it('should print an info message', () => {
135168
cli.info('Info!');
136169
assert.strictEqual(logResult(), ` ${info} Info!\n`);
@@ -143,6 +176,10 @@ describe('cli', () => {
143176
});
144177

145178
describe('error', () => {
179+
beforeEach(() => {
180+
stream = new LogStream();
181+
cli = new CLI(stream);
182+
});
146183
it('should print an error message', () => {
147184
cli.error('Error!');
148185
assert.strictEqual(logResult(), ` ${error} Error!\n`);
@@ -183,6 +220,7 @@ describe('cli', () => {
183220
questionType: cli.QUESTION_TYPE.INPUT
184221
});
185222
assert.strictEqual(cli.spinner.isSpinning, true);
223+
cli.stopSpinner('foo');
186224
});
187225
});
188226

test/unit/collaborators.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, beforeEach } from 'node:test';
12
import { fileURLToPath } from 'node:url';
23
import assert from 'node:assert';
34

test/unit/comp.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23

34
import { ascending, descending } from '../../lib/utils.js';

test/unit/links.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23

34
import { LinkParser, parsePRFromURL } from '../../lib/links.js';

test/unit/metadata_gen.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23

34
import MetadataGenerator from '../../lib/metadata_gen.js';

test/unit/pr_checker.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, before, after, afterEach } from 'node:test';
12
import assert from 'node:assert';
23

34
import sinon from 'sinon';

test/unit/pr_data.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23

34
import sinon from 'sinon';

test/unit/pr_summary.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import PRSummary from '../../lib/pr_summary.js';
23

34
import {

test/unit/prepare_release.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23
import { readFileSync } from 'node:fs';
34

test/unit/reviews.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it } from 'node:test';
12
import assert from 'node:assert';
23

34
import { ReviewAnalyzer } from '../../lib/reviews.js';

test/unit/team_info.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, before, after } from 'node:test';
12
import assert from 'node:assert';
23

34
import sinon from 'sinon';

0 commit comments

Comments
 (0)