aboutsummaryrefslogtreecommitdiff
path: root/vitest.config.js
diff options
context:
space:
mode:
authorsilverwind2022-10-14 15:36:16 +0200
committerGitHub2022-10-14 21:36:16 +0800
commitc3098076b5264f080fc727d73bfd538916ac02b3 (patch)
treeb6e217e73159deb011e537ac90d82c1edaed15fc /vitest.config.js
parent9dc264a2eebbd30bbff483c26bf27f0406677f77 (diff)
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>
Diffstat (limited to 'vitest.config.js')
-rw-r--r--vitest.config.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/vitest.config.js b/vitest.config.js
new file mode 100644
index 000000000..d17abd26c
--- /dev/null
+++ b/vitest.config.js
@@ -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(),
+ ],
+});