@@ -20,6 +20,7 @@ const { exists } = require('mz/fs');
2020const yargs = require ( 'yargs' ) ;
2121const glob = require ( 'glob' ) ;
2222const path = require ( 'path' ) ;
23+ const chalk = require ( 'chalk' ) ;
2324
2425// Check for 'configFiles' flag to run on specified karma.conf.js files instead
2526// of on all files.
@@ -37,9 +38,11 @@ const { configFiles } = yargs
3738const testFiles = configFiles . length
3839 ? configFiles
3940 : 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' ) ) ;
4346
4447// Get CI build number or generate one if running locally.
4548const buildNumber =
@@ -54,22 +57,60 @@ const buildNumber =
5457 * group.
5558 */
5659async function runTest ( testFile ) {
60+ if ( ! ( await exists ( testFile ) ) ) {
61+ console . error ( chalk `{red ERROR: ${ testFile } does not exist.}` ) ;
62+ return 1 ;
63+ }
5764 // Run pretest if this dir has a package.json with a pretest script.
5865 const testFileDir =
5966 path . resolve ( __dirname , '../' ) + '/' + path . dirname ( testFile ) ;
6067 const pkgPath = testFileDir + '/package.json' ;
68+ let pkgName = testFile ;
6169 if ( await exists ( pkgPath ) ) {
6270 const pkg = require ( pkgPath ) ;
71+ pkgName = pkg . name ;
6372 if ( pkg . scripts . pretest ) {
6473 await spawn ( 'yarn' , [ '--cwd' , testFileDir , 'pretest' ] , {
6574 stdio : 'inherit'
6675 } ) ;
6776 }
6877 }
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+ }
70105}
71106
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 ) {
73114 const karmaArgs = [
74115 'karma' ,
75116 'start' ,
@@ -92,11 +133,11 @@ async function runKarma(testFile) {
92133
93134 return promise
94135 . then ( ( ) => {
95- console . log ( ` [${ testFile } ] ******* DONE *******`) ;
136+ console . log ( chalk `{green [${ testTag } ] ******* DONE *******} `) ;
96137 return exitCode ;
97138 } )
98139 . catch ( err => {
99- console . error ( ` [${ testFile } ] ERROR:` , err . message ) ;
140+ console . error ( chalk `{red [${ testTag } ] ERROR: ${ err . message } }` ) ;
100141 return exitCode ;
101142 } ) ;
102143}
@@ -109,19 +150,29 @@ async function runKarma(testFile) {
109150 * of all child processes. This allows any failing test to result in a CI
110151 * build failure for the whole Saucelabs run.
111152 */
112- async function runNextTest ( maxExitCode = 0 ) {
153+ async function runNextTest ( maxExitCode = 0 , results = { } ) {
113154 // When test queue is empty, exit with code 0 if no tests failed or
114155 // 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+ }
116164 const nextFile = testFiles . shift ( ) ;
117165 let exitCode ;
118166 try {
119167 exitCode = await runTest ( nextFile ) ;
120168 } catch ( e ) {
121- console . error ( ` [${ nextFile } ] ERROR:` , e . message ) ;
169+ console . error ( chalk `{red [${ nextFile } ] ERROR: ${ e . message } }` ) ;
122170 exitCode = 1 ;
123171 }
124- runNextTest ( Math . max ( exitCode , maxExitCode ) ) ;
172+ runNextTest ( Math . max ( exitCode , maxExitCode ) , {
173+ ...results ,
174+ [ nextFile ] : exitCode
175+ } ) ;
125176}
126177
127178runNextTest ( ) ;
0 commit comments