File tree 9 files changed +65
-7
lines changed
packages/browser/src/client/tester
9 files changed +65
-7
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ interface BrowserRunnerOptions {
17
17
18
18
export const browserHashMap = new Map <
19
19
string ,
20
- [ test : boolean , timstamp : string ]
20
+ string
21
21
> ( )
22
22
23
23
interface CoverageHandler {
@@ -122,15 +122,15 @@ export function createBrowserRunner(
122
122
}
123
123
124
124
importFile = async ( filepath : string ) => {
125
- let [ test , hash ] = this . hashMap . get ( filepath ) ?? [ false , '' ]
126
- if ( hash === '' ) {
125
+ let hash = this . hashMap . get ( filepath )
126
+ if ( ! hash ) {
127
127
hash = Date . now ( ) . toString ( )
128
- this . hashMap . set ( filepath , [ false , hash ] )
128
+ this . hashMap . set ( filepath , hash )
129
129
}
130
130
131
131
// on Windows we need the unit to resolve the test file
132
132
const prefix = `/${ / ^ \w : / . test ( filepath ) ? '@fs/' : '' } `
133
- const query = `${ test ? ' browserv' : 'v' } =${ hash } `
133
+ const query = `browserv=${ hash } `
134
134
const importpath = `${ prefix } ${ filepath } ?${ query } ` . replace ( / \/ + / g, '/' )
135
135
await import ( /* @vite -ignore */ importpath )
136
136
}
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ async function prepareTestEnvironment(files: string[]) {
75
75
files . forEach ( ( filename ) => {
76
76
const currentVersion = browserHashMap . get ( filename )
77
77
if ( ! currentVersion || currentVersion [ 1 ] !== version ) {
78
- browserHashMap . set ( filename , [ true , version ] )
78
+ browserHashMap . set ( filename , version )
79
79
}
80
80
} )
81
81
Original file line number Diff line number Diff line change
1
+ import { beforeEach } from 'vitest' ;
2
+ import * as source from './source' ;
3
+
4
+ beforeEach < { source : any } > ( ( t ) => {
5
+ t . source = source
6
+ } )
Original file line number Diff line number Diff line change
1
+ import { expect , test } from 'vitest'
2
+ import * as source from './source'
3
+
4
+ test < { source : any } > ( 'modules are the same' , ( t ) => {
5
+ expect ( source ) . toBe ( t . source )
6
+ } )
Original file line number Diff line number Diff line change
1
+ export function answer ( ) {
2
+ return 42
3
+ }
Original file line number Diff line number Diff line change
1
+ import { fileURLToPath } from 'node:url'
2
+ import { defineConfig } from 'vitest/config'
3
+
4
+ const provider = process . env . PROVIDER || 'playwright'
5
+ const name =
6
+ process . env . BROWSER || ( provider === 'playwright' ? 'chromium' : 'chrome' )
7
+
8
+ export default defineConfig ( {
9
+ cacheDir : fileURLToPath ( new URL ( "./node_modules/.vite" , import . meta. url ) ) ,
10
+ test : {
11
+ setupFiles : [ './browser-setup.ts' ] ,
12
+ browser : {
13
+ enabled : true ,
14
+ provider,
15
+ name,
16
+ headless : false ,
17
+ } ,
18
+ } ,
19
+ } )
Original file line number Diff line number Diff line change 12
12
"test-mocking" : " vitest --root ./fixtures/mocking" ,
13
13
"test-mocking-watch" : " vitest --root ./fixtures/mocking-watch" ,
14
14
"test-locators" : " vitest --root ./fixtures/locators" ,
15
+ "test-setup-file" : " vitest --root ./fixtures/setup-file" ,
15
16
"test-snapshots" : " vitest --root ./fixtures/update-snapshot" ,
16
17
"coverage" : " vitest --coverage.enabled --coverage.provider=istanbul --browser.headless=yes" ,
17
18
"test:browser:preview" : " PROVIDER=preview vitest" ,
Original file line number Diff line number Diff line change
1
+ // fix https://github.com/vitest-dev/vitest/issues/6690
2
+
3
+ import { expect , test } from 'vitest'
4
+ import { runBrowserTests } from './utils'
5
+
6
+ test ( 'setup file imports the same modules' , async ( ) => {
7
+ const { stderr, ctx } = await runBrowserTests (
8
+ {
9
+ root : './fixtures/setup-file' ,
10
+ } ,
11
+ )
12
+
13
+ expect ( stderr ) . toBe ( '' )
14
+ expect (
15
+ Object . fromEntries (
16
+ ctx . state . getFiles ( ) . map ( f => [ f . name , f . result . state ] ) ,
17
+ ) ,
18
+ ) . toMatchInlineSnapshot ( `
19
+ {
20
+ "module-equality.test.ts": "pass",
21
+ }
22
+ ` )
23
+ } )
Original file line number Diff line number Diff line change 1
1
import type { UserConfig as ViteUserConfig } from 'vite'
2
- import type { UserConfig } from 'vitest'
2
+ import type { UserConfig } from 'vitest/node '
3
3
import { runVitest } from '../../test-utils'
4
4
5
5
export const provider = process . env . PROVIDER || 'playwright'
You can’t perform that action at this time.
0 commit comments