Skip to content

Commit

Permalink
chore(ci): switch to vitest for testing (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed May 14, 2023
1 parent 5c62ebd commit d701387
Show file tree
Hide file tree
Showing 12 changed files with 539 additions and 1,225 deletions.
5 changes: 0 additions & 5 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ module.exports = {
'vue/multi-word-component-names': 'off',
},
overrides: [
{
files: ['test/**'],
plugins: ['jest'],
extends: ['plugin:jest/recommended'],
},
{
files: ['*.ts', '*.tsx'],
extends: [
Expand Down
21 changes: 0 additions & 21 deletions jest.config.ts

This file was deleted.

10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"lint:fix": "eslint --ext .vue,.js,.ts . --fix",
"lint:fixture": "eslint --ext .vue,.js --no-ignore 'test/fixture/*/.nuxt/sentry.*'",
"release": "release-it",
"test:fixture": "NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
"test": "yarn prepack && yarn test:fixture && yarn lint:fixture && yarn typecheck",
"test:fixture": "vitest",
"test": "yarn prepack && yarn test:fixture run && yarn lint:fixture && yarn typecheck",
"typecheck": "tsc",
"coverage": "codecov"
},
Expand Down Expand Up @@ -80,17 +80,14 @@
"@sentry/webpack-plugin": "1.20.1",
"@size-limit/file": "^8.2.4",
"@types/hash-sum": "1.0.0",
"@types/jest": "29.4.3",
"@types/lodash.mergewith": "4.6.7",
"@types/node": "16.18.19",
"@types/request-promise-native": "^1.0.18",
"codecov": "3.8.3",
"eslint": "8.36.0",
"eslint-plugin-jest": "27.2.1",
"globby": "11.1.0",
"hookable": "5.5.2",
"husky": "4.3.8",
"jest": "29.4.3",
"lint-staged": "13.2.0",
"npm-run-all": "^4.1.5",
"nuxt": "2.16.3",
Expand All @@ -99,9 +96,8 @@
"sass": "1.60.0",
"sentry-testkit": "5.0.5",
"size-limit": "^8.2.4",
"ts-jest": "29.0.5",
"ts-node": "10.9.1",
"typescript": "5.0.2",
"vitest": "^0.31.0",
"vue": "2.7.14",
"vuex": "3.6.2"
}
Expand Down
7 changes: 4 additions & 3 deletions test/default.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import { describe, afterAll, beforeAll, beforeEach, test, expect } from 'vitest'
import type { Browser } from 'playwright-chromium'
import sentryTestkit from 'sentry-testkit'
import { setup, loadConfig, url } from '@nuxtjs/module-test-utils'
import { setup, url } from '@nuxtjs/module-test-utils'
import type { Nuxt } from '../src/kit-shim'
import { $$, createBrowser } from './utils'
import { $$, createBrowser, loadConfig } from './utils'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
Expand All @@ -19,7 +20,7 @@ describe('Smoke test (default)', () => {
beforeAll(async () => {
await localServer.start(TEST_DSN)
const dsn = localServer.getDsn()
nuxt = (await setup(loadConfig(__dirname, 'default', { sentry: { dsn } }, { merge: true }))).nuxt
nuxt = (await setup(await loadConfig(__dirname, 'default', { sentry: { dsn } }, { merge: true }))).nuxt
browser = await createBrowser()
})

Expand Down
7 changes: 4 additions & 3 deletions test/lazy.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import { describe, afterAll, beforeAll, test, expect } from 'vitest'
import type { Browser } from 'playwright-chromium'
import sentryTestkit from 'sentry-testkit'
import { setup, loadConfig, url } from '@nuxtjs/module-test-utils'
import { setup, url } from '@nuxtjs/module-test-utils'
import type { Nuxt } from '../src/kit-shim'
import { $$, createBrowser } from './utils'
import { $$, createBrowser, loadConfig } from './utils'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
Expand All @@ -19,7 +20,7 @@ describe('Smoke test (lazy)', () => {
beforeAll(async () => {
await localServer.start(TEST_DSN)
const dsn = localServer.getDsn()
nuxt = (await setup(loadConfig(__dirname, 'lazy', { sentry: { dsn } }, { merge: true }))).nuxt
nuxt = (await setup(await loadConfig(__dirname, 'lazy', { sentry: { dsn } }, { merge: true }))).nuxt
browser = await createBrowser()
})

Expand Down
3 changes: 0 additions & 3 deletions test/setup.ts

This file was deleted.

6 changes: 0 additions & 6 deletions test/tsconfig-jest.json

This file was deleted.

14 changes: 14 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { defu } from 'defu'
import { chromium, Browser, Page } from 'playwright-chromium'

export async function createBrowser (): Promise<Browser> {
Expand All @@ -15,3 +16,16 @@ export async function $$ (selector: string, page: Page): Promise<string | null>
}
return null
}

export async function loadConfig (dir: string, fixture: string | null = null, override: Record<string, unknown> = {}, { merge = false } = {}): Promise<Record<string, unknown>> {
const config = await import(`${dir}/fixture/${fixture ? fixture + '/' : ''}nuxt.config.cjs`)

if (merge) {
return defu(override, config)
} else {
return {
...defu(config),
...defu(override),
}
}
}
7 changes: 4 additions & 3 deletions test/with-lazy-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import { describe, afterAll, beforeAll, test, expect } from 'vitest'
import type { Browser } from 'playwright-chromium'
import sentryTestkit from 'sentry-testkit'
import { setup, loadConfig, url } from '@nuxtjs/module-test-utils'
import { setup, url } from '@nuxtjs/module-test-utils'
import type { Nuxt } from '../src/kit-shim'
import { $$, createBrowser } from './utils'
import { $$, createBrowser, loadConfig } from './utils'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
Expand All @@ -19,7 +20,7 @@ describe('Smoke test (lazy config)', () => {
beforeAll(async () => {
await localServer.start(TEST_DSN)
const dsn = localServer.getDsn()
nuxt = (await setup(loadConfig(__dirname, 'with-lazy-config', { sentry: { dsn } }, { merge: true }))).nuxt
nuxt = (await setup(await loadConfig(__dirname, 'with-lazy-config', { sentry: { dsn } }, { merge: true }))).nuxt
browser = await createBrowser()
})

Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"noEmit": true,
"strict": true,
"types": [
"jest",
"node",
],
},
Expand Down
7 changes: 7 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
hookTimeout: 30000,
},
})
Loading

0 comments on commit d701387

Please sign in to comment.