1+ import ansis from 'ansis' ;
12import path from 'node:path' ;
23import { fileURLToPath } from 'node:url' ;
34import type { Page } from 'playwright-core' ;
4- import { describe , expect , it , vi } from 'vitest' ;
55import { loadSetupScript , runSetup } from './setup.js' ;
66
77describe ( 'loadSetupScript integration' , ( ) => {
@@ -15,44 +15,39 @@ describe('loadSetupScript integration', () => {
1515 ) ;
1616
1717 it ( 'should load a valid setup script with default export' , async ( ) => {
18- const scriptPath = path . join ( fixturesDir , 'valid-setup.ts' ) ;
19-
20- const setupFn = await loadSetupScript ( scriptPath ) ;
18+ const setupFn = await loadSetupScript (
19+ path . join ( fixturesDir , 'valid-setup.ts' ) ,
20+ ) ;
2121
2222 expect ( typeof setupFn ) . toBe ( 'function' ) ;
2323 } ) ;
2424
2525 it ( 'should execute loaded setup script with runSetup' , async ( ) => {
26- const scriptPath = path . join ( fixturesDir , 'valid-setup.ts' ) ;
2726 const mockPage = { goto : vi . fn ( ) } as unknown as Page ;
2827
29- const setupFn = await loadSetupScript ( scriptPath ) ;
28+ const setupFn = await loadSetupScript (
29+ path . join ( fixturesDir , 'valid-setup.ts' ) ,
30+ ) ;
3031 await runSetup ( setupFn , mockPage ) ;
3132
3233 expect ( mockPage . goto ) . toHaveBeenCalledWith ( 'about:blank' ) ;
3334 } ) ;
3435
3536 it ( 'should throw error for setup script without default export' , async ( ) => {
36- const scriptPath = path . join ( fixturesDir , 'invalid-setup-no-default.ts' ) ;
37-
38- await expect ( loadSetupScript ( scriptPath ) ) . rejects . toThrow (
39- / I n v a l i d .* S e t u p S c r i p t M o d u l e / ,
40- ) ;
37+ await expect (
38+ loadSetupScript ( path . join ( fixturesDir , 'invalid-setup-no-default.ts' ) ) ,
39+ ) . rejects . toThrow ( `Invalid ${ ansis . bold ( 'SetupScriptModule' ) } ` ) ;
4140 } ) ;
4241
4342 it ( 'should throw error for setup script with non-function default export' , async ( ) => {
44- const scriptPath = path . join ( fixturesDir , 'invalid-setup-wrong-type.ts' ) ;
45-
46- await expect ( loadSetupScript ( scriptPath ) ) . rejects . toThrow (
47- / I n v a l i d .* S e t u p S c r i p t M o d u l e / ,
48- ) ;
43+ await expect (
44+ loadSetupScript ( path . join ( fixturesDir , 'invalid-setup-wrong-type.ts' ) ) ,
45+ ) . rejects . toThrow ( `Invalid ${ ansis . bold ( 'SetupScriptModule' ) } ` ) ;
4946 } ) ;
5047
5148 it ( 'should throw error for non-existent setup script' , async ( ) => {
52- const scriptPath = path . join ( fixturesDir , 'non-existent.ts' ) ;
53-
54- await expect ( loadSetupScript ( scriptPath ) ) . rejects . toThrow (
55- / S e t u p s c r i p t n o t f o u n d / ,
56- ) ;
49+ await expect (
50+ loadSetupScript ( path . join ( fixturesDir , 'non-existent.ts' ) ) ,
51+ ) . rejects . toThrow ( 'Setup script not found' ) ;
5752 } ) ;
5853} ) ;
0 commit comments