Switch from jest to vitest (#21444)
Even if we are not bundling with `vite` yet, we can use `vitest` in place of Jest which brings a few benefits like not requiring to use `NODE_OPTIONS` to run and having sane module resolution. It's possible to also use `jest-extended` with vitest, but I opted to not do so for now because it brings heavyweight dependencies and it was trivial to just rewrite the affected matchers to be compatible. This PR also removes 153 JS dependencies, which is certainly nice. Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>tokarchuk/v1.18
parent
9dc264a2ee
commit
c3098076b5
@ -1,15 +0,0 @@ |
|||||||
// to run tests with ES6 module, node must run with "--experimental-vm-modules", or see Makefile's "test-frontend" for reference
|
|
||||||
export default { |
|
||||||
rootDir: 'web_src', |
|
||||||
setupFilesAfterEnv: ['jest-extended/all'], |
|
||||||
testEnvironment: 'jest-environment-jsdom', |
|
||||||
testMatch: ['<rootDir>/**/*.test.js'], |
|
||||||
testTimeout: 20000, |
|
||||||
transform: { |
|
||||||
'\\.svg$': '<rootDir>/js/testUtils/jestRawLoader.js', |
|
||||||
}, |
|
||||||
setupFiles: [ |
|
||||||
'./js/testUtils/jestSetup.js', // prepare global variables used by our code (eg: window.config)
|
|
||||||
], |
|
||||||
verbose: false, |
|
||||||
}; |
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,33 @@ |
|||||||
|
import {defineConfig} from 'vitest/dist/config.js'; |
||||||
|
import {readFile} from 'fs/promises'; |
||||||
|
import {dataToEsm} from '@rollup/pluginutils'; |
||||||
|
import {extname} from 'path'; |
||||||
|
|
||||||
|
function stringPlugin() { |
||||||
|
return { |
||||||
|
name: 'string-plugin', |
||||||
|
enforce: 'pre', |
||||||
|
async load(id) { |
||||||
|
const path = id.split('?')[0]; |
||||||
|
if (extname(path) !== '.svg') return null; |
||||||
|
return dataToEsm(await readFile(path, 'utf8')); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
export default defineConfig({ |
||||||
|
test: { |
||||||
|
include: ['web_src/**/*.test.js'], |
||||||
|
setupFiles: ['./web_src/js/test/setup.js'], |
||||||
|
environment: 'jsdom', |
||||||
|
testTimeout: 20000, |
||||||
|
open: false, |
||||||
|
allowOnly: true, |
||||||
|
passWithNoTests: true, |
||||||
|
globals: true, |
||||||
|
watch: false, |
||||||
|
}, |
||||||
|
plugins: [ |
||||||
|
stringPlugin(), |
||||||
|
], |
||||||
|
}); |
@ -1,7 +1,7 @@ |
|||||||
import {svg} from './svg.js'; |
import {svg} from './svg.js'; |
||||||
|
|
||||||
test('svg', () => { |
test('svg', () => { |
||||||
expect(svg('octicon-repo')).toStartWith('<svg'); |
expect(svg('octicon-repo')).toMatch(/^<svg/); |
||||||
expect(svg('octicon-repo', 16)).toInclude('width="16"'); |
expect(svg('octicon-repo', 16)).toContain('width="16"'); |
||||||
expect(svg('octicon-repo', 32)).toInclude('width="32"'); |
expect(svg('octicon-repo', 32)).toContain('width="32"'); |
||||||
}); |
}); |
||||||
|
@ -1,5 +1,5 @@ |
|||||||
window.config = { |
window.config = { |
||||||
csrfToken: 'jest-test-csrf-token-123456', |
csrfToken: 'test-csrf-token-123456', |
||||||
pageData: {}, |
pageData: {}, |
||||||
i18n: {}, |
i18n: {}, |
||||||
}; |
}; |
@ -1,5 +0,0 @@ |
|||||||
export default { // eslint-disable-line import/no-unused-modules
|
|
||||||
process: (content) => { |
|
||||||
return {code: `module.exports = ${JSON.stringify(content)}`}; |
|
||||||
}, |
|
||||||
}; |
|
Loading…
Reference in new issue