Skip to content

Commit

Permalink
chore: Switch to seed plugin for testing (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 authored Mar 15, 2024
1 parent 816878b commit 53c63b4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/utils/testing/fake-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand Down
1 change: 0 additions & 1 deletion src/types/vitest-defines.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"types": ["vitest-plugin-random-seed/types"],
"paths": {
"~/*": ["./src/*"]
}
Expand Down
19 changes: 3 additions & 16 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -36,7 +23,7 @@ export default defineWorkspace([
restoreMocks: true,
setupFiles: 'vitest.setup.ts',
},
plugins: [testSeed()],
plugins: [RandomSeed()],
resolve,
},
{
Expand All @@ -45,7 +32,7 @@ export default defineWorkspace([
dir: 'e2e',
testTimeout: 120e3,
},
plugins: [testSeed()],
plugins: [RandomSeed()],
resolve,
},
]);

0 comments on commit 53c63b4

Please sign in to comment.