From b115c3aad345f577449dec89cf520b2c4ad74560 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 14 Oct 2024 15:11:37 -0300 Subject: [PATCH] add support to run tests in node 18.19 and node 20 (#555) --- .github/workflows/ci.yml | 2 +- package-lock.json | 33 ++++++++++++++++++++++++++++++++- package.json | 3 ++- test/generator-features.js | 26 ++++++++++++++++++++------ test/package-manager.js | 19 +++++++++++++++---- 5 files changed, 70 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58878c29..3d719704 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/package-lock.json b/package-lock.json index f7da6c3c..b07f61ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,11 +44,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", @@ -11969,6 +11970,36 @@ "resolved": "https://registry.npmjs.org/queue-tick/-/queue-tick-1.0.1.tgz", "integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==" }, + "node_modules/quibble": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/quibble/-/quibble-0.9.1.tgz", + "integrity": "sha512-2EkLLm3CsBhbHfYEgBWHSJZZRpVHUZLeuJVEQoU/lsCqxcOvVkgVlF4nWv2ACWKkb0lgxgMh3m8vq9rhx9LTIg==", + "dev": true, + "dependencies": { + "lodash": "^4.17.21", + "resolve": "^1.22.8" + }, + "engines": { + "node": ">= 0.14.0" + } + }, + "node_modules/quibble/node_modules/resolve": { + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "dev": true, + "dependencies": { + "is-core-module": "^2.13.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/quick-lru": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", diff --git a/package.json b/package.json index c486b9d6..2cc5361e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/generator-features.js b/test/generator-features.js index f2937be3..f6284b54 100644 --- a/test/generator-features.js +++ b/test/generator-features.js @@ -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(); }); }); diff --git a/test/package-manager.js b/test/package-manager.js index fae46fd0..0f74fa78 100644 --- a/test/package-manager.js +++ b/test/package-manager.js @@ -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()', () => {