@@ -9,6 +9,28 @@ const checkArrayExpectation = require("./checkArrayExpectation");
99
1010const webpack = require ( "../lib/webpack" ) ;
1111
12+ function createNestableIt ( done ) {
13+ let counter = 0 ;
14+ let aborted = false ;
15+ return ( title , fn ) => {
16+ counter ++ ;
17+ fn ( ( err ) => {
18+ if ( aborted ) {
19+ return ;
20+ }
21+ if ( err ) {
22+ aborted = true ;
23+ done ( err ) ;
24+ } else {
25+ counter -- ;
26+ if ( counter === 0 ) {
27+ done ( ) ;
28+ }
29+ }
30+ } ) ;
31+ }
32+ }
33+
1234describe ( "HotTestCases" , ( ) => {
1335 const casesPath = path . join ( __dirname , "hotCases" ) ;
1436 let categories = fs . readdirSync ( casesPath ) . filter ( ( dir ) =>
@@ -22,9 +44,6 @@ describe("HotTestCases", () => {
2244 categories . forEach ( ( category ) => {
2345 describe ( category . name , ( ) => {
2446 category . tests . forEach ( ( testName ) => {
25- const suite = describe ( testName , function ( ) {
26- this . timeout ( 10000 ) ;
27- } ) ;
2847 it ( testName + " should compile" , ( done ) => {
2948 const testDirectory = path . join ( casesPath , category . name , testName ) ;
3049 const outputDirectory = path . join ( __dirname , "js" , "hot-cases" , category . name , testName ) ;
@@ -70,11 +89,10 @@ describe("HotTestCases", () => {
7089 if ( checkArrayExpectation ( testDirectory , jsonStats , "warning" , "Warning" , done ) ) return ;
7190 let exportedTests = 0 ;
7291
92+ const __it = createNestableIt ( done ) ;
7393 function _it ( title , fn ) {
74- const test = new Test ( title , fn ) ;
75- suite . addTest ( test ) ;
94+ __it ( title , fn ) ;
7695 exportedTests ++ ;
77- return test ;
7896 }
7997
8098 function _next ( callback ) {
@@ -93,17 +111,16 @@ describe("HotTestCases", () => {
93111 function _require ( module ) {
94112 if ( module . substr ( 0 , 2 ) === "./" ) {
95113 const p = path . join ( outputDirectory , module ) ;
96- const fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, __filename, it, NEXT, STATS) {" + fs . readFileSync ( p , "utf-8" ) + "\n})" , p ) ;
114+ const fn = vm . runInThisContext ( "(function(require, module, exports, __dirname, __filename, it, expect, NEXT, STATS) {" + fs . readFileSync ( p , "utf-8" ) + "\n})" , p ) ;
97115 const m = {
98116 exports : { }
99117 } ;
100- fn . call ( m . exports , _require , m , m . exports , outputDirectory , p , _it , _next , jsonStats ) ;
118+ fn . call ( m . exports , _require , m , m . exports , outputDirectory , p , _it , expect , _next , jsonStats ) ;
101119 return m . exports ;
102120 } else return require ( module ) ;
103121 }
104122 _require ( "./bundle.js" ) ;
105123 if ( exportedTests < 1 ) return done ( new Error ( "No tests exported by test case" ) ) ;
106- process . nextTick ( done ) ;
107124 } ) ;
108125 } ) ;
109126 } ) ;
0 commit comments