Skip to content

Commit

Permalink
test: ts-jest config changes (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman authored Nov 6, 2023
1 parent 505c1a6 commit 41e62b0
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 52 deletions.
20 changes: 15 additions & 5 deletions examples/app-jest/jest.config.ts
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions examples/app-jest/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

import { defineNuxtConfig } from 'nuxt/config'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true }
Expand Down
9 changes: 5 additions & 4 deletions examples/app-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
"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",
"vue": "^3.3.7",
"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"
}
}
26 changes: 14 additions & 12 deletions examples/app-jest/test/browser.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -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!"
);
});
});
25 changes: 11 additions & 14 deletions examples/app-jest/test/dev.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -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(`
"<!DOCTYPE html>"
`)
})
})
describe("server (dev)", () => {
it("runs a test", async () => {
const html = await $fetch("/");
expect(html.slice(0, 15)).toMatchInlineSnapshot(`"<!DOCTYPE html>"`);
});
});
23 changes: 10 additions & 13 deletions examples/app-jest/test/server.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -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(`
// "<!DOCTYPE html>"
// `)
})
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(`"<!DOCTYPE html>"`)
})
})
9 changes: 7 additions & 2 deletions examples/app-jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
},
"engines": {
"node": "^14.18.0 || >=16.10.0"
}
},
"packageManager": "pnpm@8.10.2"
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"skipLibCheck": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"moduleResolution": "Bundler",
"strict": true,
"noImplicitAny": true,
"allowJs": true,
Expand Down

0 comments on commit 41e62b0

Please sign in to comment.