From 53778e3fed96d5f1eedfb50ffd5b5c15f642edfc Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Thu, 1 Oct 2015 14:51:30 -0400 Subject: [PATCH] Core: Share on module contained suites --- src/core.js | 11 ++++++++++- test/main/modules.js | 35 ++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/core.js b/src/core.js index bdb70a2c7..6d1eedbc2 100644 --- a/src/core.js +++ b/src/core.js @@ -56,9 +56,18 @@ extend( QUnit, { var module = { name: moduleName, parentModule: parentModule, - testEnvironment: testEnvironment, tests: [] }; + + var env = {}; + if ( parentModule ) { + extend( env, parentModule.testEnvironment ); + delete env.beforeEach; + delete env.afterEach; + } + extend( env, testEnvironment ); + module.testEnvironment = env; + config.modules.push( module ); return module; } diff --git a/test/main/modules.js b/test/main/modules.js index cb3802458..d5631fe36 100644 --- a/test/main/modules.js +++ b/test/main/modules.js @@ -244,23 +244,44 @@ QUnit.module( "contained suite arguments", function( hooks ) { } ); QUnit.module( "contained suite `this`", function( hooks ) { - this.outerBefore = 0; + this.outer = 1; hooks.beforeEach( function() { - this.outerBefore++; + this.outer++; } ); hooks.afterEach( function( assert ) { - assert.equal( this.outerBefore, 42 ); + assert.equal( this.outer, 2 ); } ); QUnit.test( "`this` is shared from modules to the tests", function( assert ) { - assert.equal(this.outerBefore, 1, "beforeEach updated environment" ); - this.outerBefore += 41; + assert.equal( this.outer, 2 ); } ); QUnit.test( "sibling tests don't share environments", function( assert ) { - assert.equal(this.outerBefore, 1 ); - this.outerBefore += 41; + assert.equal( this.outer, 2 ); + } ); + + QUnit.module( "nested suite `this`", function( hooks ) { + this.inner = true; + + hooks.beforeEach( function( assert ) { + assert.ok( this.outer ); + assert.ok( this.inner ); + } ); + + hooks.afterEach( function( assert ) { + assert.ok( this.outer ); + assert.ok( this.inner ); + } ); + + QUnit.test( "inner modules share outer environments", function( assert ) { + assert.ok( this.outer ); + assert.ok( this.inner ); + } ); + } ); + + QUnit.test( "tests can't see environments from nested modules", function( assert ) { + assert.strictEqual( this.inner, undefined ); } ); } );