@@ -275,13 +275,13 @@ module.exports.addTests = function({testRunner, expect}) {
275
275
t . afterEach ( ( ) => log . push ( 'suite:afterEach2' ) ) ;
276
276
t . afterAll ( ( ) => log . push ( 'suite:afterAll' ) ) ;
277
277
} ) ;
278
- t . it ( 'cuatro' , ( ) => log . push ( 'test #4' ) ) . environment ( e2 ) ;
278
+ t . it ( 'cuatro' , ( ) => log . push ( 'test #4' ) ) . addEnvironment ( e2 ) ;
279
279
t . describe ( 'no hooks suite' , ( ) => {
280
280
t . describe ( 'suite2' , ( ) => {
281
281
t . beforeAll ( ( ) => log . push ( 'suite2:beforeAll' ) ) ;
282
282
t . afterAll ( ( ) => log . push ( 'suite2:afterAll' ) ) ;
283
283
t . describe ( 'no hooks suite 2' , ( ) => {
284
- t . it ( 'cinco' , ( ) => log . push ( 'test #5' ) ) . environment ( e2 ) ;
284
+ t . it ( 'cinco' , ( ) => log . push ( 'test #5' ) ) . addEnvironment ( e2 ) ;
285
285
} ) ;
286
286
} ) ;
287
287
} ) ;
@@ -351,6 +351,31 @@ module.exports.addTests = function({testRunner, expect}) {
351
351
'root:afterAll2' ,
352
352
] ) ;
353
353
} ) ;
354
+ it ( 'should remove environment' , async ( ) => {
355
+ const log = [ ] ;
356
+ const t = newTestRunner ( ) ;
357
+ const e = t . environment ( 'env' , ( ) => {
358
+ t . beforeAll ( ( ) => log . push ( 'env:beforeAll' ) ) ;
359
+ t . afterAll ( ( ) => log . push ( 'env:afterAll' ) ) ;
360
+ t . beforeEach ( ( ) => log . push ( 'env:beforeEach' ) ) ;
361
+ t . afterEach ( ( ) => log . push ( 'env:afterEach' ) ) ;
362
+ } ) ;
363
+ const e2 = t . environment ( 'env2' , ( ) => {
364
+ t . beforeAll ( ( ) => log . push ( 'env2:beforeAll' ) ) ;
365
+ t . afterAll ( ( ) => log . push ( 'env2:afterAll' ) ) ;
366
+ t . beforeEach ( ( ) => log . push ( 'env2:beforeEach' ) ) ;
367
+ t . afterEach ( ( ) => log . push ( 'env2:afterEach' ) ) ;
368
+ } ) ;
369
+ t . it ( 'uno' , ( ) => log . push ( 'test #1' ) ) . addEnvironment ( e ) . addEnvironment ( e2 ) . removeEnvironment ( e ) ;
370
+ await t . run ( ) ;
371
+ expect ( log ) . toEqual ( [
372
+ 'env2:beforeAll' ,
373
+ 'env2:beforeEach' ,
374
+ 'test #1' ,
375
+ 'env2:afterEach' ,
376
+ 'env2:afterAll' ,
377
+ ] ) ;
378
+ } ) ;
354
379
it ( 'environment restrictions' , async ( ) => {
355
380
const t = newTestRunner ( ) ;
356
381
let env ;
@@ -372,20 +397,20 @@ module.exports.addTests = function({testRunner, expect}) {
372
397
}
373
398
} ) ;
374
399
try {
375
- t . it ( 'test' , ( ) => { } ) . environment ( env ) . environment ( env2 ) ;
400
+ t . it ( 'test' , ( ) => { } ) . addEnvironment ( env ) . addEnvironment ( env2 ) ;
376
401
expect ( true ) . toBe ( false ) ;
377
402
} catch ( e ) {
378
403
expect ( e . message ) . toBe ( 'Cannot use environments "env2" and "env" that share a parent environment "suite1 env" in test "suite1 test"' ) ;
379
404
}
380
405
try {
381
- t . it ( 'test' , ( ) => { } ) . environment ( env2 ) . environment ( env ) ;
406
+ t . it ( 'test' , ( ) => { } ) . addEnvironment ( env2 ) . addEnvironment ( env ) ;
382
407
expect ( true ) . toBe ( false ) ;
383
408
} catch ( e ) {
384
409
expect ( e . message ) . toBe ( 'Cannot use environments "env" and "env2" that share a parent environment "suite1 env" in test "suite1 test"' ) ;
385
410
}
386
411
} ) ;
387
412
try {
388
- t . it ( 'test' , ( ) => { } ) . environment ( env ) ;
413
+ t . it ( 'test' , ( ) => { } ) . addEnvironment ( env ) ;
389
414
expect ( true ) . toBe ( false ) ;
390
415
} catch ( e ) {
391
416
expect ( e . message ) . toBe ( 'Cannot use environment "env" from suite "suite1" in unrelated test "test"' ) ;
0 commit comments