Skip to content

Commit c30effd

Browse files
authored
migrate mocha to node:test (#565)
1 parent 2c39bf9 commit c30effd

File tree

4 files changed

+27
-49
lines changed

4 files changed

+27
-49
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
{
2323
"type": "node",
2424
"request": "launch",
25-
"name": "Mocha Tests",
26-
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
25+
"name": "Node Tests",
26+
"runtimeArgs": ["--enable-source-maps", "--test", "test/*.mjs"],
2727
"cwd": "${workspaceFolder}",
2828
"console": "integratedTerminal",
2929
"internalConsoleOptions": "openOnSessionStart"

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,21 @@
2929
"node": ">=20.5.0"
3030
},
3131
"scripts": {
32-
"test": "mocha",
32+
"test": "node --enable-source-maps --test test/*.mjs",
3333
"prepublishOnly": "npm test",
3434
"preversion": "npm test",
3535
"postversion": "git push && git push --tags"
3636
},
3737
"dependencies": {
38-
"chalk": "^5.6.2",
3938
"fast-plist": "^0.1.3",
4039
"request-light": "^0.8.0",
4140
"which": "^6.0.1",
42-
"yeoman-generator": "^7.5.1",
4341
"yosay": "^3.0.0"
4442
},
4543
"devDependencies": {
46-
"@types/mocha": "^10.0.10",
4744
"@types/node": "^20.x",
4845
"@yeoman/adapter": "^3.1.1",
4946
"jsonc-parser": "^3.3.1",
50-
"mocha": "^11.7.5",
5147
"yeoman-environment": "^5.1.3",
5248
"yeoman-test": "^11.2.0"
5349
}

test/test-integration.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import * as path from 'path';
66
import { createHelpers } from 'yeoman-test';
77
import * as cp from 'child_process';
8+
import { describe, it } from 'node:test';
89

9-
import * as assert from 'assert';
10+
import * as assert from 'node:assert';
1011

1112
import { fileURLToPath } from 'url';
1213

13-
describe('integration tests', function () {
14-
this.timeout(7 * 60 * 1000);
14+
describe('integration tests', { timeout: 7 * 60 * 1000 }, () => {
1515

1616
const helpers = createHelpers();
1717
const appLocation = path.join(fileURLToPath(import.meta.url), '../../generators/app');
@@ -25,7 +25,7 @@ describe('integration tests', function () {
2525
if (resAudit.stdout.indexOf('https://github.com/advisories/GHSA-73rr-hh4g-fpgx') === -1) { // diff vulnerability
2626
assert.fail(`npm audit failed: stdout ${resAudit.stdout} stderr ${resAudit.stderr}`);
2727
} else {
28-
console.warn('npm audit vulnerability for `diff` ignored for now, waiting for a mocha update');
28+
console.warn('npm audit vulnerability for `diff` ignored for now, waiting for a dependency update');
2929
}
3030
}
3131
}

test/test.mjs

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import * as path from 'path';
66
import { fileURLToPath } from 'url';
7+
import { before, describe, it } from 'node:test';
78
import { createHelpers } from 'yeoman-test';
89
import { parse } from 'jsonc-parser';
910
import * as env from '../generators/app/env.js';
1011

11-
describe('test code generator', function () {
12-
this.timeout(10000);
12+
describe('test code generator', { timeout: 10000 }, () => {
1313

1414
const helpers = createHelpers();
1515
const appLocation = path.join(fileURLToPath(import.meta.url), '../../generators/app');
@@ -275,8 +275,7 @@ describe('test code generator', function () {
275275
}
276276
});
277277

278-
it('language import', async () => {
279-
this.timeout(10000);
278+
it('language import', { timeout: 10000 }, async () => {
280279

281280
const runResult = await helpers.run(appLocation).withAnswers({
282281
type: 'ext-language',
@@ -327,8 +326,7 @@ describe('test code generator', function () {
327326
}
328327
});
329328

330-
it('language import 2', async () => {
331-
this.timeout(10000);
329+
it('language import 2', { timeout: 10000 }, async () => {
332330

333331
const runResult = await helpers.run(appLocation).withAnswers({
334332
type: 'ext-language',
@@ -379,8 +377,7 @@ describe('test code generator', function () {
379377
}
380378
});
381379

382-
it('language new', async () => {
383-
this.timeout(10000);
380+
it('language new', { timeout: 10000 }, async () => {
384381

385382
const runResult = await helpers.run(appLocation).withAnswers({
386383
type: 'ext-language',
@@ -436,8 +433,7 @@ describe('test code generator', function () {
436433
}
437434
});
438435

439-
it('snippet new', async () => {
440-
this.timeout(10000);
436+
it('snippet new', { timeout: 10000 }, async () => {
441437

442438
const runResult = await helpers.run(appLocation).withAnswers({
443439
type: 'ext-snippets',
@@ -478,8 +474,7 @@ describe('test code generator', function () {
478474
}
479475
});
480476

481-
it('snippet import', async () => {
482-
this.timeout(10000);
477+
it('snippet import', { timeout: 10000 }, async () => {
483478

484479
const runResult = await helpers.run(appLocation).withAnswers({
485480
type: 'ext-snippets',
@@ -547,8 +542,7 @@ describe('test code generator', function () {
547542
}
548543
});
549544

550-
it('keymap new', async () => {
551-
this.timeout(10000);
545+
it('keymap new', { timeout: 10000 }, async () => {
552546

553547
const runResult = await helpers.run(appLocation).withAnswers({
554548
type: 'ext-keymap',
@@ -587,8 +581,7 @@ describe('test code generator', function () {
587581
}
588582
});
589583

590-
it('command-ts', async () => {
591-
this.timeout(10000);
584+
it('command-ts', { timeout: 10000 }, async () => {
592585

593586
const runResult = await helpers.run(appLocation).withAnswers({
594587
type: 'ext-command-ts',
@@ -650,8 +643,7 @@ describe('test code generator', function () {
650643
}
651644
});
652645

653-
it('command-ts with yarn', async () => {
654-
this.timeout(10000);
646+
it('command-ts with yarn', { timeout: 10000 }, async () => {
655647

656648
const runResult = await helpers.run(appLocation).withAnswers({
657649
type: 'ext-command-ts',
@@ -730,8 +722,7 @@ describe('test code generator', function () {
730722
}
731723
});
732724

733-
it('command-ts with pnpm', async () => {
734-
this.timeout(10000);
725+
it('command-ts with pnpm', { timeout: 10000 }, async () => {
735726

736727
const runResult = await helpers.run(appLocation).withAnswers({
737728
type: 'ext-command-ts',
@@ -810,8 +801,7 @@ describe('test code generator', function () {
810801
}
811802
});
812803

813-
it('command-ts with webpack', async () => {
814-
this.timeout(10000);
804+
it('command-ts with webpack', { timeout: 10000 }, async () => {
815805

816806
const runResult = await helpers.run(appLocation).withAnswers({
817807
type: 'ext-command-ts',
@@ -880,8 +870,7 @@ describe('test code generator', function () {
880870
}
881871
});
882872

883-
it('command-ts with webpack + pnpm', async () => {
884-
this.timeout(10000);
873+
it('command-ts with webpack + pnpm', { timeout: 10000 }, async () => {
885874

886875
const runResult = await helpers.run(appLocation).withAnswers({
887876
type: 'ext-command-ts',
@@ -950,8 +939,7 @@ describe('test code generator', function () {
950939
}
951940
});
952941

953-
it('command-ts with esbuild + yarn', async () => {
954-
this.timeout(10000);
942+
it('command-ts with esbuild + yarn', { timeout: 10000 }, async () => {
955943

956944
const runResult = await helpers.run(appLocation).withAnswers({
957945
type: 'ext-command-ts',
@@ -1022,8 +1010,7 @@ describe('test code generator', function () {
10221010
}
10231011
});
10241012

1025-
it('command-js', async () => {
1026-
this.timeout(10000);
1013+
it('command-js', { timeout: 10000 }, async () => {
10271014

10281015
const runResult = await helpers.run(appLocation).withAnswers({
10291016
type: 'ext-command-js',
@@ -1080,8 +1067,7 @@ describe('test code generator', function () {
10801067
}
10811068
});
10821069

1083-
it('command-js with pnpm', async () => {
1084-
this.timeout(10000);
1070+
it('command-js with pnpm', { timeout: 10000 }, async () => {
10851071

10861072
const runResult = await helpers.run(appLocation).withAnswers({
10871073
type: 'ext-command-js',
@@ -1138,8 +1124,7 @@ describe('test code generator', function () {
11381124
}
11391125
});
11401126

1141-
it('command-js with check JS', async () => {
1142-
this.timeout(10000);
1127+
it('command-js with check JS', { timeout: 10000 }, async () => {
11431128

11441129
const runResult = await helpers.run(appLocation).withAnswers({
11451130
type: 'ext-command-js',
@@ -1342,8 +1327,7 @@ describe('test code generator', function () {
13421327
}
13431328
});
13441329

1345-
it('command-web', async () => {
1346-
this.timeout(10000);
1330+
it('command-web', { timeout: 10000 }, async () => {
13471331

13481332
const runResult = await helpers.run(appLocation).withAnswers({
13491333
type: 'ext-command-web',
@@ -1413,8 +1397,7 @@ describe('test code generator', function () {
14131397
}
14141398
});
14151399

1416-
it('command-web with pnpm', async () => {
1417-
this.timeout(10000);
1400+
it('command-web with pnpm', { timeout: 10000 }, async () => {
14181401

14191402
const runResult = await helpers.run(appLocation).withAnswers({
14201403
type: 'ext-command-web',
@@ -1484,8 +1467,7 @@ describe('test code generator', function () {
14841467
}
14851468
});
14861469

1487-
it('command-web-esbuild with yarn', async () => {
1488-
this.timeout(10000);
1470+
it('command-web-esbuild with yarn', { timeout: 10000 }, async () => {
14891471

14901472
const runResult = await helpers.run(appLocation).withAnswers({
14911473
type: 'ext-command-web',

0 commit comments

Comments
 (0)