chore: switch to vitest

This commit is contained in:
Nolan Lawson 2024-03-08 20:42:37 -08:00
parent 7365322a5f
commit d161c96453
5 changed files with 623 additions and 1420 deletions

View File

@ -1,5 +1,4 @@
import '@testing-library/jest-dom/jest-globals'
import { jest } from '@jest/globals'
import { vi } from 'vitest'
import * as FakeIndexedDB from 'fake-indexeddb'
import { Crypto } from '@peculiar/webcrypto'
import { ResizeObserver } from 'd2l-resize-aware/resize-observer-module.js'
@ -22,8 +21,6 @@ if (!globalThis.performance.measure) {
globalThis.performance.measure = () => {}
}
jest.setTimeout(60000)
globalThis.ResizeObserver = ResizeObserver
process.env.NODE_ENV = 'test'
@ -37,8 +34,8 @@ globalThis.indexedDB = new IDBFactory()
globalThis.structuredClone = globalThis.structuredClone ?? (_ => JSON.parse(JSON.stringify(_)))
beforeAll(() => {
jest.spyOn(globalThis.console, 'log').mockImplementation()
jest.spyOn(globalThis.console, 'warn').mockImplementation()
vi.spyOn(globalThis.console, 'log').mockImplementation()
vi.spyOn(globalThis.console, 'warn').mockImplementation()
const fetch = fetchMockJest.default.sandbox()
globalThis.fetch = fetch

View File

@ -1,30 +0,0 @@
module.exports = {
testEnvironment: 'jsdom',
testMatch: [
'<rootDir>/test/spec/**/*.{spec,test}.{js,jsx,ts,tsx}'
],
transform: {
'^.*PickerTemplate.js$': './config/minifyHtmlInJest.js'
},
moduleFileExtensions: ['js'],
testPathIgnorePatterns: ['node_modules'],
bail: true,
verbose: true,
silent: false,
setupFilesAfterEnv: [
'<rootDir>/config/jest.setup.js'
],
coverageReporters: ['json', 'lcov', 'text', 'html'],
coveragePathIgnorePatterns: [
'bin/',
'test/'
],
coverageThreshold: {
global: {
statements: 100,
branches: 100,
functions: 100,
lines: 100
}
}
}

View File

@ -44,9 +44,9 @@
"dev:server": "node ./test/adhoc/server.js",
"lint": "standard && stylelint '**/*.scss'",
"lint:fix": "standard --fix && stylelint --fix '**/*.scss'",
"test": "node ./bin/buildStylesForJest.js && NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
"test": "node ./bin/buildStylesForJest.js && NODE_OPTIONS=--experimental-vm-modules vitest",
"test:adhoc": "node ./test/adhoc/server.js",
"cover": "node ./bin/buildStylesForJest.js && NODE_OPTIONS=--experimental-vm-modules jest --runInBand --coverage",
"cover": "node ./bin/buildStylesForJest.js && NODE_OPTIONS=--experimental-vm-modules vitest --coverage",
"docs": "node bin/processCustomEmoji.js",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"version": "run-s changelog docs && git add CHANGELOG.md docs"
@ -96,8 +96,7 @@
"focus-visible": "^5.2.0",
"get-folder-size": "^4.0.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^24.0.0",
"lint-staged": "^15.2.2",
"lodash-es": "^4.17.15",
"markdown-table": "^3.0.2",
@ -120,7 +119,8 @@
"stylelint-scss": "^6.1.0",
"svgo": "^3.2.0",
"tachometer": "^0.7.0",
"terser": "^5.28.1"
"terser": "^5.28.1",
"vitest": "^1.3.1"
},
"//": {
"jsonwebtoken": "comes from tachometer, tachometer is pinned for now due to breaking change, but jsonwebtoken 8 has a vuln"

28
vitest.config.cjs Normal file
View File

@ -0,0 +1,28 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
transform: {
'^.*PickerTemplate.js$': './config/minifyHtmlInJest.js'
},
setupFiles: [
'./config/jest.setup.js'
],
testTimeout: 60000,
coverageReporters: ['json', 'lcov', 'text', 'html'],
coveragePathIgnorePatterns: [
'bin/',
'test/'
],
coverageThreshold: {
global: {
statements: 100,
branches: 100,
functions: 100,
lines: 100
}
}
}
})

1966
yarn.lock

File diff suppressed because it is too large Load Diff