@@ -20,6 +20,7 @@ const { exists } = require('mz/fs');
20
20
const yargs = require ( 'yargs' ) ;
21
21
const glob = require ( 'glob' ) ;
22
22
const path = require ( 'path' ) ;
23
+ const chalk = require ( 'chalk' ) ;
23
24
24
25
// Check for 'configFiles' flag to run on specified karma.conf.js files instead
25
26
// of on all files.
@@ -37,9 +38,11 @@ const { configFiles } = yargs
37
38
const testFiles = configFiles . length
38
39
? configFiles
39
40
: glob
40
- . sync ( `{packages,integration}/*/karma.conf.js` )
41
- // Automated tests in integration/firestore are currently disabled.
42
- . filter ( name => ! name . includes ( 'integration/firestore' ) ) ;
41
+ . sync ( `packages/*/karma.conf.js` )
42
+ // Skip integration namespace tests, not very useful, introduce errors.
43
+ . concat ( 'integration/firestore/karma.conf.js' )
44
+ // Exclude database - currently too many failures.
45
+ . filter ( name => ! name . includes ( 'packages/database' ) ) ;
43
46
44
47
// Get CI build number or generate one if running locally.
45
48
const buildNumber =
@@ -54,22 +57,60 @@ const buildNumber =
54
57
* group.
55
58
*/
56
59
async function runTest ( testFile ) {
60
+ if ( ! ( await exists ( testFile ) ) ) {
61
+ console . error ( chalk `{red ERROR: ${ testFile } does not exist.}` ) ;
62
+ return 1 ;
63
+ }
57
64
// Run pretest if this dir has a package.json with a pretest script.
58
65
const testFileDir =
59
66
path . resolve ( __dirname , '../' ) + '/' + path . dirname ( testFile ) ;
60
67
const pkgPath = testFileDir + '/package.json' ;
68
+ let pkgName = testFile ;
61
69
if ( await exists ( pkgPath ) ) {
62
70
const pkg = require ( pkgPath ) ;
71
+ pkgName = pkg . name ;
63
72
if ( pkg . scripts . pretest ) {
64
73
await spawn ( 'yarn' , [ '--cwd' , testFileDir , 'pretest' ] , {
65
74
stdio : 'inherit'
66
75
} ) ;
67
76
}
68
77
}
69
- return runKarma ( testFile ) ;
78
+ if ( testFile . includes ( 'integration/firestore' ) ) {
79
+ console . log (
80
+ chalk `{blue Generating memory-only build for integration/firestore.}`
81
+ ) ;
82
+ await spawn ( 'yarn' , [ '--cwd' , 'integration/firestore' , 'build:memory' ] , {
83
+ stdio : 'inherit'
84
+ } ) ;
85
+ console . log (
86
+ chalk `{blue Running tests on memory-only build for integration/firestore.}`
87
+ ) ;
88
+ const exitCode1 = await runKarma ( testFile , `${ pkgName } -memory` ) ;
89
+ console . log (
90
+ chalk `{blue Generating persistence build for integration/firestore.}`
91
+ ) ;
92
+ await spawn (
93
+ 'yarn' ,
94
+ [ '--cwd' , 'integration/firestore' , 'build:persistence' ] ,
95
+ { stdio : 'inherit' }
96
+ ) ;
97
+ console . log (
98
+ chalk `{blue Running tests on persistence build for integration/firestore.}`
99
+ ) ;
100
+ const exitCode2 = await runKarma ( testFile , `${ pkgName } -persistence` ) ;
101
+ return Math . max ( exitCode1 , exitCode2 ) ;
102
+ } else {
103
+ return runKarma ( testFile , pkgName ) ;
104
+ }
70
105
}
71
106
72
- async function runKarma ( testFile ) {
107
+ /**
108
+ * Runs the karma test command for one package.
109
+ *
110
+ * @param {string } testFile - path to karma.conf.js file
111
+ * @param {string } testTag - package label for messages (usually package name)
112
+ */
113
+ async function runKarma ( testFile , testTag ) {
73
114
const karmaArgs = [
74
115
'karma' ,
75
116
'start' ,
@@ -92,11 +133,11 @@ async function runKarma(testFile) {
92
133
93
134
return promise
94
135
. then ( ( ) => {
95
- console . log ( ` [${ testFile } ] ******* DONE *******`) ;
136
+ console . log ( chalk `{green [${ testTag } ] ******* DONE *******} `) ;
96
137
return exitCode ;
97
138
} )
98
139
. catch ( err => {
99
- console . error ( ` [${ testFile } ] ERROR:` , err . message ) ;
140
+ console . error ( chalk `{red [${ testTag } ] ERROR: ${ err . message } }` ) ;
100
141
return exitCode ;
101
142
} ) ;
102
143
}
@@ -109,19 +150,29 @@ async function runKarma(testFile) {
109
150
* of all child processes. This allows any failing test to result in a CI
110
151
* build failure for the whole Saucelabs run.
111
152
*/
112
- async function runNextTest ( maxExitCode = 0 ) {
153
+ async function runNextTest ( maxExitCode = 0 , results = { } ) {
113
154
// When test queue is empty, exit with code 0 if no tests failed or
114
155
// 1 if any tests failed.
115
- if ( ! testFiles . length ) process . exit ( maxExitCode ) ;
156
+ if ( ! testFiles . length ) {
157
+ for ( const fileName of Object . keys ( results ) ) {
158
+ if ( results [ fileName ] > 0 ) {
159
+ console . log ( `FAILED: ${ fileName } ` ) ;
160
+ }
161
+ }
162
+ process . exit ( maxExitCode ) ;
163
+ }
116
164
const nextFile = testFiles . shift ( ) ;
117
165
let exitCode ;
118
166
try {
119
167
exitCode = await runTest ( nextFile ) ;
120
168
} catch ( e ) {
121
- console . error ( ` [${ nextFile } ] ERROR:` , e . message ) ;
169
+ console . error ( chalk `{red [${ nextFile } ] ERROR: ${ e . message } }` ) ;
122
170
exitCode = 1 ;
123
171
}
124
- runNextTest ( Math . max ( exitCode , maxExitCode ) ) ;
172
+ runNextTest ( Math . max ( exitCode , maxExitCode ) , {
173
+ ...results ,
174
+ [ nextFile ] : exitCode
175
+ } ) ;
125
176
}
126
177
127
178
runNextTest ( ) ;
0 commit comments