Skip to content

Commit f362e74

Browse files
committed
build only packages needed for testing
1 parent eb55e6f commit f362e74

File tree

7 files changed

+78
-19
lines changed

7 files changed

+78
-19
lines changed

integration/firestore/firebase_export.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firebase from 'firebase/app';
19-
import 'firebase/firestore';
18+
import firebase from '@firebase/app';
19+
import '@firebase/firestore';
20+
import { FirebaseApp } from '@firebase/app-types';
21+
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2022

2123
// This file replaces "packages/firestore/test/integration/util/firebase_export"
2224
// and depends on the minified sources.
@@ -25,9 +27,9 @@ let appCount = 0;
2527

2628
export function newTestFirestore(
2729
projectId: string,
28-
nameOrApp?: string | firebase.app.App,
29-
settings?: firebase.firestore.Settings
30-
): firebase.firestore.Firestore {
30+
nameOrApp?: string | FirebaseApp,
31+
settings?: Settings
32+
): FirebaseFirestore {
3133
if (nameOrApp === undefined) {
3234
nameOrApp = 'test-app-' + appCount++;
3335
}
@@ -36,7 +38,7 @@ export function newTestFirestore(
3638
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
3739
: nameOrApp;
3840

39-
const firestore = firebase.firestore(app);
41+
const firestore = firebase.firestore!(app);
4042
if (settings) {
4143
firestore.settings(settings);
4244
}

integration/firestore/firebase_export_memory.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firebase from 'firebase/app';
19-
import 'firebase/firestore/memory';
18+
import firebase from '@firebase/app';
19+
import '@firebase/firestore/memory';
20+
import { FirebaseApp } from '@firebase/app-types';
21+
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2022

2123
// This file replaces "packages/firestore/test/integration/util/firebase_export"
2224
// and depends on the minified sources.
@@ -25,9 +27,9 @@ let appCount = 0;
2527

2628
export function newTestFirestore(
2729
projectId: string,
28-
nameOrApp?: string | firebase.app.App,
29-
settings?: firebase.firestore.Settings
30-
): firebase.firestore.Firestore {
30+
nameOrApp?: string | FirebaseApp,
31+
settings?: Settings
32+
): FirebaseFirestore {
3133
if (nameOrApp === undefined) {
3234
nameOrApp = 'test-app-' + appCount++;
3335
}

integration/firestore/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
"test:memory": "yarn build:memory; karma start --single-run",
1414
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
1515
},
16-
"peerDependencies": {
17-
"@firebase/app": "0.x",
18-
"@firebase/firestore": "1.16.4"
19-
},
2016
"devDependencies": {
17+
"@firebase/app": "0.6.10",
18+
"@firebase/firestore": "1.16.4",
2119
"@types/mocha": "7.0.2",
2220
"gulp": "4.0.2",
2321
"gulp-filter": "6.0.0",

packages/firestore/register-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as types from '@firebase/firestore-types';
1919

2020
declare module '@firebase/app-types' {
2121
interface FirebaseNamespace {
22-
firestore?: {
22+
firestore: {
2323
(app?: FirebaseApp): types.FirebaseFirestore;
2424
Blob: typeof types.Blob;
2525
CollectionReference: typeof types.CollectionReference;

scripts/ci-test/build.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { TestTask, TestReason } from './run_changed';
19+
import { spawn } from 'child-process-promise';
20+
import chalk from 'chalk';
21+
import { resolve } from 'path';
22+
const root = resolve(__dirname, '../..');
23+
24+
export async function buildForTests(testTasks: TestTask[]) {
25+
try {
26+
if (testTasks.length === 0) {
27+
chalk`{green No test tasks. Skipping all tests }`;
28+
process.exit(0);
29+
}
30+
31+
const lernaCmd = ['lerna', 'run'];
32+
console.log(chalk`{blue Running build in:}`);
33+
for (const task of testTasks) {
34+
if (task.reason === TestReason.Changed) {
35+
console.log(chalk`{yellow ${task.pkgName} (contains modified files)}`);
36+
} else if (task.reason === TestReason.Dependent) {
37+
console.log(
38+
chalk`{yellow ${task.pkgName} (depends on modified files)}`
39+
);
40+
} else {
41+
console.log(chalk`{yellow ${task.pkgName} (running all tests)}`);
42+
}
43+
lernaCmd.push('--scope');
44+
lernaCmd.push(task.pkgName);
45+
}
46+
47+
lernaCmd.push('--include-dependencies', 'build');
48+
await spawn('npx', lernaCmd, { stdio: 'inherit', cwd: root });
49+
process.exit(0);
50+
} catch (e) {
51+
console.error(chalk`{red ${e}}`);
52+
process.exit(1);
53+
}
54+
}

scripts/ci-test/run_changed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import { resolve } from 'path';
1919
import { spawn, exec } from 'child-process-promise';
2020
import chalk from 'chalk';
2121
import simpleGit from 'simple-git/promise';
22-
const root = resolve(__dirname, '..');
22+
const root = resolve(__dirname, '../..');
2323
const git = simpleGit(root);
2424

25-
interface TestTask {
25+
export interface TestTask {
2626
pkgName: string;
2727
reason: TestReason;
2828
}
2929

30-
enum TestReason {
30+
export enum TestReason {
3131
Changed = 'changed',
3232
Dependent = 'dependent',
3333
Global = 'global'

scripts/ci-test/run_changed_no_firestore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { runTests, getTestTasks, createTestTask } from './run_changed';
19+
import { buildForTests } from './build';
1920

2021
/**
2122
* Always run tests in these paths.
@@ -44,6 +45,8 @@ async function run() {
4445
// remove the ignored packages from the tasks
4546
testTasks = testTasks.filter(t => !ignoredPackages.includes(t.pkgName));
4647

48+
await buildForTests(testTasks);
49+
4750
runTests(testTasks);
4851
}
4952

0 commit comments

Comments
 (0)