Skip to content

Commit

Permalink
chore(test): migrate to node:test (#670)
Browse files Browse the repository at this point in the history
Co-authored-by: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
aduh95 and MoLow committed Mar 20, 2023
1 parent 92d621e commit cc4b11c
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 24 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run coverage-all
if: matrix.node-version == '16.x'
run: npm run test-unit
- name: Run tests
if: matrix.node-version != '16.x'
run: npm run coverage:ci
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v3
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
},
"scripts": {
"test": "npm run test-unit && npm run lint",
"test-unit": "mocha --timeout 60000 test/unit/*.test.js --exit",
"test-all": "mocha --timeout 60000 test/**/*.test.js --exit",
"test-unit": "node --test test/unit",
"test:reporters": "node --test --test-reporter=spec --test-reporter-destination=stdout --test-reporter=@reporters/github --test-reporter-destination=stdout test/unit",
"coverage": "c8 --reporter=html --reporter=text --reporter=text-summary npm test",
"coverage-all": "c8 --reporter=lcov --reporter=text --reporter=text-summary npm run test-all",
"coverage:ci": "c8 --reporter=lcov --reporter=text --reporter=text-summary npm run test:reporters",
"lint": "eslint . --cache",
"lint-fix": "eslint . --fix"
},
Expand Down Expand Up @@ -55,13 +55,13 @@
"yargs": "^17.7.1"
},
"devDependencies": {
"@reporters/github": "^1.1.2",
"c8": "^7.13.0",
"eslint": "^8.35.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^10.2.0",
"sinon": "^15.0.1"
}
}
6 changes: 0 additions & 6 deletions test/.eslintrc

This file was deleted.

13 changes: 1 addition & 12 deletions test/unit/auth.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import { spawn } from 'node:child_process';
import path from 'node:path';
import fs from 'node:fs';
Expand All @@ -18,39 +19,34 @@ const MOCKED_TOKEN = JSON.stringify({

describe('auth', async function() {
it('asks for auth data if no ncurc is found', async function() {
this.timeout(2000);
await runAuthScript(
undefined,
[FIRST_TIME_MSG, MOCKED_TOKEN]
);
});

it('asks for auth data if ncurc is invalid json', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: 'this is not json' },
[FIRST_TIME_MSG, MOCKED_TOKEN]
);
});

it('returns ncurc data if valid in HOME', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789abcdef' } },
[MOCKED_TOKEN]
);
});

it('returns ncurc data if valid in XDG_CONFIG_HOME', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789abcdef' } },
[MOCKED_TOKEN]
);
});

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

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

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

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

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

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

it('permits capital letters in token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: '0123456789ABCDEF' } },
['{"github":"bnlhbmNhdDowMTIzNDU2Nzg5QUJDREVG"}']
);
});

it('permits underscores in token format', async function() {
this.timeout(2000);
await runAuthScript(
{ HOME: { username: 'nyancat', token: 'ghp_0123456789ABCDEF' } },
['{"github":"bnlhbmNhdDpnaHBfMDEyMzQ1Njc4OUFCQ0RFRg=="}']
Expand Down
1 change: 1 addition & 0 deletions test/unit/cache.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import path from 'node:path';
import fs from 'node:fs';
import assert from 'node:assert';
Expand Down
1 change: 1 addition & 0 deletions test/unit/ci_failure_parser.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import CIFailureParser from '../../lib/ci/ci_failure_parser.js';
Expand Down
1 change: 1 addition & 0 deletions test/unit/ci_result_parser.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
Expand Down
1 change: 1 addition & 0 deletions test/unit/ci_start.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, before } from 'node:test';
import assert from 'assert';

import sinon from 'sinon';
Expand Down
1 change: 1 addition & 0 deletions test/unit/ci_type_parser.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import {
Expand Down
40 changes: 39 additions & 1 deletion test/unit/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, beforeEach, afterEach } from 'node:test';
import assert from 'node:assert';

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

describe('spinners', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
cli.startSpinner('foo');
});

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

describe('write', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should write in stream', () => {
const stream = new LogStream();
const cli = new CLI(stream);
cli.write('Getting commits...');
assert.strictEqual(logResult(), 'Getting commits...');
assert.strictEqual(strip(stream.toString()), 'Getting commits...');
});
});

describe('log', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should write in stream', () => {
cli.log('Getting commits...');
assert.strictEqual(logResult(), 'Getting commits...\n');
});
});

describe('table', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print the first element with bold style and padding', () => {
cli.table('Title', 'description');
assert.strictEqual(logResult(),
Expand All @@ -80,6 +97,10 @@ describe('cli', () => {
});

describe('separator', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print a separator line with the specified text', () => {
cli.separator('Separator');
assert.strictEqual(
Expand All @@ -105,6 +126,10 @@ describe('cli', () => {
});

describe('ok', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print a success message', () => {
cli.ok('Perfect!');
assert.strictEqual(logResult(), ` ${success} Perfect!\n`);
Expand All @@ -118,6 +143,10 @@ describe('cli', () => {
});

describe('warn', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print a warning message', () => {
cli.warn('Warning!');
assert.strictEqual(logResult(), ` ${warning} Warning!\n`);
Expand All @@ -131,6 +160,10 @@ describe('cli', () => {
});

describe('info', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print an info message', () => {
cli.info('Info!');
assert.strictEqual(logResult(), ` ${info} Info!\n`);
Expand All @@ -143,6 +176,10 @@ describe('cli', () => {
});

describe('error', () => {
beforeEach(() => {
stream = new LogStream();
cli = new CLI(stream);
});
it('should print an error message', () => {
cli.error('Error!');
assert.strictEqual(logResult(), ` ${error} Error!\n`);
Expand Down Expand Up @@ -183,6 +220,7 @@ describe('cli', () => {
questionType: cli.QUESTION_TYPE.INPUT
});
assert.strictEqual(cli.spinner.isSpinning, true);
cli.stopSpinner('foo');
});
});

Expand Down
1 change: 1 addition & 0 deletions test/unit/collaborators.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, beforeEach } from 'node:test';
import { fileURLToPath } from 'node:url';
import assert from 'node:assert';

Expand Down
1 change: 1 addition & 0 deletions test/unit/comp.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import { ascending, descending } from '../../lib/utils.js';
Expand Down
1 change: 1 addition & 0 deletions test/unit/links.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import { LinkParser, parsePRFromURL } from '../../lib/links.js';
Expand Down
1 change: 1 addition & 0 deletions test/unit/metadata_gen.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import MetadataGenerator from '../../lib/metadata_gen.js';
Expand Down
1 change: 1 addition & 0 deletions test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, before, after, afterEach } from 'node:test';
import assert from 'node:assert';

import sinon from 'sinon';
Expand Down
1 change: 1 addition & 0 deletions test/unit/pr_data.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import sinon from 'sinon';
Expand Down
1 change: 1 addition & 0 deletions test/unit/pr_summary.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import PRSummary from '../../lib/pr_summary.js';

import {
Expand Down
1 change: 1 addition & 0 deletions test/unit/prepare_release.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { readFileSync } from 'node:fs';

Expand Down
1 change: 1 addition & 0 deletions test/unit/reviews.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import { ReviewAnalyzer } from '../../lib/reviews.js';
Expand Down
1 change: 1 addition & 0 deletions test/unit/team_info.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, before, after } from 'node:test';
import assert from 'node:assert';

import sinon from 'sinon';
Expand Down

0 comments on commit cc4b11c

Please sign in to comment.