Skip to content

Commit b115c3a

Browse files
authored
add support to run tests in node 18.19 and node 20 (yeoman#555)
1 parent 78f9776 commit b115c3a

File tree

5 files changed

+70
-13
lines changed

5 files changed

+70
-13
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest, windows-latest, macos-latest]
25-
node-version: [18.18.2]
25+
node-version: [18, 20]
2626
steps:
2727
- uses: actions/checkout@v4
2828
- uses: actions/setup-node@v4

package-lock.json

+32-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@
8585
"@types/semver": "^7.5.3",
8686
"c8": "^10.1.2",
8787
"cpy-cli": "^5.0.0",
88-
"esmocha": "^1.0.1",
88+
"esmocha": "^1.2.0",
8989
"fs-extra": "^11.1.1",
9090
"jsdoc": "^4.0.2",
9191
"prettier": "3.0.3",
9292
"prettier-plugin-packagejson": "^2.4.6",
93+
"quibble": "^0.9.1",
9394
"rimraf": "^5.0.5",
9495
"sinon": "^19.0.2",
9596
"sinon-test": "^3.1.5",

test/generator-features.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import assert from 'node:assert';
2+
import { Module } from 'node:module';
23
import sinon from 'sinon';
3-
import { esmocha, expect, mock } from 'esmocha';
4+
import { after, before, esmocha, expect } from 'esmocha';
5+
import quibble from 'quibble';
46
import helpers, { getCreateEnv } from './helpers.js';
57
import { greaterThan5 } from './generator-versions.js';
8+
import * as execaModule from 'execa';
69

7-
const { commitSharedFsTask } = await mock('../src/commit.ts');
8-
const { packageManagerInstallTask } = await mock('../src/package-manager.ts');
10+
if (!Module.register) {
11+
throw new Error('Node greater than v18.19.0 or v20.6.0 is required to test this module.');
12+
}
13+
14+
const commitSharedFsTask = esmocha.fn();
15+
const packageManagerInstallTask = esmocha.fn();
16+
const execa = esmocha.fn();
17+
await quibble.esm('../src/commit.ts', { commitSharedFsTask });
18+
await quibble.esm('../src/package-manager.ts', { packageManagerInstallTask });
19+
await quibble.esm('execa', { ...execaModule, execa });
920
const { default: BasicEnvironment } = await import('../src/environment-base.js');
1021

1122
for (const generatorVersion of greaterThan5) {
@@ -14,9 +25,12 @@ for (const generatorVersion of greaterThan5) {
1425
class FeaturesGenerator extends Generator {}
1526

1627
describe(`environment (generator-features) using ${generatorVersion}`, () => {
17-
beforeEach(() => {
28+
afterEach(() => {
1829
esmocha.resetAllMocks();
1930
});
31+
after(() => {
32+
quibble.reset();
33+
});
2034

2135
describe('customCommitTask feature', () => {
2236
describe('without customInstallTask', () => {
@@ -172,8 +186,8 @@ for (const generatorVersion of greaterThan5) {
172186
await runContext.run();
173187
});
174188

175-
it('should not call packageManagerInstallTask', () => {
176-
expect(packageManagerInstallTask).not.toHaveBeenCalled();
189+
it('should not call execa', () => {
190+
expect(execa).not.toHaveBeenCalled();
177191
});
178192
});
179193

test/package-manager.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
import { Module } from 'node:module';
12
import path, { dirname } from 'node:path';
23
import { fileURLToPath } from 'node:url';
34
import sinon from 'sinon';
4-
import { esmocha, expect, resetAllMocks } from 'esmocha';
5+
import { esmocha, expect } from 'esmocha';
6+
import quibble from 'quibble';
57

6-
const { execa } = await esmocha.mock('execa');
7-
const { whichPackageManager } = await esmocha.mock('which-package-manager');
8+
if (!Module.register) {
9+
throw new Error('Node greater than v18.19.0 or v20.6.0 is required to test this module.');
10+
}
11+
12+
const execa = esmocha.fn();
13+
await quibble.esm('execa', { execa });
14+
const whichPackageManager = esmocha.fn();
15+
await quibble.esm('which-package-manager', { whichPackageManager });
816

917
const { packageManagerInstallTask } = await import('../src/package-manager.js');
1018

@@ -32,7 +40,10 @@ describe('environment (package-manager)', () => {
3240
});
3341

3442
afterEach(() => {
35-
resetAllMocks();
43+
esmocha.resetAllMocks();
44+
});
45+
after(() => {
46+
quibble.reset();
3647
});
3748

3849
describe('#packageManagerInstallTask()', () => {

0 commit comments

Comments
 (0)