Skip to content

Commit

Permalink
Add Node.js v20 and npm v9 support alongside end-to-end tests
Browse files Browse the repository at this point in the history
Create a basic end-to-end test suite (that is a suite that invokes the
CLI just like users would) and use it to initiate support for Node.js
v20 and v9 of the npm CLI. To ensure the support the end-to-end tests
are ran continuously against all combinations of supported versions of
Node.js and npm.

Signed-off-by: Eric Cornelissen <[email protected]>
  • Loading branch information
ericcornelissen committed Nov 16, 2024
1 parent ea3d538 commit 1ad6c3f
Show file tree
Hide file tree
Showing 12 changed files with 2,440 additions and 11 deletions.
34 changes: 32 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Check licenses
run: npm run licenses
test-unit:
name: Unit Test
name: Test unit
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
Expand All @@ -58,7 +58,37 @@ jobs:
- name: Install dependencies
run: npm clean-install
- name: Test
run: npm run coverage
run: npm run coverage:unit
test-e2e:
name: Test end-to-end (Node.js v${{ matrix.node }} with npm v${{ matrix.npm }})
runs-on: ubuntu-24.04
needs:
- test-unit
strategy:
fail-fast: false
matrix:
node:
- 20.0.0
- 22.0.0
npm:
- 9.0.0
- 10.0.0
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Install Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
cache: npm
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm clean-install
- name: Install npm@${{ matrix.npm }}
run: npm install --global npm@${{ matrix.npm }}
- name: Test
run: npm run test:e2e
vet:
name: Vet
runs-on: ubuntu-24.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
npm update --omit dev --omit optional --omit peer
npm install
- name: Run tests
run: npm run test
run: npm run test:unit
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Versioning].

## [Unreleased]

- Add support for Node.js v20.
- Add support for npm v9.
- Fix support for aliases in `dependencies`.
- Fix an error if there are no `dependencies` or `devDependencies`.
- Type check the `#ignore` value.

## [0.3.2] - 2024-11-09
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@
"bin": "./bin/cli.js",
"type": "module",
"engines": {
"node": "^22",
"npm": "^10"
"node": "^20 || ^22",
"npm": "^9 || ^10"
},
"scripts": {
"audit": "npm run audit:deprecations && npm run audit:vulnerabilities",
"audit:deprecations": "npm run dogfeed",
"audit:vulnerabilities": "better-npm-audit audit",
"coverage": "node --test --experimental-test-coverage 'src/*.test.js'",
"coverage": "npm run coverage:unit",
"coverage:unit": "node --test --experimental-test-coverage 'src/*.test.js'",
"dogfeed": "node bin/cli.js --errors-only",
"licenses": "licensee --errors-only",
"test": "node --test 'src/*.test.js'",
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "node --test 'src/*.test.js'",
"test:e2e": "node --test 'test/e2e.test.js'",
"verify": "npm run test && npm run vet && npm run licenses && npm run dogfeed",
"vet": "lockfile-lint && ls-engines && publint --strict && node check-runtime-deps.js"
},
Expand Down
7 changes: 3 additions & 4 deletions src/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ async function obtainAliases() {

const aliases = new Map();
for (const deps of [
manifest.dependencies,
manifest.devDependencies,
manifest.dependencies || {},
manifest.devDependencies || {},
]) {
for (const name in deps) {
const rhs = manifest.devDependencies[name];
for (const [name, rhs] of Object.entries(deps)) {
const aliasMatch = /^npm:(@?.+?)@(.+)$/.exec(rhs);
if (aliasMatch) {
const [, alias, version] = aliasMatch;
Expand Down
94 changes: 94 additions & 0 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (C) 2024 Eric Cornelissen
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, version 3 of the License only.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import * as assert from "node:assert/strict";
import * as cp from "node:child_process";
import * as fs from "node:fs";
import * as path from "node:path";
import * as process from "node:process";
import { test } from "node:test";
import * as url from "node:url";

test("end-to-end", async (t) => {
await t.test("--help", () => {
const result = cli({
args: ["--help"],
project: project("example"),
});

assert.equal(result.exitCode, 0);
assert.notEqual(result.stdout, "");
assert.equal(result.stderr, "");
});

await t.test("basic example without unexpected error", () => {
const result = cli({
project: project("example"),
});

assert.notEqual(result.exitCode, 2);
});

await t.test("ignoring all deprecation warnings with --errors-only", () => {
const result = cli({
args: ["--errors-only"],
project: project("ignore-all"),
});

assert.equal(result.exitCode, 0);
assert.equal(result.stdout, "");
assert.equal(result.stderr, "");
});
});

const root = path.resolve(
path.dirname(url.fileURLToPath(new URL(import.meta.url))),
"..",
);

function project(name) {
return path.join(root, "test", "fixtures", name);
}

function cli({ args, project }) {
// Ensure the project to test exists.
assert.doesNotThrow(() => fs.accessSync(project), `${project} not found`);

// Run the command.
const result = cp.spawnSync(
process.argv[0],
[
path.join(root, "bin", "cli.js"),

// Provide test-specified CLI arguments, if any.
...(args || []),
],
{
// Run depreman in the test-specified directory.
cwd: project,

// Get output as text instead of a buffer.
encoding: "utf-8",
},
);

// Ensure running the command did not fail.
assert.equal(result.error, undefined, "Starting depreman failed");

return {
exitCode: result.status,
stdout: result.stdout,
stderr: result.stderr,
};
}
2 changes: 2 additions & 0 deletions test/fixtures/example/.ndmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Loading

0 comments on commit 1ad6c3f

Please sign in to comment.