Skip to content

Commit

Permalink
add support to run tests in node 18.19 and node 20 (#555)
Browse files Browse the repository at this point in the history
mshima authored Oct 14, 2024
1 parent 78f9776 commit b115c3a
Showing 5 changed files with 70 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18.18.2]
node-version: [18, 20]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
33 changes: 32 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -85,11 +85,12 @@
"@types/semver": "^7.5.3",
"c8": "^10.1.2",
"cpy-cli": "^5.0.0",
"esmocha": "^1.0.1",
"esmocha": "^1.2.0",
"fs-extra": "^11.1.1",
"jsdoc": "^4.0.2",
"prettier": "3.0.3",
"prettier-plugin-packagejson": "^2.4.6",
"quibble": "^0.9.1",
"rimraf": "^5.0.5",
"sinon": "^19.0.2",
"sinon-test": "^3.1.5",
26 changes: 20 additions & 6 deletions test/generator-features.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import assert from 'node:assert';
import { Module } from 'node:module';
import sinon from 'sinon';
import { esmocha, expect, mock } from 'esmocha';
import { after, before, esmocha, expect } from 'esmocha';
import quibble from 'quibble';
import helpers, { getCreateEnv } from './helpers.js';
import { greaterThan5 } from './generator-versions.js';
import * as execaModule from 'execa';

const { commitSharedFsTask } = await mock('../src/commit.ts');
const { packageManagerInstallTask } = await mock('../src/package-manager.ts');
if (!Module.register) {
throw new Error('Node greater than v18.19.0 or v20.6.0 is required to test this module.');
}

const commitSharedFsTask = esmocha.fn();
const packageManagerInstallTask = esmocha.fn();
const execa = esmocha.fn();
await quibble.esm('../src/commit.ts', { commitSharedFsTask });
await quibble.esm('../src/package-manager.ts', { packageManagerInstallTask });
await quibble.esm('execa', { ...execaModule, execa });
const { default: BasicEnvironment } = await import('../src/environment-base.js');

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

describe(`environment (generator-features) using ${generatorVersion}`, () => {
beforeEach(() => {
afterEach(() => {
esmocha.resetAllMocks();
});
after(() => {
quibble.reset();
});

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

it('should not call packageManagerInstallTask', () => {
expect(packageManagerInstallTask).not.toHaveBeenCalled();
it('should not call execa', () => {
expect(execa).not.toHaveBeenCalled();
});
});

19 changes: 15 additions & 4 deletions test/package-manager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Module } from 'node:module';
import path, { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import sinon from 'sinon';
import { esmocha, expect, resetAllMocks } from 'esmocha';
import { esmocha, expect } from 'esmocha';
import quibble from 'quibble';

const { execa } = await esmocha.mock('execa');
const { whichPackageManager } = await esmocha.mock('which-package-manager');
if (!Module.register) {
throw new Error('Node greater than v18.19.0 or v20.6.0 is required to test this module.');
}

const execa = esmocha.fn();
await quibble.esm('execa', { execa });
const whichPackageManager = esmocha.fn();
await quibble.esm('which-package-manager', { whichPackageManager });

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

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

afterEach(() => {
resetAllMocks();
esmocha.resetAllMocks();
});
after(() => {
quibble.reset();
});

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

0 comments on commit b115c3a

Please sign in to comment.