11const path = require ( "path" ) ;
22const fs = require ( "fs" ) ;
33
4+ const assert = require ( "../../../modules/console/assert.js" ) ;
45const WorkspacePath = require ( "../../../modules/workspace/workspace-path.js" ) ;
56const TestEnv = require ( "../../../modules/integration-test/test-env.js" ) ;
7+ const TestCasesConfig = require ( "../../../modules/integration-test/test-case/test-cases-config.js" ) ;
68
79
810class TestCases {
911
1012 static getTestCases ( testCasesConfigReady , filters ) {
1113 return new Promise ( ( resolve , reject ) => {
1214 testCasesConfigReady . then ( configs => {
13- let testCasesReadyList = [ ] ;
14- let filteredTestCasesReadyList = [ ] ;
15- configs . suites . forEach ( suite => {
16- let testCasesReady = TestCases . collectTestCases ( suite . suite ) ;
17- testCasesReadyList . push ( testCasesReady ) ;
18- testCasesReady . then ( testCases => {
19- let filteredTestCasesReady = TestCases . filterTestCases ( testCases , suite . suite , filters ) ;
20- filteredTestCasesReadyList . push ( filteredTestCasesReady ) ;
15+ try {
16+ assert ( TestCasesConfig . isTestCasesConfig ( configs ) , "test cases config schema validation failed" ) ;
17+ let testCasesReadyList = [ ] ;
18+ let filteredTestCasesReadyList = [ ] ;
19+ configs . suites . forEach ( suite => {
20+ let testCasesReady = TestCases . collectTestCases ( suite . suite ) ;
21+ testCasesReadyList . push ( testCasesReady ) ;
22+ testCasesReady . then ( testCases => {
23+ let filteredTestCasesReady = TestCases . filterTestCases ( testCases , suite . suite , filters ) ;
24+ filteredTestCasesReadyList . push ( filteredTestCasesReady ) ;
25+ } ) . catch ( err => {
26+ return reject ( err ) ;
27+ } ) ;
2128 } ) ;
22- } ) ;
23- Promise . all ( testCasesReadyList ) . then ( testCasesList => {
24- testCasesList = testCasesList . flat ( 1 ) ;
25- Promise . all ( filteredTestCasesReadyList ) . then ( filteredTestCasesList => {
26- filteredTestCasesList = filteredTestCasesList . flat ( 1 ) ;
27- return resolve ( { testCases : testCasesList , filteredTestCases : filteredTestCasesList } ) ;
29+ Promise . all ( testCasesReadyList ) . then ( testCasesList => {
30+ testCasesList = testCasesList . flat ( 1 ) ;
31+ Promise . all ( filteredTestCasesReadyList ) . then ( filteredTestCasesList => {
32+ filteredTestCasesList = filteredTestCasesList . flat ( 1 ) ;
33+ return resolve ( { testCases : testCasesList , filteredTestCases : filteredTestCasesList } ) ;
34+ } ) ;
35+ } ) . catch ( err => {
36+ return reject ( err ) ;
2837 } ) ;
29- } ) ;
38+ } catch ( err ) {
39+ return reject ( err ) ;
40+ }
3041 } ) ;
3142 } ) ;
3243 }
@@ -49,10 +60,14 @@ class TestCases {
4960 testCasesReady . push ( testCaseReady ) ;
5061 testCaseReady . then ( newTestCases => {
5162 testCases = testCases . concat ( newTestCases ) ;
63+ } ) . catch ( err => {
64+ return reject ( err ) ;
5265 } ) ;
5366 } ) ;
5467 Promise . all ( testCasesReady ) . then ( ( ) => {
5568 return resolve ( testCases ) ;
69+ } ) . catch ( err => {
70+ return reject ( err ) ;
5671 } ) ;
5772 }
5873 } ) ;
@@ -71,7 +86,7 @@ class TestCases {
7186 }
7287
7388
74- static filterTestCases ( testCases , suitePath , filters ) {
89+ static filterTestCases ( testCases , suitePath , filters = [ ] ) {
7590 return new Promise ( ( resolve , reject ) => {
7691 let filteredTestCases = [ ] ;
7792 if ( filters . length === 0 ) {
@@ -89,7 +104,11 @@ class TestCases {
89104 if ( testCases . includes ( filter ) ) {
90105 filteredTestCases . push ( filter ) ;
91106 } else {
92- let filterWithSuitePath = path . join ( suitePath , filter ) ;
107+ let filterPathInSuite = "/" + path . join (
108+ path . relative (
109+ TestEnv . getWorkspacePath ( ) ,
110+ suitePath ) ,
111+ filter ) ;
93112 let filterRelative = "/" + path . relative (
94113 TestEnv . getWorkspacePath ( ) ,
95114 WorkspacePath . resolvePath (
@@ -99,8 +118,8 @@ class TestCases {
99118 let filterAbsolute = "/" + path . relative (
100119 TestEnv . getWorkspacePath ( ) ,
101120 filter ) ;
102- if ( testCases . includes ( filterWithSuitePath ) ) {
103- filteredTestCases . push ( filterWithSuitePath ) ;
121+ if ( testCases . includes ( filterPathInSuite ) ) {
122+ filteredTestCases . push ( filterPathInSuite ) ;
104123 } else if ( testCases . includes ( filterRelative ) ) {
105124 filteredTestCases . push ( filterRelative ) ;
106125 } else if ( testCases . includes ( filterAbsolute ) ) {
0 commit comments