diff --git a/examples/app-jest/jest.config.ts b/examples/app-jest/jest.config.ts index fcff56a59..0c7a35740 100644 --- a/examples/app-jest/jest.config.ts +++ b/examples/app-jest/jest.config.ts @@ -1,7 +1,17 @@ -import type { Config } from 'jest' + +import type {Config} from "jest" export default { - extensionsToTreatAsEsm: ['.ts'], - preset: 'ts-jest', - testEnvironment: 'node', -} satisfies Config + preset: 'ts-jest/presets/default-esm', // or other ESM presets + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1', + }, + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + useESM: true, + }, + ], + }, +} satisfies Config \ No newline at end of file diff --git a/examples/app-jest/nuxt.config.ts b/examples/app-jest/nuxt.config.ts index 8851e7746..4ab34bced 100644 --- a/examples/app-jest/nuxt.config.ts +++ b/examples/app-jest/nuxt.config.ts @@ -1,3 +1,6 @@ + +import { defineNuxtConfig } from 'nuxt/config' + // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ devtools: { enabled: true } diff --git a/examples/app-jest/package.json b/examples/app-jest/package.json index 90602ca5a..4d96033f8 100644 --- a/examples/app-jest/package.json +++ b/examples/app-jest/package.json @@ -8,7 +8,7 @@ "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare", - "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js" + "test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js" }, "dependencies": { "nuxt": "^3.8.0", @@ -16,11 +16,12 @@ "vue-router": "^4.2.5" }, "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^5.2.2", "@nuxt/test-utils": "latest", "@types/jest": "^29.5.7", + "@types/node": "^20.8.10", "jest": "^29.7.0", - "ts-jest": "^29.1.1", - "ts-node": "^10.9.1", - "typescript": "^5.2.2" + "ts-jest": "^29.1.1" } } diff --git a/examples/app-jest/test/browser.e2e.spec.ts b/examples/app-jest/test/browser.e2e.spec.ts index 3f3864c49..e879bdda8 100644 --- a/examples/app-jest/test/browser.e2e.spec.ts +++ b/examples/app-jest/test/browser.e2e.spec.ts @@ -1,16 +1,18 @@ -import { fileURLToPath } from 'node:url' -import { createPage, setup } from '@nuxt/test-utils' -import { describe, expect, it } from 'vitest' +import { fileURLToPath } from "node:url"; +import { createPage, setup } from "@nuxt/test-utils"; await setup({ - rootDir: fileURLToPath(new URL('../', import.meta.url)), + rootDir: fileURLToPath(new URL("../", import.meta.url)), browser: true, - runner: 'jest', -}) + runner: "jest", +}); -describe('browser', async () => { - it('runs a test', async () => { - const page = await createPage('/') - expect(page.getByRole('heading').innerText()).toContain('Welcome to Nuxt!') - }) -}) +describe("browser", () => { + it("runs a test", async () => { + const page = await createPage("/"); + const text = await page.getByRole("heading",{ name: 'Welcome to Nuxt!' }).innerText() + await expect(text).toContain( + "Welcome to Nuxt!" + ); + }); +}); diff --git a/examples/app-jest/test/dev.e2e.spec.ts b/examples/app-jest/test/dev.e2e.spec.ts index 3e8517918..d7f50ede7 100644 --- a/examples/app-jest/test/dev.e2e.spec.ts +++ b/examples/app-jest/test/dev.e2e.spec.ts @@ -1,18 +1,15 @@ -import { fileURLToPath } from 'node:url' -import { $fetch, setup } from '@nuxt/test-utils' -import { describe, expect, it } from 'vitest' +import { fileURLToPath } from "node:url"; +import { $fetch, setup } from "@nuxt/test-utils"; await setup({ - rootDir: fileURLToPath(new URL('../', import.meta.url)), + rootDir: fileURLToPath(new URL("../", import.meta.url)), dev: true, - runner: 'jest' -}) + runner: "jest", +}); -describe('server (dev)', async () => { - it('runs a test', async () => { - const html = await $fetch('/') - expect(html.slice(0, 15)).toMatchInlineSnapshot(` - "" - `) - }) -}) +describe("server (dev)", () => { + it("runs a test", async () => { + const html = await $fetch("/"); + expect(html.slice(0, 15)).toMatchInlineSnapshot(`""`); + }); +}); diff --git a/examples/app-jest/test/server.e2e.spec.ts b/examples/app-jest/test/server.e2e.spec.ts index 13647c7de..1744908ec 100644 --- a/examples/app-jest/test/server.e2e.spec.ts +++ b/examples/app-jest/test/server.e2e.spec.ts @@ -1,17 +1,14 @@ import { fileURLToPath } from 'node:url' import { $fetch, setup } from '@nuxt/test-utils' -import { describe, expect, it } from 'vitest' -// await setup({ -// rootDir: fileURLToPath(new URL('../', import.meta.url)), -// runner: 'jest' -// }) -describe('app', async () => { - it('runs a test', async () => { - expect(true).toBe(true) - // const html = await $fetch('/') - // expect(html.slice(0, 15)).toMatchInlineSnapshot(` - // "" - // `) - }) +await setup({ + rootDir: fileURLToPath(new URL('../', import.meta.url)), + runner: 'jest' }) + +describe("app",()=>{ + it("runs a test",async ()=>{ + const html = await $fetch('/') + expect(html.slice(0, 15)).toMatchInlineSnapshot(`""`) + }) +}) \ No newline at end of file diff --git a/examples/app-jest/tsconfig.json b/examples/app-jest/tsconfig.json index 218be4b2a..62dbc9621 100644 --- a/examples/app-jest/tsconfig.json +++ b/examples/app-jest/tsconfig.json @@ -1,9 +1,14 @@ { "extends": "./.nuxt/tsconfig.json", "compilerOptions": { - "target": "ESNext", + // "lib": ["ES2021"], "module": "ESNext", + "esModuleInterop": true, + "moduleResolution": "Bundler", "verbatimModuleSyntax": false, - "moduleResolution": "Bundler" + "target": "ESNext", + "types": ["node", "jest"], + "typeRoots": ["node_modules/@types"], + "resolveJsonModule": true } } diff --git a/package.json b/package.json index 571e8e47f..24c3404ab 100644 --- a/package.json +++ b/package.json @@ -77,5 +77,6 @@ }, "engines": { "node": "^14.18.0 || >=16.10.0" - } + }, + "packageManager": "pnpm@8.10.2" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d2e50709a..27334605b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -116,6 +116,9 @@ importers: '@types/jest': specifier: ^29.5.7 version: 29.5.7 + '@types/node': + specifier: ^20.8.10 + version: 20.8.10 jest: specifier: ^29.7.0 version: 29.7.0(@types/node@20.8.10)(ts-node@10.9.1) diff --git a/tsconfig.json b/tsconfig.json index 0b11102b4..b9b8e1a93 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "skipLibCheck": true, "target": "ESNext", "module": "ESNext", - "moduleResolution": "Node", + "moduleResolution": "Bundler", "strict": true, "noImplicitAny": true, "allowJs": true,