Skip to content

Commit 3c21efe

Browse files
authored
Run integration/firestore tests in Saucelabs (#3319)
1 parent 23891b2 commit 3c21efe

File tree

4 files changed

+88
-32
lines changed

4 files changed

+88
-32
lines changed

config/karma.saucelabs.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,22 @@ const browserMap = {
4646
* Any special options per package.
4747
*/
4848
const packageConfigs = {
49-
messaging: {
49+
'@firebase/messaging': {
5050
// Messaging currently only supports these browsers.
5151
browsers: ['Chrome_Windows', 'Firefox_Windows', 'Edge_Windows']
5252
},
53-
firestore: {
53+
// Firestore unit tests have OOM problems compiling with Babel for IE.
54+
// Firestore integration/firestore tests do run on all browsers.
55+
'@firebase/firestore': {
56+
browsers: [
57+
'Chrome_Windows',
58+
'Firefox_Windows',
59+
'Edge_Windows',
60+
'Safari_macOS'
61+
]
62+
},
63+
// Installations has IE errors related to `idb` library that need to be figured out.
64+
'@firebase/installations': {
5465
browsers: [
5566
'Chrome_Windows',
5667
'Firefox_Windows',
@@ -84,12 +95,12 @@ function getSauceLabsBrowsers(packageName) {
8495
*/
8596
function getPackageLabels() {
8697
const match = testConfigFile.match(
87-
/([a-zA-Z]+)\/([a-zA-Z-]+)\/karma\.conf\.js/
98+
/([a-zA-Z]+\/[a-zA-Z-]+)\/karma\.conf\.js/
8899
);
89-
return {
90-
type: match[1],
91-
name: match[2]
92-
};
100+
const packagePath = match[1];
101+
const root = path.resolve(__dirname, '..');
102+
const pkg = require(path.join(root, packagePath, 'package.json'));
103+
return pkg.name;
93104
}
94105

95106
/**
@@ -106,11 +117,8 @@ function getTestFiles() {
106117
}
107118

108119
function seleniumLauncher(browserName, platform, version) {
109-
const { name, type } = getPackageLabels();
110-
const testName =
111-
type === 'integration'
112-
? `${type}-${name}-${browserName}`
113-
: `${name}-${browserName}`;
120+
const { name } = getPackageLabels();
121+
const testName = `${name}-${browserName}`;
114122
return {
115123
base: 'SauceLabs',
116124
browserName: browserName,
@@ -150,8 +158,8 @@ module.exports = function(config) {
150158
const sauceLabsBrowsers = getSauceLabsBrowsers(packageName);
151159

152160
const sauceLabsConfig = {
153-
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER + '-' + packageName,
154-
build: process.env.TRAVIS_BUILD_NUMBER || argv['buildNumber'],
161+
tunnelIdentifier: process.env.GITHUB_RUN_ID + '-' + packageName,
162+
build: process.env.GITHUB_RUN_ID || argv['buildNumber'],
155163
username: process.env.SAUCE_USERNAME,
156164
accessKey: process.env.SAUCE_ACCESS_KEY,
157165
startConnect: true,
@@ -210,7 +218,7 @@ module.exports = function(config) {
210218
maxLogLines: 5,
211219
suppressErrorSummary: false,
212220
suppressFailed: false,
213-
suppressPassed: false,
221+
suppressPassed: true,
214222
suppressSkipped: true,
215223
showSpecTiming: true,
216224
failFast: false

integration/firestore/karma.conf.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,11 +19,7 @@ const karma = require('karma');
1919
const path = require('path');
2020
const karmaBase = require('../../config/karma.base');
2121

22-
const files = [
23-
`${path.dirname(require.resolve('firebase'))}/firebase.js`,
24-
`${path.dirname(require.resolve('firebase'))}/firebase-firestore.js`,
25-
'./dist/test-harness.js'
26-
];
22+
const files = ['./dist/test-harness.js'];
2723

2824
module.exports = function(config) {
2925
const karmaConfig = Object.assign({}, karmaBase, {

packages/polyfill/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ import 'core-js/features/symbol/iterator';
3838
import 'core-js/features/map';
3939
import 'core-js/features/set';
4040
import 'core-js/features/number/is-integer';
41+
import 'core-js/features/number/is-nan';

scripts/run_saucelabs.js

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const { exists } = require('mz/fs');
2020
const yargs = require('yargs');
2121
const glob = require('glob');
2222
const 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
3738
const 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.
4548
const buildNumber =
@@ -54,22 +57,60 @@ const buildNumber =
5457
* group.
5558
*/
5659
async 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

127178
runNextTest();

0 commit comments

Comments
 (0)