@@ -16,74 +16,55 @@ const {
16
16
getBrowserOptions,
17
17
} = Utils
18
18
19
- jest . spyOn ( fs , 'exists' )
20
-
21
19
beforeEach ( ( ) => {
22
20
jest . resetModules ( )
23
21
} )
24
22
25
23
describe ( 'readConfig' , ( ) => {
26
24
it ( 'should return the default configuration if there was no separate configuration specified' , async ( ) => {
27
- ; ( ( fs . exists as unknown ) as jest . Mock ) . mockImplementationOnce (
28
- ( _ , cb : ( exists : boolean ) => void ) => cb ( false ) ,
29
- )
30
- const config = await readConfig ( )
31
- expect ( config ) . toMatchObject ( DEFAULT_CONFIG )
32
- } )
33
- it ( 'should overwrite with a custom configuration' , async ( ) => {
34
- ; ( ( fs . exists as unknown ) as jest . Mock ) . mockImplementationOnce (
35
- ( _ , cb : ( exists : boolean ) => void ) => cb ( true ) ,
36
- )
37
25
jest . mock (
38
26
path . join ( __dirname , '..' , 'jest-playwright.config.js' ) ,
39
- ( ) => ( {
40
- launchOptions : {
41
- headless : true ,
42
- } ,
43
- browser : 'chromium' ,
44
- contextOptions : {
45
- ignoreHTTPSErrors : true ,
46
- } ,
47
- } ) ,
27
+ ( ) => ( { } ) ,
48
28
{ virtual : true } ,
49
29
)
50
30
const config = await readConfig ( )
51
- const expectedConfig = {
31
+ expect ( config ) . toMatchObject ( DEFAULT_CONFIG )
32
+ } )
33
+ it ( 'should overwrite with a custom configuration' , async ( ) => {
34
+ const configObject = {
52
35
launchOptions : {
53
36
headless : true ,
54
37
} ,
38
+ browser : 'chromium' ,
55
39
contextOptions : {
56
40
ignoreHTTPSErrors : true ,
57
41
} ,
58
- browser : 'chromium' ,
59
- exitOnPageError : true ,
60
42
}
61
- expect ( config ) . toMatchObject ( expectedConfig )
62
- } )
63
- it ( 'should overwrite with a custom configuration and spread the "launchOptions" and "contextOptions" setting' , async ( ) => {
64
- ; ( ( fs . exists as unknown ) as jest . Mock ) . mockImplementationOnce (
65
- ( _ , cb : ( exists : boolean ) => void ) => cb ( true ) ,
66
- )
67
43
jest . mock (
68
44
path . join ( __dirname , '..' , 'jest-playwright.config.js' ) ,
69
- ( ) => ( {
70
- launchOptions : {
71
- headless : true ,
72
- } ,
73
- contextOptions : {
74
- foo : true ,
75
- } ,
76
- } ) ,
45
+ ( ) => configObject ,
77
46
{ virtual : true } ,
78
47
)
79
48
const config = await readConfig ( )
80
- const expectedConfig = {
49
+ expect ( config ) . toMatchObject ( configObject )
50
+ } )
51
+ it ( 'should overwrite with a custom configuration and spread the "launchOptions" and "contextOptions" setting' , async ( ) => {
52
+ const configObject = {
81
53
launchOptions : {
82
54
headless : true ,
83
55
} ,
84
56
contextOptions : {
85
57
foo : true ,
86
58
} ,
59
+ }
60
+ jest . mock (
61
+ path . join ( __dirname , '..' , 'jest-playwright.config.js' ) ,
62
+ ( ) => configObject ,
63
+ { virtual : true } ,
64
+ )
65
+ const config = await readConfig ( )
66
+ const expectedConfig = {
67
+ ...configObject ,
87
68
browsers : [ 'chromium' ] ,
88
69
exitOnPageError : true ,
89
70
}
@@ -100,6 +81,35 @@ describe('readConfig', () => {
100
81
expect ( error ) . toBeTruthy ( )
101
82
delete process . env . JEST_PLAYWRIGHT_CONFIG
102
83
} )
84
+ it ( 'should check cjs config if npm_package_type is module' , async ( ) => {
85
+ process . env . npm_package_type = 'module'
86
+ const configPath = path . join ( __dirname , '..' , 'jest-playwright.config.cjs' )
87
+ const configObject = {
88
+ browsers : [ 'webkit' ] ,
89
+ launchOptions : {
90
+ headless : true ,
91
+ } ,
92
+ contextOptions : {
93
+ foo : true ,
94
+ } ,
95
+ }
96
+ fs . writeFileSync ( configPath , '' )
97
+ jest . mock (
98
+ path . join ( __dirname , '..' , 'jest-playwright.config.cjs' ) ,
99
+ ( ) => configObject ,
100
+ {
101
+ virtual : true ,
102
+ } ,
103
+ )
104
+ const expectedConfig = {
105
+ ...configObject ,
106
+ exitOnPageError : true ,
107
+ }
108
+ const config = await readConfig ( )
109
+ expect ( config ) . toMatchObject ( expectedConfig )
110
+ delete process . env . npm_package_type
111
+ fs . unlinkSync ( configPath )
112
+ } )
103
113
} )
104
114
105
115
describe ( 'getDisplayName' , ( ) => {
0 commit comments