@@ -21,7 +21,7 @@ test('globalSetup and globalTeardown should work', async ({ runInlineTest }) =>
21
21
'playwright.config.ts' : `
22
22
import * as path from 'path';
23
23
module.exports = {
24
- globalSetup: './globalSetup.ts ',
24
+ globalSetup: './globalSetup',
25
25
globalTeardown: path.join(__dirname, 'globalTeardown.ts'),
26
26
};
27
27
` ,
@@ -54,7 +54,7 @@ test('globalTeardown runs after failures', async ({ runInlineTest }) => {
54
54
import * as path from 'path';
55
55
module.exports = {
56
56
globalSetup: 'globalSetup.ts',
57
- globalTeardown: 'globalTeardown.ts',
57
+ globalTeardown: './ globalTeardown.ts',
58
58
};
59
59
` ,
60
60
'globalSetup.ts' : `
@@ -85,7 +85,7 @@ test('globalTeardown does not run when globalSetup times out', async ({ runInlin
85
85
'playwright.config.ts' : `
86
86
import * as path from 'path';
87
87
module.exports = {
88
- globalSetup: 'globalSetup.ts',
88
+ globalSetup: './ globalSetup.ts',
89
89
globalTeardown: 'globalTeardown.ts',
90
90
globalTimeout: 1000,
91
91
};
@@ -119,7 +119,7 @@ test('globalSetup should be run before requiring tests', async ({ runInlineTest
119
119
'playwright.config.ts' : `
120
120
import * as path from 'path';
121
121
module.exports = {
122
- globalSetup: 'globalSetup.ts',
122
+ globalSetup: './ globalSetup.ts',
123
123
};
124
124
` ,
125
125
'globalSetup.ts' : `
@@ -143,7 +143,7 @@ test('globalSetup should work with sync function', async ({ runInlineTest }) =>
143
143
'playwright.config.ts' : `
144
144
import * as path from 'path';
145
145
module.exports = {
146
- globalSetup: 'globalSetup.ts',
146
+ globalSetup: './ globalSetup.ts',
147
147
};
148
148
` ,
149
149
'globalSetup.ts' : `
@@ -167,7 +167,7 @@ test('globalSetup should throw when passed non-function', async ({ runInlineTest
167
167
'playwright.config.ts' : `
168
168
import * as path from 'path';
169
169
module.exports = {
170
- globalSetup: 'globalSetup.ts',
170
+ globalSetup: './ globalSetup.ts',
171
171
};
172
172
` ,
173
173
'globalSetup.ts' : `
@@ -187,7 +187,7 @@ test('globalSetup should work with default export and run the returned fn', asyn
187
187
'playwright.config.ts' : `
188
188
import * as path from 'path';
189
189
module.exports = {
190
- globalSetup: 'globalSetup.ts',
190
+ globalSetup: './ globalSetup.ts',
191
191
};
192
192
` ,
193
193
'globalSetup.ts' : `
@@ -212,3 +212,28 @@ test('globalSetup should work with default export and run the returned fn', asyn
212
212
expect ( output ) . toContain ( `%%setup: 42` ) ;
213
213
expect ( output ) . toContain ( `%%teardown: 42` ) ;
214
214
} ) ;
215
+
216
+ test ( 'globalSetup should allow requiring a package from node_modules' , async ( { runInlineTest } ) => {
217
+ const { results } = await runInlineTest ( {
218
+ 'playwright.config.ts' : `
219
+ import * as path from 'path';
220
+ module.exports = {
221
+ globalSetup: 'my-global-setup'
222
+ };
223
+ ` ,
224
+ 'node_modules/my-global-setup/index.js' : `
225
+ module.exports = async () => {
226
+ await new Promise(f => setTimeout(f, 100));
227
+ global.value = 42;
228
+ process.env.FOO = String(global.value);
229
+ };
230
+ ` ,
231
+ 'a.test.js' : `
232
+ const { test } = pwt;
233
+ test('should work', async ({}, testInfo) => {
234
+ expect(process.env.FOO).toBe('42');
235
+ });
236
+ ` ,
237
+ } ) ;
238
+ expect ( results [ 0 ] . status ) . toBe ( 'passed' ) ;
239
+ } ) ;
0 commit comments