Skip to content

Commit 3e2c2e2

Browse files
Merge branch 'master' into mrschmidt/nomultitab
2 parents a763d95 + 437c404 commit 3e2c2e2

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

packages-exp/app-exp/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
},
2525
"dependencies": {
2626
"@firebase/app-types-exp": "0.800.0",
27-
"@firebase/util": "0.2.43",
28-
"@firebase/logger": "0.2.0",
29-
"@firebase/component": "0.1.8",
27+
"@firebase/util": "0.2.44",
28+
"@firebase/logger": "0.2.1",
29+
"@firebase/component": "0.1.9",
3030
"tslib": "1.11.1"
3131
},
3232
"license": "Apache-2.0",

packages/firestore/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"@firebase/app-types": "0.x"
5151
},
5252
"devDependencies": {
53+
"@types/json-stable-stringify": "1.0.32",
54+
"json-stable-stringify": "1.0.1",
5355
"protobufjs": "6.8.9",
5456
"rollup": "2.0.6",
5557
"rollup-plugin-copy-assets": "1.1.0",

packages/firestore/test/unit/specs/describe_spec.ts

Lines changed: 63 additions & 2 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,14 @@ import { ExclusiveTestFunction, PendingTestFunction } from 'mocha';
1919

2020
import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence';
2121
import { assert } from '../../../src/util/assert';
22+
import { primitiveComparator } from '../../../src/util/misc';
2223
import { addEqualityMatcher } from '../../util/equality_matcher';
2324

2425
import { SpecBuilder } from './spec_builder';
2526
import { SpecStep } from './spec_test_runner';
2627

28+
import * as stringify from 'json-stable-stringify';
29+
2730
// Disables all other tests; useful for debugging. Multiple tests can have
2831
// this tag and they'll all be run (but all others won't).
2932
const EXCLUSIVE_TAG = 'exclusive';
@@ -242,7 +245,65 @@ export function describeSpec(
242245
} else {
243246
specsInThisTest = {};
244247
builder();
245-
const output = JSON.stringify(specsInThisTest, null, 2);
248+
// Note: We use json-stable-stringify instead of JSON.stringify() to ensure
249+
// that the generated JSON does not produce diffs merely due to the order
250+
// of the keys in an object changing.
251+
const output = stringify(specsInThisTest, {
252+
space: 2,
253+
cmp: stringifyComparator
254+
});
246255
writeJSONFile(output);
247256
}
248257
}
258+
259+
/**
260+
* The key ordering overrides used when sorting keys in the generated JSON.
261+
* If both keys being compared are present in this array then they should be
262+
* ordered in the generated JSON in the same relative order of this array.
263+
*/
264+
const stringifyCustomOrdering = [
265+
'comment',
266+
'describeName',
267+
'itName',
268+
'tags',
269+
'config',
270+
'steps'
271+
];
272+
273+
/**
274+
* Assigns a "group number" to the given key in the generated JSON.
275+
*
276+
* Keys with lower group numbers should be ordered before keys with greater
277+
* group numbers. Keys with equal group numbers should be ordered
278+
* alphabetically.
279+
*/
280+
function stringifyGroup(s: string): number {
281+
const index = stringifyCustomOrdering.indexOf(s);
282+
if (index >= 0) {
283+
return index;
284+
} else if (!s.startsWith('expected')) {
285+
return stringifyCustomOrdering.length;
286+
} else {
287+
return stringifyCustomOrdering.length + 1;
288+
}
289+
}
290+
291+
/**
292+
* A comparator function for stringify() that sorts keys in the JSON output.
293+
*
294+
* In order to produce JSON that has somewhat-intuitively-ordered keys, this
295+
* comparator intentionally deviates from pure alphabetic ordering, placing
296+
* some logically-first keys before others.
297+
*/
298+
function stringifyComparator(
299+
a: stringify.Element,
300+
b: stringify.Element
301+
): number {
302+
const aGroup = stringifyGroup(a.key);
303+
const bGroup = stringifyGroup(b.key);
304+
if (aGroup === bGroup) {
305+
return primitiveComparator(a.key, b.key);
306+
} else {
307+
return primitiveComparator(aGroup, bGroup);
308+
}
309+
}

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,11 @@
21212121
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
21222122
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==
21232123

2124+
2125+
version "1.0.32"
2126+
resolved "https://registry.npmjs.org/@types/json-stable-stringify/-/json-stable-stringify-1.0.32.tgz#121f6917c4389db3923640b2e68de5fa64dda88e"
2127+
integrity sha512-q9Q6+eUEGwQkv4Sbst3J4PNgDOvpuVuKj79Hl/qnmBMEIPzB5QoFRUtjcgcg2xNUZyYUGXBk5wYIBKHt0A+Mxw==
2128+
21242129
"@types/long@*", "@types/long@^4.0.0":
21252130
version "4.0.0"
21262131
resolved "https://registry.npmjs.org/@types/long/-/long-4.0.0.tgz#719551d2352d301ac8b81db732acb6bdc28dbdef"
@@ -8924,6 +8929,13 @@ json-stable-stringify-without-jsonify@^1.0.1:
89248929
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
89258930
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
89268931

8932+
8933+
version "1.0.1"
8934+
resolved "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af"
8935+
integrity sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=
8936+
dependencies:
8937+
jsonify "~0.0.0"
8938+
89278939
json-stable-stringify@~0.0.0:
89288940
version "0.0.1"
89298941
resolved "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-0.0.1.tgz#611c23e814db375527df851193db59dd2af27f45"

0 commit comments

Comments
 (0)