Skip to content

Commit a165854

Browse files
committed
test: add vitest plugin snap test for async factory loading
1 parent bb46b63 commit a165854

6 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function myVitestPlugin() {
2+
return {
3+
name: 'my-vitest-plugin',
4+
config() {
5+
return {
6+
test: {
7+
env: {
8+
MY_VITEST_PLUGIN_LOADED: '1',
9+
},
10+
},
11+
};
12+
},
13+
};
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "vite-plugins-async-test",
3+
"private": true
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
> vp test # async plugins factory should load vitest plugin with configureVitest hook
2+
RUN <cwd>
3+
4+
✓ src/index.test.ts (1 test) <variable>ms
5+
6+
Test Files 1 passed (1)
7+
Tests 1 passed (1)
8+
Start at <date>
9+
Duration <variable>ms (transform <variable>ms, setup <variable>ms, import <variable>ms, tests <variable>ms, environment <variable>ms)
10+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, test } from '@voidzero-dev/vite-plus-test';
2+
3+
test('async plugin factory should load vitest plugin', () => {
4+
expect(process.env.MY_VITEST_PLUGIN_LOADED).toBe('1');
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"commands": [
3+
"vp test # async plugins factory should load vitest plugin with configureVitest hook"
4+
]
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vite-plus';
2+
3+
export default defineConfig({
4+
plugins: async () => {
5+
const { default: myVitestPlugin } = await import('./my-vitest-plugin');
6+
return [myVitestPlugin()];
7+
},
8+
});

0 commit comments

Comments
 (0)