@@ -47,31 +47,31 @@ const fullTestTriggerFiles = [
47
47
/**
48
48
* Always run tests in these paths.
49
49
*/
50
- const alwaysRunTestPaths = [
50
+ const alwaysRunTestPackages = [
51
51
// These tests are very fast.
52
- 'integration/ browserify' ,
53
- 'integration/ firebase-typings' ,
54
- 'integration/ typescript' ,
55
- 'integration/ webpack'
52
+ 'firebase- browserify-test ' ,
53
+ 'firebase-package- typings-test ' ,
54
+ 'firebase- typescript-test ' ,
55
+ 'firebase- webpack-test '
56
56
] ;
57
57
58
58
/**
59
59
* These files trigger tests in other dirs
60
60
*/
61
61
const specialPaths = {
62
62
'scripts/emulator-testing/emulators/firestore-emulator.ts' : [
63
- 'packages /firestore'
63
+ '@firebase /firestore'
64
64
] ,
65
65
'scripts/emulator-testing/emulators/database-emulator.ts' : [
66
- 'packages /database'
66
+ '@firebase /database'
67
67
] ,
68
68
'scripts/emulator-testing/emulators/emulator.ts' : [
69
- 'packages /firestore' ,
70
- 'packages /database'
69
+ '@firebase /firestore' ,
70
+ '@firebase /database'
71
71
] ,
72
- 'scripts/emulator-testing/firestore-test-runner.ts' : [ 'packages /firestore' ] ,
73
- 'scripts/emulator-testing/database-test-runner.ts' : [ 'packages /database' ] ,
74
- 'packages/firestore' : [ 'integration/ firestore' ]
72
+ 'scripts/emulator-testing/firestore-test-runner.ts' : [ '@firebase /firestore' ] ,
73
+ 'scripts/emulator-testing/database-test-runner.ts' : [ '@firebase /database' ] ,
74
+ 'packages/firestore' : [ 'firebase- firestore-integration-test ' ]
75
75
} ;
76
76
77
77
/**
@@ -101,7 +101,9 @@ async function getChangedPackages() {
101
101
) ;
102
102
for ( const matchingSpecialPath of matchingSpecialPaths ) {
103
103
for ( const targetPackage of specialPaths [ matchingSpecialPath ] ) {
104
- changedPackages [ targetPackage ] = 'dependency' ;
104
+ if ( ! changedPackages [ targetPackage ] ) {
105
+ changedPackages [ targetPackage ] = 'dependency' ;
106
+ }
105
107
}
106
108
}
107
109
// Check for changed files inside package dirs.
@@ -110,7 +112,7 @@ async function getChangedPackages() {
110
112
const changedPackage = require ( resolve ( root , match [ 1 ] , 'package.json' ) ) ;
111
113
if ( changedPackage ) {
112
114
// Add the package itself.
113
- changedPackages [ match [ 1 ] ] = 'direct' ;
115
+ changedPackages [ changedPackage . name ] = 'direct' ;
114
116
// Add packages that depend on it.
115
117
for ( const package in depGraph ) {
116
118
if ( depGraph [ package ] . includes ( changedPackage . name ) ) {
@@ -121,9 +123,8 @@ async function getChangedPackages() {
121
123
'package.json'
122
124
) ) ;
123
125
if ( depPkgJson ) {
124
- const depPath = depData . location . replace ( `${ root } /` , '' ) ;
125
- if ( ! changedPackages [ depPath ] ) {
126
- changedPackages [ depPath ] = 'dependency' ;
126
+ if ( ! changedPackages [ depPkgJson . name ] ) {
127
+ changedPackages [ depPkgJson . name ] = 'dependency' ;
127
128
}
128
129
}
129
130
}
@@ -145,23 +146,6 @@ async function getChangedPackages() {
145
146
}
146
147
}
147
148
148
- /**
149
- * Runs `yarn test` in all dirs in pathList.
150
- * @param {Array<string> } pathList
151
- */
152
- async function runTests ( pathList ) {
153
- if ( ! pathList ) return ;
154
- for ( const testPath of pathList ) {
155
- try {
156
- await spawn ( 'yarn' , [ '--cwd' , testPath , testCommand ] , {
157
- stdio : 'inherit'
158
- } ) ;
159
- } catch ( e ) {
160
- throw new Error ( `Error running "yarn ${ testCommand } " in ${ testPath } .` ) ;
161
- }
162
- }
163
- }
164
-
165
149
async function main ( ) {
166
150
try {
167
151
const { testAll, changedPackages = { } } = await getChangedPackages ( ) ;
@@ -171,22 +155,33 @@ async function main() {
171
155
} ) ;
172
156
} else {
173
157
console . log ( chalk `{blue Running tests in:}` ) ;
174
- for ( const filename of alwaysRunTestPaths ) {
158
+ for ( const packageName of alwaysRunTestPackages ) {
175
159
// array
176
- console . log ( chalk `{green ${ filename } (always runs)}` ) ;
160
+ console . log ( chalk `{green ${ packageName } (always runs)}` ) ;
177
161
}
178
- for ( const filename in changedPackages ) {
162
+ for ( const packageName in changedPackages ) {
179
163
// obj
180
- if ( changedPackages [ filename ] === 'direct' ) {
181
- console . log ( chalk `{yellow ${ filename } (contains modified files)}` ) ;
164
+ if ( changedPackages [ packageName ] === 'direct' ) {
165
+ console . log ( chalk `{yellow ${ packageName } (contains modified files)}` ) ;
182
166
} else {
183
- console . log ( chalk `{yellow ${ filename } (depends on modified files)}` ) ;
167
+ console . log (
168
+ chalk `{yellow ${ packageName } (depends on modified files)}`
169
+ ) ;
184
170
}
185
171
}
186
172
187
173
changedPackages [ 'packages/app' ] = 'direct' ;
188
- await runTests ( alwaysRunTestPaths ) ;
189
- await runTests ( Object . keys ( changedPackages ) ) ;
174
+ let lernaCmds = [ 'lerna' , 'run' , '--concurrency' , '4' , '--stream' ] ;
175
+ const packagesToRun = alwaysRunTestPackages . concat (
176
+ Object . keys ( changedPackages )
177
+ ) ;
178
+ for ( const packageToRun of packagesToRun ) {
179
+ lernaCmds . push ( '--scope' ) ;
180
+ lernaCmds . push ( packageToRun ) ;
181
+ }
182
+ lernaCmds . push ( testCommand ) ;
183
+ await spawn ( 'npx' , lernaCmds , { stdio : 'inherit' , cwd : root } ) ;
184
+ process . exit ( ) ;
190
185
}
191
186
} catch ( e ) {
192
187
console . error ( chalk `{red ${ e } }` ) ;
0 commit comments