Skip to content

Commit de8c146

Browse files
authored
Adding Firestore minified int tests (#199)
* Fixing firestore integration tests * Regen yarn.lock * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * Refactor timeout/retry logic to be globally applied * Documenting changes to firestore int tests * Fixing tests to properly build the firestore int tests * Trim dist directory for consistent rebuilds * [AUTOMATED]: Prettier Code Styling * Fixing some whitespace issues
1 parent 1d9f803 commit de8c146

File tree

14 files changed

+183
-265
lines changed

14 files changed

+183
-265
lines changed

config/karma.base.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,14 @@ const config = {
102102
startConnect: false
103103
},
104104

105-
singleRun: false
105+
singleRun: false,
106+
107+
client: {
108+
mocha: {
109+
timeout: 20000,
110+
retries: 3
111+
}
112+
}
106113
};
107114

108115
// In CI environment, use saucelabs to test

integration/firestore/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
temp

integration/firestore/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@ These tests are intended to be run against the minified compiled version of the
22
firebase binary (i.e. `firebase.js` and `firebase-firestore.js` of the `firebase`
33
package).
44

5-
They are currently just rerunning tests against the uncompiled version and we
6-
need to address that.
5+
The integration test files are modified to replace references to the
6+
`firebase_export` entrypoint with the following `declare` statement:
7+
8+
```typescript
9+
declare var firebase;
10+
```
11+
12+
This will help the test files pass the compile step, and will allow us to, at
13+
test time, inject the firebase variable into global scope (from the compiled)
14+
files, which will be used by the tests.

integration/firestore/firebase_export.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

integration/firestore/gulpfile.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const gulp = require('gulp');
18+
const replace = require('gulp-replace');
19+
const { resolve } = require('path');
20+
const webpackStream = require('webpack-stream');
21+
const webpack = require('webpack');
22+
const filter = require('gulp-filter');
23+
24+
function reworkFirebasePaths() {
25+
return gulp
26+
.src(
27+
[
28+
resolve(__dirname, '../../packages/firestore/**/*.ts'),
29+
`!${resolve(__dirname, '../../packages/firestore/node_modules/**/*')}`,
30+
`!${resolve(__dirname, '../../packages/firestore/dist/**/*')}`
31+
],
32+
{ base: '../../packages/firestore' }
33+
)
34+
.pipe(
35+
replace(
36+
/**
37+
* This regex is designed to match the following statement used in our
38+
* firestore integratino test suites:
39+
*
40+
* import firebase from '../../util/firebase_export';
41+
*
42+
* It will handle variations in whitespace, single/double quote
43+
* differences, as well as different paths to a valid firebase_export
44+
*/
45+
/import\s+firebase\s+from\s+('|")[^\1]+firebase_export\1;?/,
46+
'declare var firebase;'
47+
)
48+
)
49+
.pipe(
50+
/**
51+
* Fixing the project.json require to properly reference the file
52+
*/
53+
replace(
54+
'../../../../../config/project.json',
55+
'../../../../../../config/project.json'
56+
)
57+
)
58+
.pipe(gulp.dest('temp'));
59+
}
60+
61+
function compileWebpack() {
62+
const config = require('../../config/webpack.test');
63+
return gulp
64+
.src('./temp/test/integration/**/*.ts')
65+
.pipe(
66+
webpackStream(
67+
Object.assign({}, config, {
68+
output: {
69+
filename: 'test-harness.js'
70+
}
71+
}),
72+
webpack
73+
)
74+
)
75+
.pipe(filter(['**', '!**/*.d.ts']))
76+
.pipe(gulp.dest('dist'));
77+
}
78+
79+
gulp.task('compile-tests', gulp.series(reworkFirebasePaths, compileWebpack));

integration/firestore/hijack-promise.test.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

integration/firestore/karma.conf.js

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
const webpackConfig = require('./webpack.config');
17+
const karma = require('karma');
18+
const path = require('path');
19+
const karmaBase = require('../../config/karma.base');
1820

19-
// Karma configuration
2021
module.exports = function(config) {
21-
config.set({
22+
const karmaConfig = Object.assign({}, karmaBase, {
23+
// files to load into karma
24+
files: [
25+
`${path.dirname(require.resolve('firebase'))}/firebase.js`,
26+
`${path.dirname(require.resolve('firebase'))}/firebase-firestore.js`,
27+
'./dist/test-harness.js'
28+
],
2229
// frameworks to use
2330
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
24-
frameworks: ['mocha'],
25-
26-
// list of files / patterns to load in the browser
27-
files: [{ pattern: 'tests/**/*.test.ts' }],
28-
29-
client: {
30-
mocha: {
31-
// Set timeout / retries to match what's configured in /gulp/config.js
32-
timeout: 5000,
33-
retries: 5
34-
}
35-
},
36-
37-
preprocessors: {
38-
'**/*.ts': ['webpack']
39-
},
40-
41-
mime: {
42-
'text/x-typescript': ['ts', 'tsx']
43-
},
44-
45-
// test results reporter to use
46-
// possible values: 'dots', 'progress'
47-
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
48-
reporters: ['spec'],
49-
50-
// enable / disable colors in the output (reporters and logs)
51-
colors: true,
52-
53-
// level of logging
54-
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
55-
logLevel: config.LOG_INFO,
56-
57-
// enable / disable watching file and executing tests whenever any file changes
58-
autoWatch: false,
59-
60-
// start these browsers
61-
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
62-
browsers: ['ChromeHeadless'],
63-
64-
// Continuous Integration mode
65-
// if true, Karma captures browsers, runs the tests and exits
66-
singleRun: true,
67-
68-
webpack: webpackConfig
31+
frameworks: ['mocha']
6932
});
33+
34+
config.set(karmaConfig);
7035
};

integration/firestore/package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
{
22
"name": "firebase-firestore-integration-test",
33
"version": "1.0.0",
4-
"main": "runner.sh",
4+
"scripts": {
5+
"pretest": "gulp compile-tests",
6+
"test": "karma start --single-run"
7+
},
58
"devDependencies": {
6-
"@types/chai": "^3.4.35",
79
"@types/mocha": "^2.2.39",
810
"@types/node": "^7.0.8",
9-
"chai": "^3.5.0",
11+
"gulp": "gulpjs/gulp#4.0",
12+
"gulp-filter": "^5.0.1",
13+
"gulp-replace": "^0.6.1",
1014
"karma": "^1.7.0",
1115
"karma-chrome-launcher": "^2.2.0",
1216
"karma-mocha": "^1.3.0",
1317
"karma-spec-reporter": "0.0.31",
14-
"karma-typescript": "^3.0.6",
15-
"karma-webpack": "^2.0.4",
1618
"mocha": "^3.5.0",
1719
"ts-loader": "^2.3.6",
1820
"typescript": "^2.4.2",
19-
"webpack": "^3.5.6"
21+
"webpack": "^3.6.0",
22+
"webpack-stream": "^4.0.0"
2023
}
2124
}

integration/firestore/runner.sh

Lines changed: 0 additions & 72 deletions
This file was deleted.

integration/firestore/tsconfig.json

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
11
{
2-
"compileOnSave": false,
3-
"compilerOptions": {
4-
"allowJs": true,
5-
"lib": [
6-
"es5",
7-
"es2015",
8-
"es2015.promise",
9-
"dom"
10-
],
11-
"module": "commonjs",
12-
"moduleResolution": "node",
13-
"outDir": "tmp",
14-
"target": "ES5",
15-
"sourceMap": true,
16-
"typeRoots" : [
17-
"node_modules/@types"
18-
]
19-
},
20-
"exclude": [
21-
"node_modules"
22-
]
2+
"extends": "../../config/tsconfig.base.json"
233
}

0 commit comments

Comments
 (0)