-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
test("basic", () => { | ||
expect(1).toBe(1); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
test("basic", () => { | ||
expect(1).toBe(1); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
function logHook(...args: unknown[]) { | ||
((globalThis as any).__testHooks ??= []).push(args[0]); | ||
|
||
if (process.env["LOG_HOOK"]) { | ||
console.log(...args); | ||
} | ||
} | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
{ | ||
name: "test-default", | ||
configureServer() { | ||
logHook("configureServer(default)") | ||
}, | ||
buildStart() { | ||
logHook("buildStart(default)") | ||
}, | ||
resolveId(source) { | ||
logHook("resolveId(default)", source) | ||
}, | ||
transform(_code, id) { | ||
logHook("transform(default)", id) | ||
}, | ||
}, | ||
{ | ||
name: "test-pre", | ||
enforce: "pre", | ||
configureServer() { | ||
logHook("configureServer(pre)") | ||
}, | ||
buildStart() { | ||
logHook("buildStart(pre)") | ||
}, | ||
resolveId(source) { | ||
logHook("resolveId(pre)", source) | ||
}, | ||
transform(_code, id) { | ||
logHook("transform(pre)", id) | ||
}, | ||
} | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect, it, vi } from 'vitest' | ||
import { createVitest } from 'vitest/node' | ||
|
||
it(createVitest, async () => { | ||
const onFinished = vi.fn() | ||
const ctx = await createVitest('test', { | ||
watch: false, | ||
root: 'fixtures/create-vitest', | ||
reporters: [ | ||
{ | ||
onFinished, | ||
}, | ||
], | ||
}) | ||
const testFiles = await ctx.globTestFiles() | ||
await ctx.runFiles(testFiles, false) | ||
expect(onFinished.mock.calls[0]).toMatchObject([ | ||
[ | ||
{ | ||
name: 'basic.test.ts', | ||
result: { | ||
state: 'pass', | ||
}, | ||
}, | ||
], | ||
[], | ||
]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { expect, it } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
it('plugin hooks', async () => { | ||
await runVitest({ root: './fixtures/plugin' }) | ||
expect((globalThis as any).__testHooks.slice(0, 5)).toEqual( | ||
[ | ||
'configureServer(pre)', | ||
'configureServer(default)', | ||
'buildStart(pre)', | ||
'buildStart(default)', | ||
'resolveId(pre)', | ||
], | ||
) | ||
}) |