@@ -244,11 +244,16 @@ module.exports.addTests = function({testRunner, expect}) {
244
244
it ( 'should run all hooks in proper order' , async ( ) => {
245
245
const log = [ ] ;
246
246
const t = newTestRunner ( ) ;
247
- const e = t . environment ( 'env' , ( ) => {
247
+ let e2 ;
248
+ t . environment ( 'env' , ( ) => {
248
249
t . beforeAll ( ( ) => log . push ( 'env:beforeAll' ) ) ;
249
250
t . afterAll ( ( ) => log . push ( 'env:afterAll' ) ) ;
250
251
t . beforeEach ( ( ) => log . push ( 'env:beforeEach' ) ) ;
251
252
t . afterEach ( ( ) => log . push ( 'env:afterEach' ) ) ;
253
+ e2 = t . environment ( 'env2' , ( ) => {
254
+ t . beforeAll ( ( ) => log . push ( 'env2:beforeAll' ) ) ;
255
+ t . afterAll ( ( ) => log . push ( 'env2:afterAll' ) ) ;
256
+ } ) ;
252
257
} ) ;
253
258
t . beforeAll ( ( ) => log . push ( 'root:beforeAll' ) ) ;
254
259
t . beforeEach ( ( ) => log . push ( 'root:beforeEach1' ) ) ;
@@ -270,13 +275,13 @@ module.exports.addTests = function({testRunner, expect}) {
270
275
t . afterEach ( ( ) => log . push ( 'suite:afterEach2' ) ) ;
271
276
t . afterAll ( ( ) => log . push ( 'suite:afterAll' ) ) ;
272
277
} ) ;
273
- t . it ( 'cuatro' , ( ) => log . push ( 'test #4' ) ) . environment ( e ) ;
278
+ t . it ( 'cuatro' , ( ) => log . push ( 'test #4' ) ) . environment ( e2 ) ;
274
279
t . describe ( 'no hooks suite' , ( ) => {
275
280
t . describe ( 'suite2' , ( ) => {
276
281
t . beforeAll ( ( ) => log . push ( 'suite2:beforeAll' ) ) ;
277
282
t . afterAll ( ( ) => log . push ( 'suite2:afterAll' ) ) ;
278
283
t . describe ( 'no hooks suite 2' , ( ) => {
279
- t . it ( 'cinco' , ( ) => log . push ( 'test #5' ) ) . environment ( e ) ;
284
+ t . it ( 'cinco' , ( ) => log . push ( 'test #5' ) ) . environment ( e2 ) ;
280
285
} ) ;
281
286
} ) ;
282
287
} ) ;
@@ -321,6 +326,7 @@ module.exports.addTests = function({testRunner, expect}) {
321
326
'suite:afterAll' ,
322
327
323
328
'env:beforeAll' ,
329
+ 'env2:beforeAll' ,
324
330
325
331
'root:beforeEach1' ,
326
332
'root:beforeEach2' ,
@@ -338,6 +344,7 @@ module.exports.addTests = function({testRunner, expect}) {
338
344
'root:afterEach' ,
339
345
'suite2:afterAll' ,
340
346
347
+ 'env2:afterAll' ,
341
348
'env:afterAll' ,
342
349
343
350
'root:afterAll1' ,
@@ -347,8 +354,10 @@ module.exports.addTests = function({testRunner, expect}) {
347
354
it ( 'environment restrictions' , async ( ) => {
348
355
const t = newTestRunner ( ) ;
349
356
let env ;
357
+ let env2 ;
350
358
t . describe ( 'suite1' , ( ) => {
351
359
env = t . environment ( 'env' , ( ) => {
360
+ env2 = t . environment ( 'env2' , ( ) => { } ) ;
352
361
try {
353
362
t . it ( 'test' , ( ) => { } ) ;
354
363
expect ( true ) . toBe ( false ) ;
@@ -361,13 +370,19 @@ module.exports.addTests = function({testRunner, expect}) {
361
370
} catch ( e ) {
362
371
expect ( e . message ) . toBe ( 'Cannot define a suite inside an environment' ) ;
363
372
}
364
- try {
365
- t . environment ( 'env2' , ( ) => { } ) ;
366
- expect ( true ) . toBe ( false ) ;
367
- } catch ( e ) {
368
- expect ( e . message ) . toBe ( 'Cannot define an environment inside an environment' ) ;
369
- }
370
373
} ) ;
374
+ try {
375
+ t . it ( 'test' , ( ) => { } ) . environment ( env ) . environment ( env2 ) ;
376
+ expect ( true ) . toBe ( false ) ;
377
+ } catch ( e ) {
378
+ expect ( e . message ) . toBe ( 'Cannot use environments "env2" and "env" that share a parent environment "suite1 env" in test "suite1 test"' ) ;
379
+ }
380
+ try {
381
+ t . it ( 'test' , ( ) => { } ) . environment ( env2 ) . environment ( env ) ;
382
+ expect ( true ) . toBe ( false ) ;
383
+ } catch ( e ) {
384
+ expect ( e . message ) . toBe ( 'Cannot use environments "env" and "env2" that share a parent environment "suite1 env" in test "suite1 test"' ) ;
385
+ }
371
386
} ) ;
372
387
try {
373
388
t . it ( 'test' , ( ) => { } ) . environment ( env ) ;
0 commit comments