Skip to content

Commit c9a881e

Browse files
author
Brian Chen
authored
Make running against the emulator the default for Firestore integration tests (#1995)
1 parent c8bbad8 commit c9a881e

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

packages/firestore/CONTRIBUTING.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ contributing to the Firebase JavaScript SDK (including Cloud Firestore).
55
Follow instructions there to install dependencies, build the SDK, and set up
66
the testing environment.
77

8-
## Setting up a project for testing
8+
## Integration Testing
9+
10+
### Setting up a project for testing
911

1012
You will need a production project to test the Firestore SDK. You can create
1113
a new project by visiting the
@@ -16,10 +18,28 @@ See
1618
[Automated Setup](https://github.com/firebase/firebase-js-sdk#automated-setup)
1719
for more details.
1820

21+
### Setting up the Firestore emulator
22+
23+
The integration tests require that the Firestore emulator is running
24+
on port 8080, which is default when running it via CLI.
25+
26+
* [Install the Firebase CLI](https://firebase.google.com/docs/cli/).
27+
```
28+
npm install -g firebase-tools
29+
```
30+
* [Install the Firestore
31+
emulator](https://firebase.google.com/docs/firestore/security/test-rules-emulator#install_the_emulator).
32+
```
33+
firebase setup:emulators:firestore
34+
```
35+
* Run the emulator
36+
```
37+
firebase serve --only firestore
38+
```
1939
20-
## Running Firestore Tests
40+
### Running Firestore Tests
2141
22-
All commands must be run from this `packages/firestore/` directory.
42+
All commands must be run from the `packages/firestore/` directory.
2343
2444
```
2545
# Come up to date on dependencies after performing git pull
@@ -43,7 +63,14 @@ yarn test:browser --integration
4363
# localhost:8080.
4464
yarn test:browser --integration --local
4565

66+
# Run all node tests once (unit and integration) against the emulator.
67+
yarn test:node
68+
4669
# Run a subset of tests whose names match a filter.
4770
yarn test:browser --grep 'SortedSet keeps elements in the right order'
4871
yarn test:node --grep 'SortedSet keeps elements in the right order'
72+
73+
# Run tests against the production backend.
74+
yarn test:node:prod
75+
yarn test:node:persistence:prod
4976
```

packages/firestore/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
1212
"prettier": "prettier --write 'src/**/*.js' 'test/**/*.js' 'src/**/*.ts' 'test/**/*.ts'",
1313
"test": "run-s lint test:all",
14-
"test:all": "run-p test:browser test:emulator",
14+
"test:all": "run-p test:browser test:travis",
1515
"test:browser": "karma start --single-run",
1616
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
17-
"test:node": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --opts ../../config/mocha.node.opts",
18-
"test:node:persistence": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --require ts-node/register --require index.node.ts --require test/util/node_persistence.ts --opts ../../config/mocha.node.opts",
19-
"test:emulator": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
17+
"test:node": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --opts ../../config/mocha.node.opts",
18+
"test:node:prod": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --opts ../../config/mocha.node.opts",
19+
"test:node:persistence": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --require ts-node/register --require index.node.ts --require test/util/node_persistence.ts --opts ../../config/mocha.node.opts",
20+
"test:node:persistence:prod": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --require ts-node/register --require index.node.ts --require test/util/node_persistence.ts --opts ../../config/mocha.node.opts",
21+
"test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
2022
"prepare": "yarn build"
2123
},
2224
"main": "dist/index.node.cjs.js",

scripts/emulator-testing/firestore-test-runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function runTest(port: number, projectId: string): ChildProcessPromise {
3535
};
3636
// TODO(b/113267261): Include browser test once WebChannel support is
3737
// ready in Firestore emulator.
38-
return spawn('yarn', ['test:node'], options);
38+
// Use test:node:prod to allow runner's env var overrides to work.
39+
return spawn('yarn', ['test:node:prod'], options);
3940
}
4041

4142
async function run(): Promise<void> {

0 commit comments

Comments
 (0)