diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4eba0eaf..9ac525c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - node: [18, 20] + node: [18, 20, 22] fail-fast: false steps: @@ -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 diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..2bd5a0a9 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index 30815bcf..51ce7af6 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -14,48 +14,17 @@ import.meta.env?.TEST true" `; exports[`fixtures > error-parse > stderr 1`] = ` -"/lib/index.js:2 - throw err; /* ↓ Check stack trace ↓ */ - ^ - -Error: ParseError: \`import\` can only be used in \`import - /index.ts - at Object. (/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" +[ + "Error: ParseError: \`import\` can only be used in \`import ", +] `; exports[`fixtures > error-parse > stdout 1`] = `""`; exports[`fixtures > error-runtime > stderr 1`] = ` -"/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 /index.ts - at evalModule (/dist/jiti) - at jiti (/dist/jiti) - at Object. (/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" +[ + "TypeError: The "listener" argument must be of type function. Received undefined", +] `; exports[`fixtures > error-runtime > stdout 1`] = `""`; @@ -65,21 +34,7 @@ exports[`fixtures > esm > stdout 1`] = ` { file: '/test.js', dir: '', - 'import.meta.url': 'file:///test.js', - stack: [ - 'at getStack (/test)', - 'at test (/test)', - 'at /index.js', - 'at evalModule (/dist/jiti)', - 'at jiti (/dist/jiti)', - 'at Object. (/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:///test.js' }" `; @@ -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 /index.js is loading ES Module /esm.js using require().", +] +`; + exports[`fixtures > mixed > stdout 1`] = `"Mixed works for: "`; exports[`fixtures > native > stdout 1`] = `"[Module: null prototype] { default: { hasRequire: false } }"`; diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 822f155f..f08a22ff 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -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"); @@ -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", @@ -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(""); } diff --git a/test/fixtures/esm/test.js b/test/fixtures/esm/test.js index c8eaf962..806819df 100644 --- a/test/fixtures/esm/test.js +++ b/test/fixtures/esm/test.js @@ -5,9 +5,5 @@ export default function test() { file: __filename, dir: __dirname, "import.meta.url": import.meta.url, - stack: getStack() - .split("\n") - .splice(1) - .map((s) => s.trim()), }; }