chore: Switch to seed plugin for testing (#547)

This commit is contained in:
Aaron
2024-03-15 00:43:20 -05:00
committed by GitHub
parent 816878bc15
commit 53c63b4556
6 changed files with 17 additions and 18 deletions
+1
View File
@@ -171,6 +171,7 @@
"vitepress": "1.0.0-rc.34",
"vitest": "^1.2.2",
"vitest-mock-extended": "^1.3.1",
"vitest-plugin-random-seed": "^1.0.2",
"vue": "^3.3.10"
},
"packageManager": "pnpm@8.6.3",
+11
View File
@@ -198,6 +198,9 @@ importers:
vitest-mock-extended:
specifier: ^1.3.1
version: 1.3.1(typescript@5.3.3)(vitest@1.2.2)
vitest-plugin-random-seed:
specifier: ^1.0.2
version: 1.0.2(vite@5.1.3)
vue:
specifier: ^3.3.10
version: 3.3.10(typescript@5.3.3)
@@ -5334,6 +5337,14 @@ packages:
vitest: 1.2.2(@types/node@20.10.3)(happy-dom@13.3.8)(sass@1.69.5)
dev: true
/vitest-plugin-random-seed@1.0.2(vite@5.1.3):
resolution: {integrity: sha512-Kt5QHmx7I1p2WShsmgJSK/L8hNPZpyNu85zSml5yv/fHDe7gJspcKc7kNYrLVVwZdGcqcZxyHAeH503szzQ95g==}
peerDependencies:
vite: ^4.0.0 || ^5.0.0
dependencies:
vite: 5.1.3(@types/node@20.10.3)(sass@1.69.5)
dev: true
/vitest@1.2.2(@types/node@20.10.3)(happy-dom@13.3.8)(sass@1.69.5):
resolution: {integrity: sha512-d5Ouvrnms3GD9USIK36KG8OZ5bEvKEkITFtnGv56HFaSlbItJuYr7hv2Lkn903+AvRAgSixiamozUVfORUekjw==}
engines: {node: ^18.0.0 || >=20.0.0}
+1 -1
View File
@@ -27,7 +27,7 @@ import { mock } from 'vitest-mock-extended';
import { vi } from 'vitest';
import { setWxtForTesting } from '~/core/wxt';
faker.seed(__TEST_SEED__);
faker.seed(import.meta.test.SEED);
type DeepPartial<T> = T extends object
? {
-1
View File
@@ -1 +0,0 @@
declare const __TEST_SEED__: number;
+1
View File
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"types": ["vitest-plugin-random-seed/types"],
"paths": {
"~/*": ["./src/*"]
}
+3 -16
View File
@@ -1,20 +1,7 @@
import { defineWorkspace } from 'vitest/config';
import fs from 'fs-extra';
import pc from 'picocolors';
import type { Plugin } from 'vite';
import path from 'node:path';
const seed = Math.round(Math.random() * Number.MAX_SAFE_INTEGER);
console.info('Test seed: ' + pc.cyan(seed));
// config.define doesn't work with workspaces, so we have to set it inside a plugin
const testSeed = (): Plugin => ({
name: 'test-seed',
config(config) {
config.define ??= {};
config.define.__TEST_SEED__ = JSON.stringify(seed);
},
});
import RandomSeed from 'vitest-plugin-random-seed';
const resolve = {
alias: {
@@ -36,7 +23,7 @@ export default defineWorkspace([
restoreMocks: true,
setupFiles: 'vitest.setup.ts',
},
plugins: [testSeed()],
plugins: [RandomSeed()],
resolve,
},
{
@@ -45,7 +32,7 @@ export default defineWorkspace([
dir: 'e2e',
testTimeout: 120e3,
},
plugins: [testSeed()],
plugins: [RandomSeed()],
resolve,
},
]);