Skip to content

Commit b9b6aa9

Browse files
authored
fix failing unit test "throws with ill-formatted bundle with bytesPerRead" which erroneously fails due to different webkit error message on json parse failure compared to chrome
1 parent 87b6936 commit b9b6aa9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/firestore/test/unit/util/bundle.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,21 @@ function genericBundleReadingTests(bytesPerRead: number): void {
239239
'Reached the end of bundle when a length string is expected.'
240240
);
241241

242-
await expect(
243-
generateBundleAndParse('{metadata: "no length prefix"}', bytesPerRead)
244-
).to.be.rejectedWith(/(Unexpected end of )(?=.*JSON\b).*/gi);
242+
// The multiple "rejectedWith" checks below are an attempt to make the
243+
// test robust in the presence of various permutations of the error
244+
// message, which is produced by the JavaScript runtime.
245+
// Chrome produces: Unexpected end of JSON input
246+
// Webkit produces: JSON Parse error: Unexpected EOF
247+
const noLengthPrefixPromise = generateBundleAndParse(
248+
'{metadata: "no length prefix"}',
249+
bytesPerRead
250+
);
251+
await expect(noLengthPrefixPromise).to.be.rejectedWith(
252+
/(\b|^)unexpected ((end of)|(eof))(\b|$)/gi
253+
);
254+
await expect(noLengthPrefixPromise).to.be.rejectedWith(
255+
/(\b|^)JSON(\b|$)/g
256+
);
245257

246258
await expect(
247259
generateBundleAndParse(

0 commit comments

Comments
 (0)