Skip to content

Commit 4c0cf0e

Browse files
committed
Include firestore emulator tests in Travis.
Refactor emulators managing code. Exclude failing cases from firestore emulator tests.
1 parent 5509eaf commit 4c0cf0e

19 files changed

+826
-592
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ jobs:
3737
- script: yarn test:saucelabs --database-firestore-only
3838
# TODO(yifanyang): Once we verify the emulator tests are reliable, we
3939
# should make these tests blocking rather than allow failures.
40-
- script: node scripts/testing/database-emulator-test.js
40+
- script: yarn test:database:emulator
41+
- script: yarn test:firestore:emulator
4142
include:
4243
- name: Node.js and Browser (Chrome) Test
4344
stage: test
@@ -51,9 +52,12 @@ jobs:
5152
stage: test
5253
script: yarn test:saucelabs --database-firestore-only
5354
if: type = push
54-
- name: Database Node.js and Browser (Chrome) Test with Emulator
55+
- name: Database Emulator Node.js and Browser (Chrome) Test
5556
stage: test
56-
script: node scripts/testing/database-emulator-test.js
57+
script: yarn test:database:emulator
58+
- name: Firestore Emulator Node.js Test
59+
stage: test
60+
script: yarn test:firestore:emulator
5761
- stage: deploy
5862
script: skip
5963
# NPM Canary Build Config

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"test:coverage": "lcov-result-merger 'packages/**/lcov.info' | coveralls",
3030
"test:setup": "node tools/config.js",
3131
"pretest:saucelabs": "lerna run --parallel pretest",
32-
"test:saucelabs": "karma start config/karma.saucelabs.js --single-run"
32+
"test:saucelabs": "karma start config/karma.saucelabs.js --single-run",
33+
"test:database:emulator": "ts-node scripts/emulator-testing/database-test-runner.ts",
34+
"test:firestore:emulator": "ts-node scripts/emulator-testing/firestore-test-runner.ts"
3335
},
3436
"repository": {
3537
"type": "git",
@@ -61,6 +63,8 @@
6163
"prettier": "1.12.0",
6264
"semver": "5.5.0",
6365
"simple-git": "1.92.0",
66+
"ts-node": "5.0.1",
67+
"typescript": "2.8.1",
6468
"yargs": "11.0.0"
6569
}
6670
}

packages/firestore/test/integration/api/batch_writes.test.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { EventsAccumulator } from '../util/events_accumulator';
2121
import firebase from '../util/firebase_export';
2222
import * as integrationHelpers from '../util/helpers';
2323

24+
const USE_EMULATOR = integrationHelpers.USE_EMULATOR;
25+
2426
const apiDescribe = integrationHelpers.apiDescribe;
2527
const Timestamp = firebase.firestore!.Timestamp;
2628
const FieldValue = firebase.firestore!.FieldValue;
@@ -317,36 +319,39 @@ apiDescribe('Database batch writes', persistence => {
317319
});
318320
});
319321

320-
it('can update nested fields', () => {
321-
const initialData = {
322-
desc: 'Description',
323-
owner: { name: 'Jonny' },
324-
'is.admin': false
325-
};
326-
const finalData = {
327-
desc: 'Description',
328-
owner: { name: 'Sebastian' },
329-
'is.admin': true
330-
};
322+
(!persistence && USE_EMULATOR ? it.skip : it)(
323+
'can update nested fields',
324+
() => {
325+
const initialData = {
326+
desc: 'Description',
327+
owner: { name: 'Jonny' },
328+
'is.admin': false
329+
};
330+
const finalData = {
331+
desc: 'Description',
332+
owner: { name: 'Sebastian' },
333+
'is.admin': true
334+
};
331335

332-
return integrationHelpers.withTestDb(persistence, db => {
333-
const doc = db.collection('counters').doc();
334-
return doc.firestore
335-
.batch()
336-
.set(doc, initialData)
337-
.update(
338-
doc,
339-
'owner.name',
340-
'Sebastian',
341-
new firebase.firestore!.FieldPath('is.admin'),
342-
true
343-
)
344-
.commit()
345-
.then(() => doc.get())
346-
.then(docSnapshot => {
347-
expect(docSnapshot.exists).to.be.ok;
348-
expect(docSnapshot.data()).to.deep.equal(finalData);
349-
});
350-
});
351-
});
336+
return integrationHelpers.withTestDb(persistence, db => {
337+
const doc = db.collection('counters').doc();
338+
return doc.firestore
339+
.batch()
340+
.set(doc, initialData)
341+
.update(
342+
doc,
343+
'owner.name',
344+
'Sebastian',
345+
new firebase.firestore!.FieldPath('is.admin'),
346+
true
347+
)
348+
.commit()
349+
.then(() => doc.get())
350+
.then(docSnapshot => {
351+
expect(docSnapshot.exists).to.be.ok;
352+
expect(docSnapshot.data()).to.deep.equal(finalData);
353+
});
354+
});
355+
}
356+
);
352357
});

packages/firestore/test/integration/api/cursor.test.ts

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
apiDescribe,
2222
toDataArray,
2323
toIds,
24+
USE_EMULATOR,
2425
withTestCollection,
2526
withTestDb,
2627
withTestDbs
@@ -30,52 +31,55 @@ const Timestamp = firebase.firestore!.Timestamp;
3031
const FieldPath = firebase.firestore!.FieldPath;
3132

3233
apiDescribe('Cursors', persistence => {
33-
it('can page through items', () => {
34-
const testDocs = {
35-
a: { v: 'a' },
36-
b: { v: 'b' },
37-
c: { v: 'c' },
38-
d: { v: 'd' },
39-
e: { v: 'e' },
40-
f: { v: 'f' }
41-
};
42-
return withTestCollection(persistence, testDocs, coll => {
43-
return coll
44-
.limit(2)
45-
.get()
46-
.then(docs => {
47-
expect(toDataArray(docs)).to.deep.equal([{ v: 'a' }, { v: 'b' }]);
48-
const lastDoc = docs.docs[docs.docs.length - 1];
49-
return coll
50-
.limit(3)
51-
.startAfter(lastDoc)
52-
.get();
53-
})
54-
.then(docs => {
55-
expect(toDataArray(docs)).to.deep.equal([
56-
{ v: 'c' },
57-
{ v: 'd' },
58-
{ v: 'e' }
59-
]);
60-
const lastDoc = docs.docs[docs.docs.length - 1];
61-
return coll
62-
.limit(1)
63-
.startAfter(lastDoc)
64-
.get();
65-
})
66-
.then(docs => {
67-
expect(toDataArray(docs)).to.deep.equal([{ v: 'f' }]);
68-
const lastDoc = docs.docs[docs.docs.length - 1];
69-
return coll
70-
.limit(3)
71-
.startAfter(lastDoc)
72-
.get();
73-
})
74-
.then(docs => {
75-
expect(toDataArray(docs)).to.deep.equal([]);
76-
});
77-
});
78-
});
34+
(!persistence && USE_EMULATOR ? it.skip : it)(
35+
'can page through items',
36+
() => {
37+
const testDocs = {
38+
a: { v: 'a' },
39+
b: { v: 'b' },
40+
c: { v: 'c' },
41+
d: { v: 'd' },
42+
e: { v: 'e' },
43+
f: { v: 'f' }
44+
};
45+
return withTestCollection(persistence, testDocs, coll => {
46+
return coll
47+
.limit(2)
48+
.get()
49+
.then(docs => {
50+
expect(toDataArray(docs)).to.deep.equal([{ v: 'a' }, { v: 'b' }]);
51+
const lastDoc = docs.docs[docs.docs.length - 1];
52+
return coll
53+
.limit(3)
54+
.startAfter(lastDoc)
55+
.get();
56+
})
57+
.then(docs => {
58+
expect(toDataArray(docs)).to.deep.equal([
59+
{ v: 'c' },
60+
{ v: 'd' },
61+
{ v: 'e' }
62+
]);
63+
const lastDoc = docs.docs[docs.docs.length - 1];
64+
return coll
65+
.limit(1)
66+
.startAfter(lastDoc)
67+
.get();
68+
})
69+
.then(docs => {
70+
expect(toDataArray(docs)).to.deep.equal([{ v: 'f' }]);
71+
const lastDoc = docs.docs[docs.docs.length - 1];
72+
return coll
73+
.limit(3)
74+
.startAfter(lastDoc)
75+
.get();
76+
})
77+
.then(docs => {
78+
expect(toDataArray(docs)).to.deep.equal([]);
79+
});
80+
});
81+
}
82+
);
7983

8084
it('can be created from documents', () => {
8185
const testDocs = {

0 commit comments

Comments
 (0)