Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: test against node v22 (v1) #350

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20]
node: [18, 20, 22]
fail-fast: false

steps:
Expand All @@ -28,15 +28,15 @@ jobs:
node-version: ${{ matrix.node }}
cache: "pnpm"
- uses: oven-sh/setup-bun@v2
if: ${{ matrix.os != 'windows-latest' && matrix.node == 20 }}
if: ${{ matrix.os != 'windows-latest' && matrix.node == 22 }}
with:
bun-version: latest
- run: pnpm install
- run: pnpm lint
if: ${{ matrix.os != 'windows-latest' && matrix.node == 20 }}
if: ${{ matrix.os != 'windows-latest' && matrix.node == 22 }}
- run: pnpm build
- run: pnpm vitest run --coverage
- run: pnpm test:bun --coverage
if: ${{ matrix.os != 'windows-latest' && matrix.node == 20 }}
if: ${{ matrix.os != 'windows-latest' && matrix.node == 22 }}
# - name: Coverage
# uses: codecov/codecov-action@v1
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
65 changes: 13 additions & 52 deletions test/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,17 @@ import.meta.env?.TEST true"
`;

exports[`fixtures > error-parse > stderr 1`] = `
"<root>/lib/index.js:2
throw err; /* ↓ Check stack trace ↓ */
^

Error: ParseError: \`import\` can only be used in \`import
<cwd>/index.ts
at Object.<anonymous> (<root>/bin/jiti)
at Module._compile (internal/modules/cjs/loader)
at Module._extensions..js (internal/modules/cjs/loader)
at Module.load (internal/modules/cjs/loader)
at Module._load (internal/modules/cjs/loader)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main)
at internal/main/run_main_module

Node.js v<version>"
[
"Error: ParseError: \`import\` can only be used in \`import ",
]
`;

exports[`fixtures > error-parse > stdout 1`] = `""`;

exports[`fixtures > error-runtime > stderr 1`] = `
"<root>/lib/index.js:2
throw err; /* ↓ Check stack trace ↓ */
^

TypeError: The "listener" argument must be of type function. Received undefined
at checkListener (events)
at _addListener (events)
at process.addListener (events)
at <cwd>/index.ts
at evalModule (<root>/dist/jiti)
at jiti (<root>/dist/jiti)
at Object.<anonymous> (<root>/bin/jiti)
at Module._compile (internal/modules/cjs/loader)
at Module._extensions..js (internal/modules/cjs/loader)
at Module.load (internal/modules/cjs/loader)
at Module._load (internal/modules/cjs/loader)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main)
at internal/main/run_main_module {
code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v<version>"
[
"TypeError: The "listener" argument must be of type function. Received undefined",
]
`;

exports[`fixtures > error-runtime > stdout 1`] = `""`;
Expand All @@ -65,21 +34,7 @@ exports[`fixtures > esm > stdout 1`] = `
{
file: '<cwd>/test.js',
dir: '<cwd>',
'import.meta.url': 'file://<cwd>/test.js',
stack: [
'at getStack (<cwd>/test)',
'at test (<cwd>/test)',
'at <cwd>/index.js',
'at evalModule (<root>/dist/jiti)',
'at jiti (<root>/dist/jiti)',
'at Object.<anonymous> (<root>/bin/jiti)',
'at Module._compile (internal/modules/cjs/loader)',
'at Module._extensions..js (internal/modules/cjs/loader)',
'at Module.load (internal/modules/cjs/loader)',
'at Module._load (internal/modules/cjs/loader)',
'at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main)',
'at internal/main/run_main_module'
]
'import.meta.url': 'file://<cwd>/test.js'
}"
`;

Expand All @@ -99,6 +54,12 @@ Required : { test: 123 } .default: { test: 123 }
Dynamic Imported : { test: 123 } .default: { test: 123 }"
`;

exports[`fixtures > mixed > stderr 1`] = `
[
"ExperimentalWarning: CommonJS module <cwd>/index.js is loading ES Module <cwd>/esm.js using require().",
]
`;

exports[`fixtures > mixed > stdout 1`] = `"Mixed works for: <cwd>"`;

exports[`fixtures > native > stdout 1`] = `"[Module: null prototype] { default: { hasRequire: false } }"`;
Expand Down
17 changes: 15 additions & 2 deletions test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { execa } from "execa";
import { describe, it, expect } from "vitest";
import fg from "fast-glob";

const nodeMajor = Number.parseInt(process.version.slice(1), 10);

describe("fixtures", async () => {
const jitiPath = resolve(__dirname, "../bin/jiti.js");

Expand Down Expand Up @@ -35,6 +37,14 @@ describe("fixtures", async () => {
.trim();
}

function extractErrors(message: string) {
const errors = [] as string[];
for (const m of message.matchAll(/\w*(Error|Warning).*:.*$/gm)) {
errors.push(m[0]);
}
return errors;
}

const { stdout, stderr } = await execa("node", [jitiPath, fixtureEntry], {
cwd,
stdio: "pipe",
Expand All @@ -46,9 +56,12 @@ describe("fixtures", async () => {
});

if (name.includes("error")) {
expect(cleanUpSnap(stderr)).toMatchSnapshot("stderr");
expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("stderr");
} else if (name === "mixed" && nodeMajor >= 22) {
console.log(stderr);
expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("stderr");
} else {
// expect no error
// Expect no error by default
expect(stderr).toBe("");
}

Expand Down
4 changes: 0 additions & 4 deletions test/fixtures/esm/test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const getStack = () => new Error("Boo").stack;

Check warning on line 1 in test/fixtures/esm/test.js

View workflow job for this annotation

GitHub Actions / autofix

'getStack' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 1 in test/fixtures/esm/test.js

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 22)

'getStack' is assigned a value but never used. Allowed unused vars must match /^_/u

export default function test() {
return {
file: __filename,
dir: __dirname,
"import.meta.url": import.meta.url,
stack: getStack()
.split("\n")
.splice(1)
.map((s) => s.trim()),
};
}
Loading