@fluidframework/routerlicious-driver 2.0.0-dev-rc.2.0.0.245554 → 2.0.0-dev-rc.3.0.0.250606
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
- package/api-extractor-lint.json +1 -1
- package/api-extractor.json +1 -1
- package/{lib/storageContracts.mjs → dist/axios.cjs} +3 -2
- package/dist/axios.cjs.map +1 -0
- package/dist/axios.d.cts +7 -0
- package/dist/axios.d.cts.map +1 -0
- package/dist/cache.js +2 -2
- package/dist/cache.js.map +1 -1
- package/dist/defaultTokenProvider.d.ts +1 -1
- package/dist/defaultTokenProvider.d.ts.map +1 -1
- package/dist/defaultTokenProvider.js.map +1 -1
- package/dist/deltaStorageService.d.ts +3 -3
- package/dist/deltaStorageService.d.ts.map +1 -1
- package/dist/deltaStorageService.js.map +1 -1
- package/dist/documentDeltaConnection.d.ts +1 -1
- package/dist/documentDeltaConnection.d.ts.map +1 -1
- package/dist/documentDeltaConnection.js +4 -4
- package/dist/documentDeltaConnection.js.map +1 -1
- package/dist/documentService.d.ts +6 -6
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +22 -22
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts +3 -3
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +25 -25
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts +7 -7
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +4 -4
- package/dist/documentStorageService.js.map +1 -1
- package/dist/errorUtils.d.ts +1 -1
- package/dist/errorUtils.d.ts.map +1 -1
- package/dist/errorUtils.js +2 -3
- package/dist/errorUtils.js.map +1 -1
- package/dist/gitManager.d.ts +3 -3
- package/dist/gitManager.d.ts.map +1 -1
- package/dist/gitManager.js.map +1 -1
- package/dist/historian.d.ts +4 -4
- package/dist/historian.d.ts.map +1 -1
- package/dist/historian.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/package.json +3 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/r11sSnapshotParser.d.ts +1 -1
- package/dist/r11sSnapshotParser.d.ts.map +1 -1
- package/dist/r11sSnapshotParser.js.map +1 -1
- package/dist/restWrapper.d.ts +4 -4
- package/dist/restWrapper.d.ts.map +1 -1
- package/dist/restWrapper.js +11 -11
- package/dist/restWrapper.js.map +1 -1
- package/dist/restWrapperBase.d.ts +2 -2
- package/dist/restWrapperBase.d.ts.map +1 -1
- package/dist/restWrapperBase.js.map +1 -1
- package/dist/retriableGitManager.d.ts +3 -3
- package/dist/retriableGitManager.d.ts.map +1 -1
- package/dist/retriableGitManager.js.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts +6 -6
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +7 -7
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/storageContracts.d.ts +2 -2
- package/dist/storageContracts.d.ts.map +1 -1
- package/dist/storageContracts.js.map +1 -1
- package/dist/summaryTreeUploadManager.d.ts +1 -1
- package/dist/summaryTreeUploadManager.d.ts.map +1 -1
- package/dist/summaryTreeUploadManager.js.map +1 -1
- package/dist/treeUtils.d.ts +2 -2
- package/dist/treeUtils.d.ts.map +1 -1
- package/dist/treeUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts +6 -6
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +12 -12
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/dist/wholeSummaryUploadManager.d.ts +1 -1
- package/dist/wholeSummaryUploadManager.d.ts.map +1 -1
- package/dist/wholeSummaryUploadManager.js.map +1 -1
- package/lib/axios.cjs +7 -0
- package/lib/axios.cjs.map +1 -0
- package/lib/axios.d.cts +7 -0
- package/lib/axios.d.cts.map +1 -0
- package/lib/{cache.d.mts → cache.d.ts} +1 -1
- package/lib/cache.d.ts.map +1 -0
- package/lib/{cache.mjs → cache.js} +2 -2
- package/lib/cache.js.map +1 -0
- package/lib/{contracts.d.mts → contracts.d.ts} +1 -1
- package/lib/contracts.d.ts.map +1 -0
- package/lib/{policies.mjs → contracts.js} +1 -1
- package/lib/contracts.js.map +1 -0
- package/lib/{createNewUtils.d.mts → createNewUtils.d.ts} +1 -1
- package/lib/createNewUtils.d.ts.map +1 -0
- package/lib/{createNewUtils.mjs → createNewUtils.js} +1 -1
- package/lib/createNewUtils.js.map +1 -0
- package/lib/{defaultTokenProvider.d.mts → defaultTokenProvider.d.ts} +2 -2
- package/lib/defaultTokenProvider.d.ts.map +1 -0
- package/lib/{defaultTokenProvider.mjs → defaultTokenProvider.js} +1 -1
- package/lib/defaultTokenProvider.js.map +1 -0
- package/lib/{definitions.d.mts → definitions.d.ts} +1 -1
- package/lib/definitions.d.ts.map +1 -0
- package/lib/{definitions.mjs → definitions.js} +1 -1
- package/lib/definitions.js.map +1 -0
- package/lib/{deltaStorageService.d.mts → deltaStorageService.d.ts} +4 -4
- package/lib/deltaStorageService.d.ts.map +1 -0
- package/lib/{deltaStorageService.mjs → deltaStorageService.js} +2 -2
- package/lib/deltaStorageService.js.map +1 -0
- package/lib/{documentDeltaConnection.d.mts → documentDeltaConnection.d.ts} +2 -2
- package/lib/documentDeltaConnection.d.ts.map +1 -0
- package/lib/{documentDeltaConnection.mjs → documentDeltaConnection.js} +3 -3
- package/lib/documentDeltaConnection.js.map +1 -0
- package/lib/{documentService.d.mts → documentService.d.ts} +7 -7
- package/lib/documentService.d.ts.map +1 -0
- package/lib/{documentService.mjs → documentService.js} +12 -12
- package/lib/documentService.js.map +1 -0
- package/lib/{documentServiceFactory.d.mts → documentServiceFactory.d.ts} +4 -4
- package/lib/documentServiceFactory.d.ts.map +1 -0
- package/lib/{documentServiceFactory.mjs → documentServiceFactory.js} +9 -9
- package/lib/documentServiceFactory.js.map +1 -0
- package/lib/{documentStorageService.d.mts → documentStorageService.d.ts} +8 -8
- package/lib/documentStorageService.d.ts.map +1 -0
- package/lib/{documentStorageService.mjs → documentStorageService.js} +3 -3
- package/lib/documentStorageService.js.map +1 -0
- package/lib/{errorUtils.d.mts → errorUtils.d.ts} +2 -2
- package/lib/errorUtils.d.ts.map +1 -0
- package/lib/{errorUtils.mjs → errorUtils.js} +3 -4
- package/lib/errorUtils.js.map +1 -0
- package/lib/{gitManager.d.mts → gitManager.d.ts} +4 -4
- package/lib/gitManager.d.ts.map +1 -0
- package/lib/{gitManager.mjs → gitManager.js} +1 -1
- package/lib/gitManager.js.map +1 -0
- package/lib/{historian.d.mts → historian.d.ts} +5 -5
- package/lib/historian.d.ts.map +1 -0
- package/lib/{historian.mjs → historian.js} +1 -1
- package/lib/historian.js.map +1 -0
- package/lib/{index.d.mts → index.d.ts} +7 -7
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/{mapWithExpiration.d.mts → mapWithExpiration.d.ts} +1 -1
- package/lib/mapWithExpiration.d.ts.map +1 -0
- package/lib/{mapWithExpiration.mjs → mapWithExpiration.js} +1 -1
- package/lib/mapWithExpiration.js.map +1 -0
- package/lib/{nullBlobStorageService.d.mts → nullBlobStorageService.d.ts} +1 -1
- package/lib/nullBlobStorageService.d.ts.map +1 -0
- package/lib/{nullBlobStorageService.mjs → nullBlobStorageService.js} +1 -1
- package/lib/nullBlobStorageService.js.map +1 -0
- package/lib/{packageVersion.d.mts → packageVersion.d.ts} +2 -2
- package/lib/packageVersion.d.ts.map +1 -0
- package/lib/{packageVersion.mjs → packageVersion.js} +2 -2
- package/lib/packageVersion.js.map +1 -0
- package/lib/{policies.d.mts → policies.d.ts} +1 -1
- package/lib/policies.d.ts.map +1 -0
- package/lib/{contracts.mjs → policies.js} +1 -1
- package/lib/policies.js.map +1 -0
- package/lib/{r11sSnapshotParser.d.mts → r11sSnapshotParser.d.ts} +2 -2
- package/lib/r11sSnapshotParser.d.ts.map +1 -0
- package/lib/{r11sSnapshotParser.mjs → r11sSnapshotParser.js} +1 -1
- package/lib/r11sSnapshotParser.js.map +1 -0
- package/lib/{restWrapper.d.mts → restWrapper.d.ts} +5 -5
- package/lib/restWrapper.d.ts.map +1 -0
- package/lib/{restWrapper.mjs → restWrapper.js} +7 -7
- package/lib/restWrapper.js.map +1 -0
- package/lib/{restWrapperBase.d.mts → restWrapperBase.d.ts} +3 -3
- package/lib/restWrapperBase.d.ts.map +1 -0
- package/lib/{restWrapperBase.mjs → restWrapperBase.js} +1 -1
- package/lib/restWrapperBase.js.map +1 -0
- package/lib/{retriableGitManager.d.mts → retriableGitManager.d.ts} +4 -4
- package/lib/retriableGitManager.d.ts.map +1 -0
- package/lib/{retriableGitManager.mjs → retriableGitManager.js} +1 -1
- package/lib/retriableGitManager.js.map +1 -0
- package/lib/{routerliciousResolvedUrl.d.mts → routerliciousResolvedUrl.d.ts} +1 -1
- package/lib/routerliciousResolvedUrl.d.ts.map +1 -0
- package/lib/{routerliciousResolvedUrl.mjs → routerliciousResolvedUrl.js} +1 -1
- package/lib/routerliciousResolvedUrl.js.map +1 -0
- package/lib/{shreddedSummaryDocumentStorageService.d.mts → shreddedSummaryDocumentStorageService.d.ts} +7 -7
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -0
- package/lib/{shreddedSummaryDocumentStorageService.mjs → shreddedSummaryDocumentStorageService.js} +6 -6
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -0
- package/lib/{storageContracts.d.mts → storageContracts.d.ts} +3 -3
- package/lib/storageContracts.d.ts.map +1 -0
- package/lib/storageContracts.js +6 -0
- package/lib/storageContracts.js.map +1 -0
- package/lib/{summaryTreeUploadManager.d.mts → summaryTreeUploadManager.d.ts} +2 -2
- package/lib/summaryTreeUploadManager.d.ts.map +1 -0
- package/lib/{summaryTreeUploadManager.mjs → summaryTreeUploadManager.js} +2 -2
- package/lib/summaryTreeUploadManager.js.map +1 -0
- package/lib/test/cache.spec.js +43 -0
- package/lib/test/cache.spec.js.map +1 -0
- package/lib/test/errorUtils.spec.js +227 -0
- package/lib/test/errorUtils.spec.js.map +1 -0
- package/lib/test/mapWithExpiration.spec.js +205 -0
- package/lib/test/mapWithExpiration.spec.js.map +1 -0
- package/lib/test/restWrapper.spec.js +309 -0
- package/lib/test/restWrapper.spec.js.map +1 -0
- package/lib/test/types/validateRouterliciousDriverPrevious.generated.js +22 -0
- package/lib/test/types/validateRouterliciousDriverPrevious.generated.js.map +1 -0
- package/lib/test/urlUtils.spec.js +62 -0
- package/lib/test/urlUtils.spec.js.map +1 -0
- package/lib/test/wholeSummaryDocumentStorageService.spec.js +144 -0
- package/lib/test/wholeSummaryDocumentStorageService.spec.js.map +1 -0
- package/lib/{tokens.d.mts → tokens.d.ts} +1 -1
- package/lib/tokens.d.ts.map +1 -0
- package/lib/{tokens.mjs → tokens.js} +1 -1
- package/lib/tokens.js.map +1 -0
- package/lib/{treeUtils.d.mts → treeUtils.d.ts} +3 -3
- package/lib/treeUtils.d.ts.map +1 -0
- package/lib/{treeUtils.mjs → treeUtils.js} +1 -1
- package/lib/treeUtils.js.map +1 -0
- package/lib/{urlUtils.d.mts → urlUtils.d.ts} +1 -1
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/{urlUtils.mjs → urlUtils.js} +1 -1
- package/lib/urlUtils.js.map +1 -0
- package/lib/{wholeSummaryDocumentStorageService.d.mts → wholeSummaryDocumentStorageService.d.ts} +7 -7
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -0
- package/lib/{wholeSummaryDocumentStorageService.mjs → wholeSummaryDocumentStorageService.js} +7 -7
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -0
- package/lib/{wholeSummaryUploadManager.d.mts → wholeSummaryUploadManager.d.ts} +2 -2
- package/lib/wholeSummaryUploadManager.d.ts.map +1 -0
- package/lib/{wholeSummaryUploadManager.mjs → wholeSummaryUploadManager.js} +1 -1
- package/lib/wholeSummaryUploadManager.js.map +1 -0
- package/package.json +46 -40
- package/src/axios.cts +8 -0
- package/src/cache.ts +1 -1
- package/src/defaultTokenProvider.ts +1 -1
- package/src/deltaStorageService.ts +5 -5
- package/src/documentDeltaConnection.ts +3 -3
- package/src/documentService.ts +17 -17
- package/src/documentServiceFactory.ts +14 -14
- package/src/documentStorageService.ts +9 -9
- package/src/errorUtils.ts +5 -6
- package/src/gitManager.ts +3 -3
- package/src/historian.ts +4 -4
- package/src/index.ts +6 -6
- package/src/packageVersion.ts +1 -1
- package/src/r11sSnapshotParser.ts +6 -2
- package/src/restWrapper.ts +12 -12
- package/src/restWrapperBase.ts +2 -2
- package/src/retriableGitManager.ts +4 -4
- package/src/shreddedSummaryDocumentStorageService.ts +15 -15
- package/src/storageContracts.ts +2 -2
- package/src/summaryTreeUploadManager.ts +2 -2
- package/src/treeUtils.ts +2 -2
- package/src/wholeSummaryDocumentStorageService.ts +17 -17
- package/src/wholeSummaryUploadManager.ts +1 -1
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +2 -5
- package/lib/cache.d.mts.map +0 -1
- package/lib/cache.mjs.map +0 -1
- package/lib/contracts.d.mts.map +0 -1
- package/lib/contracts.mjs.map +0 -1
- package/lib/createNewUtils.d.mts.map +0 -1
- package/lib/createNewUtils.mjs.map +0 -1
- package/lib/defaultTokenProvider.d.mts.map +0 -1
- package/lib/defaultTokenProvider.mjs.map +0 -1
- package/lib/definitions.d.mts.map +0 -1
- package/lib/definitions.mjs.map +0 -1
- package/lib/deltaStorageService.d.mts.map +0 -1
- package/lib/deltaStorageService.mjs.map +0 -1
- package/lib/documentDeltaConnection.d.mts.map +0 -1
- package/lib/documentDeltaConnection.mjs.map +0 -1
- package/lib/documentService.d.mts.map +0 -1
- package/lib/documentService.mjs.map +0 -1
- package/lib/documentServiceFactory.d.mts.map +0 -1
- package/lib/documentServiceFactory.mjs.map +0 -1
- package/lib/documentStorageService.d.mts.map +0 -1
- package/lib/documentStorageService.mjs.map +0 -1
- package/lib/errorUtils.d.mts.map +0 -1
- package/lib/errorUtils.mjs.map +0 -1
- package/lib/gitManager.d.mts.map +0 -1
- package/lib/gitManager.mjs.map +0 -1
- package/lib/historian.d.mts.map +0 -1
- package/lib/historian.mjs.map +0 -1
- package/lib/index.d.mts.map +0 -1
- package/lib/index.mjs +0 -8
- package/lib/index.mjs.map +0 -1
- package/lib/mapWithExpiration.d.mts.map +0 -1
- package/lib/mapWithExpiration.mjs.map +0 -1
- package/lib/nullBlobStorageService.d.mts.map +0 -1
- package/lib/nullBlobStorageService.mjs.map +0 -1
- package/lib/packageVersion.d.mts.map +0 -1
- package/lib/packageVersion.mjs.map +0 -1
- package/lib/policies.d.mts.map +0 -1
- package/lib/policies.mjs.map +0 -1
- package/lib/r11sSnapshotParser.d.mts.map +0 -1
- package/lib/r11sSnapshotParser.mjs.map +0 -1
- package/lib/restWrapper.d.mts.map +0 -1
- package/lib/restWrapper.mjs.map +0 -1
- package/lib/restWrapperBase.d.mts.map +0 -1
- package/lib/restWrapperBase.mjs.map +0 -1
- package/lib/retriableGitManager.d.mts.map +0 -1
- package/lib/retriableGitManager.mjs.map +0 -1
- package/lib/routerliciousResolvedUrl.d.mts.map +0 -1
- package/lib/routerliciousResolvedUrl.mjs.map +0 -1
- package/lib/shreddedSummaryDocumentStorageService.d.mts.map +0 -1
- package/lib/shreddedSummaryDocumentStorageService.mjs.map +0 -1
- package/lib/storageContracts.d.mts.map +0 -1
- package/lib/storageContracts.mjs.map +0 -1
- package/lib/summaryTreeUploadManager.d.mts.map +0 -1
- package/lib/summaryTreeUploadManager.mjs.map +0 -1
- package/lib/tokens.d.mts.map +0 -1
- package/lib/tokens.mjs.map +0 -1
- package/lib/treeUtils.d.mts.map +0 -1
- package/lib/treeUtils.mjs.map +0 -1
- package/lib/urlUtils.d.mts.map +0 -1
- package/lib/urlUtils.mjs.map +0 -1
- package/lib/wholeSummaryDocumentStorageService.d.mts.map +0 -1
- package/lib/wholeSummaryDocumentStorageService.mjs.map +0 -1
- package/lib/wholeSummaryUploadManager.d.mts.map +0 -1
- package/lib/wholeSummaryUploadManager.mjs.map +0 -1
- /package/lib/{routerlicious-driver-alpha.d.mts → routerlicious-driver-alpha.d.ts} +0 -0
- /package/lib/{routerlicious-driver-beta.d.mts → routerlicious-driver-beta.d.ts} +0 -0
- /package/lib/{routerlicious-driver-public.d.mts → routerlicious-driver-public.d.ts} +0 -0
- /package/lib/{routerlicious-driver-untrimmed.d.mts → routerlicious-driver-untrimmed.d.ts} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { strict as assert } from "assert";
|
|
6
|
+
import { useFakeTimers } from "sinon";
|
|
7
|
+
import { InMemoryCache } from "../cache.js";
|
|
8
|
+
describe("InMemoryCache", () => {
|
|
9
|
+
let clock;
|
|
10
|
+
let cache;
|
|
11
|
+
before(() => {
|
|
12
|
+
clock = useFakeTimers();
|
|
13
|
+
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
clock.reset();
|
|
16
|
+
});
|
|
17
|
+
after(() => {
|
|
18
|
+
clock.restore();
|
|
19
|
+
});
|
|
20
|
+
it("No expiry", async () => {
|
|
21
|
+
cache = new InMemoryCache();
|
|
22
|
+
await cache.put("one", 1);
|
|
23
|
+
clock.tick(Number.MAX_SAFE_INTEGER);
|
|
24
|
+
assert.equal(await cache.get("one"), 1, "Entry shouldn't expire");
|
|
25
|
+
});
|
|
26
|
+
it("With expiry", async () => {
|
|
27
|
+
const expiryMs = 10;
|
|
28
|
+
cache = new InMemoryCache(expiryMs);
|
|
29
|
+
await cache.put("one", 1);
|
|
30
|
+
await cache.put("two", 2);
|
|
31
|
+
clock.tick(5);
|
|
32
|
+
assert.equal(await cache.get("one"), 1, "'one' shouldn't be expired after 5ms");
|
|
33
|
+
assert.equal(await cache.get("two"), 2, "'two' shouldn't be expired after 5ms");
|
|
34
|
+
assert.equal(await cache.get("one"), 1); // Should NOT reset the expiry, only put does
|
|
35
|
+
await cache.put("two", 2.1);
|
|
36
|
+
await cache.put("three", 3);
|
|
37
|
+
clock.tick(5);
|
|
38
|
+
assert.equal(await cache.get("one"), undefined, "'one' should be expired after 10ms");
|
|
39
|
+
assert.equal(await cache.get("two"), 2.1, "'two' shouldn't be expired after 5ms");
|
|
40
|
+
assert.equal(await cache.get("three"), 3, "'three' shouldn't be expired after 5ms");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=cache.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.spec.js","sourceRoot":"","sources":["../../src/test/cache.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAmB,aAAa,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAU,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC9B,IAAI,KAAsB,CAAC;IAC3B,IAAI,KAAqB,CAAC;IAE1B,MAAM,CAAC,GAAG,EAAE;QACX,KAAK,GAAG,aAAa,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACd,KAAK,CAAC,KAAK,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,GAAG,EAAE;QACV,KAAK,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;QAC1B,KAAK,GAAG,IAAI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AAC;QACtF,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,sCAAsC,CAAC,CAAC;QAClF,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,wCAAwC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"assert\";\nimport { SinonFakeTimers, useFakeTimers } from \"sinon\";\nimport { ICache, InMemoryCache } from \"../cache.js\";\n\ndescribe(\"InMemoryCache\", () => {\n\tlet clock: SinonFakeTimers;\n\tlet cache: ICache<number>;\n\n\tbefore(() => {\n\t\tclock = useFakeTimers();\n\t});\n\n\tafterEach(() => {\n\t\tclock.reset();\n\t});\n\n\tafter(() => {\n\t\tclock.restore();\n\t});\n\n\tit(\"No expiry\", async () => {\n\t\tcache = new InMemoryCache();\n\t\tawait cache.put(\"one\", 1);\n\n\t\tclock.tick(Number.MAX_SAFE_INTEGER);\n\n\t\tassert.equal(await cache.get(\"one\"), 1, \"Entry shouldn't expire\");\n\t});\n\n\tit(\"With expiry\", async () => {\n\t\tconst expiryMs = 10;\n\t\tcache = new InMemoryCache<number>(expiryMs);\n\n\t\tawait cache.put(\"one\", 1);\n\t\tawait cache.put(\"two\", 2);\n\n\t\tclock.tick(5);\n\t\tassert.equal(await cache.get(\"one\"), 1, \"'one' shouldn't be expired after 5ms\");\n\t\tassert.equal(await cache.get(\"two\"), 2, \"'two' shouldn't be expired after 5ms\");\n\n\t\tassert.equal(await cache.get(\"one\"), 1); // Should NOT reset the expiry, only put does\n\t\tawait cache.put(\"two\", 2.1);\n\t\tawait cache.put(\"three\", 3);\n\n\t\tclock.tick(5);\n\t\tassert.equal(await cache.get(\"one\"), undefined, \"'one' should be expired after 10ms\");\n\t\tassert.equal(await cache.get(\"two\"), 2.1, \"'two' shouldn't be expired after 5ms\");\n\t\tassert.equal(await cache.get(\"three\"), 3, \"'three' shouldn't be expired after 5ms\");\n\t});\n});\n"]}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import assert from "assert";
|
|
6
|
+
import { FluidErrorTypes } from "@fluidframework/core-interfaces";
|
|
7
|
+
import { RouterliciousErrorTypes, createR11sNetworkError, errorObjectFromSocketError, throwR11sNetworkError, } from "../errorUtils.js";
|
|
8
|
+
describe("ErrorUtils", () => {
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the input is an {@link IThrottlingWarning}.
|
|
11
|
+
*/
|
|
12
|
+
function isIThrottlingWarning(input) {
|
|
13
|
+
return (input !== undefined &&
|
|
14
|
+
input.errorType === FluidErrorTypes.throttlingError &&
|
|
15
|
+
input.retryAfterSeconds !== undefined);
|
|
16
|
+
}
|
|
17
|
+
describe("createR11sNetworkError()", () => {
|
|
18
|
+
it("creates non-retriable authorization error on 401", () => {
|
|
19
|
+
const message = "test error";
|
|
20
|
+
const error = createR11sNetworkError(message, 401);
|
|
21
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);
|
|
22
|
+
assert.strictEqual(error.canRetry, false);
|
|
23
|
+
});
|
|
24
|
+
it("creates non-retriable authorization error on 403", () => {
|
|
25
|
+
const message = "test error";
|
|
26
|
+
const error = createR11sNetworkError(message, 403);
|
|
27
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);
|
|
28
|
+
assert.strictEqual(error.canRetry, false);
|
|
29
|
+
});
|
|
30
|
+
it("creates non-retriable not-found error on 404", () => {
|
|
31
|
+
const message = "test error";
|
|
32
|
+
const error = createR11sNetworkError(message, 404);
|
|
33
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.fileNotFoundOrAccessDeniedError);
|
|
34
|
+
assert.strictEqual(error.canRetry, false);
|
|
35
|
+
});
|
|
36
|
+
it("creates retriable error on 429 with retry-after", () => {
|
|
37
|
+
const message = "test error";
|
|
38
|
+
const error = createR11sNetworkError(message, 429, 5000);
|
|
39
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.throttlingError);
|
|
40
|
+
assert.strictEqual(error.canRetry, true);
|
|
41
|
+
assert.strictEqual(error.retryAfterSeconds, 5);
|
|
42
|
+
});
|
|
43
|
+
it("creates retriable error on 429 without retry-after", () => {
|
|
44
|
+
const message = "test error";
|
|
45
|
+
const error = createR11sNetworkError(message, 429);
|
|
46
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);
|
|
47
|
+
assert.strictEqual(error.canRetry, true);
|
|
48
|
+
});
|
|
49
|
+
it("creates retriable error on 500", () => {
|
|
50
|
+
const message = "test error";
|
|
51
|
+
const error = createR11sNetworkError(message, 500);
|
|
52
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);
|
|
53
|
+
assert.strictEqual(error.canRetry, true);
|
|
54
|
+
});
|
|
55
|
+
it("creates retriable error on anything else with retryAfter", () => {
|
|
56
|
+
const message = "test error";
|
|
57
|
+
const error = createR11sNetworkError(message, 400, 100000);
|
|
58
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.throttlingError);
|
|
59
|
+
assert.strictEqual(error.canRetry, true);
|
|
60
|
+
assert.strictEqual(error.retryAfterSeconds, 100);
|
|
61
|
+
});
|
|
62
|
+
it("creates non-retriable error on anything else", () => {
|
|
63
|
+
const message = "test error";
|
|
64
|
+
const error2 = createR11sNetworkError(message, 400);
|
|
65
|
+
assert.strictEqual(error2.errorType, RouterliciousErrorTypes.genericNetworkError);
|
|
66
|
+
assert.strictEqual(error2.canRetry, false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("throwR11sNetworkError()", () => {
|
|
70
|
+
it("throws non-retriable authorization error on 401", () => {
|
|
71
|
+
const message = "test error";
|
|
72
|
+
assert.throws(() => {
|
|
73
|
+
throwR11sNetworkError(message, 401);
|
|
74
|
+
}, {
|
|
75
|
+
errorType: RouterliciousErrorTypes.authorizationError,
|
|
76
|
+
canRetry: false,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("throws non-retriable authorization error on 403", () => {
|
|
80
|
+
const message = "test error";
|
|
81
|
+
assert.throws(() => {
|
|
82
|
+
throwR11sNetworkError(message, 403);
|
|
83
|
+
}, {
|
|
84
|
+
errorType: RouterliciousErrorTypes.authorizationError,
|
|
85
|
+
canRetry: false,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
it("throws non-retriable not-found error on 404", () => {
|
|
89
|
+
const message = "test error";
|
|
90
|
+
assert.throws(() => {
|
|
91
|
+
throwR11sNetworkError(message, 404);
|
|
92
|
+
}, {
|
|
93
|
+
errorType: RouterliciousErrorTypes.fileNotFoundOrAccessDeniedError,
|
|
94
|
+
canRetry: false,
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it("throws retriable error on 429 with retry-after", () => {
|
|
98
|
+
const message = "test error";
|
|
99
|
+
assert.throws(() => {
|
|
100
|
+
throwR11sNetworkError(message, 429, 5000);
|
|
101
|
+
}, {
|
|
102
|
+
errorType: RouterliciousErrorTypes.throttlingError,
|
|
103
|
+
canRetry: true,
|
|
104
|
+
retryAfterSeconds: 5,
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
it("throws retriable error on 429 without retry-after", () => {
|
|
108
|
+
const message = "test error";
|
|
109
|
+
assert.throws(() => {
|
|
110
|
+
throwR11sNetworkError(message, 429);
|
|
111
|
+
}, {
|
|
112
|
+
errorType: RouterliciousErrorTypes.genericNetworkError,
|
|
113
|
+
canRetry: true,
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
it("throws retriable error on 500", () => {
|
|
117
|
+
const message = "test error";
|
|
118
|
+
assert.throws(() => {
|
|
119
|
+
throwR11sNetworkError(message, 500);
|
|
120
|
+
}, {
|
|
121
|
+
errorType: RouterliciousErrorTypes.genericNetworkError,
|
|
122
|
+
canRetry: true,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
it("throws retriable error on anything else with retryAfter", () => {
|
|
126
|
+
const message = "test error";
|
|
127
|
+
assert.throws(() => {
|
|
128
|
+
throwR11sNetworkError(message, 400, 200000);
|
|
129
|
+
}, {
|
|
130
|
+
errorType: RouterliciousErrorTypes.throttlingError,
|
|
131
|
+
canRetry: true,
|
|
132
|
+
retryAfterSeconds: 200,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
it("throws non-retriable error on anything else", () => {
|
|
136
|
+
const message = "test error";
|
|
137
|
+
assert.throws(() => {
|
|
138
|
+
throwR11sNetworkError(message, 400);
|
|
139
|
+
}, {
|
|
140
|
+
errorType: RouterliciousErrorTypes.genericNetworkError,
|
|
141
|
+
canRetry: false,
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe("errorObjectFromSocketError()", () => {
|
|
146
|
+
const handler = "test_handler";
|
|
147
|
+
const message = "test error";
|
|
148
|
+
const assertExpectedMessage = (actualMessage) => {
|
|
149
|
+
assert(actualMessage.includes(message), "R11s error should include socket error message");
|
|
150
|
+
assert(actualMessage.includes(handler), "R11s error should include handler name");
|
|
151
|
+
};
|
|
152
|
+
it("creates non-retriable authorization error on 401", () => {
|
|
153
|
+
const error = errorObjectFromSocketError({
|
|
154
|
+
code: 401,
|
|
155
|
+
message,
|
|
156
|
+
}, handler);
|
|
157
|
+
assertExpectedMessage(error.message);
|
|
158
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);
|
|
159
|
+
assert.strictEqual(error.canRetry, false);
|
|
160
|
+
assert.strictEqual(error.statusCode, 401);
|
|
161
|
+
});
|
|
162
|
+
it("creates non-retriable authorization error on 403", () => {
|
|
163
|
+
const error = errorObjectFromSocketError({
|
|
164
|
+
code: 403,
|
|
165
|
+
message,
|
|
166
|
+
}, handler);
|
|
167
|
+
assertExpectedMessage(error.message);
|
|
168
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);
|
|
169
|
+
assert.strictEqual(error.canRetry, false);
|
|
170
|
+
assert.strictEqual(error.statusCode, 403);
|
|
171
|
+
});
|
|
172
|
+
it("creates non-retriable not-found error on 404", () => {
|
|
173
|
+
const error = errorObjectFromSocketError({
|
|
174
|
+
code: 404,
|
|
175
|
+
message,
|
|
176
|
+
}, handler);
|
|
177
|
+
assertExpectedMessage(error.message);
|
|
178
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.fileNotFoundOrAccessDeniedError);
|
|
179
|
+
assert.strictEqual(error.canRetry, false);
|
|
180
|
+
assert.strictEqual(error.statusCode, 404);
|
|
181
|
+
});
|
|
182
|
+
it("creates retriable error on 429 with retry-after", () => {
|
|
183
|
+
const error = errorObjectFromSocketError({
|
|
184
|
+
code: 429,
|
|
185
|
+
message,
|
|
186
|
+
retryAfterMs: 5000,
|
|
187
|
+
}, handler);
|
|
188
|
+
assert(isIThrottlingWarning(error));
|
|
189
|
+
assertExpectedMessage(error.message);
|
|
190
|
+
assert.strictEqual(error.canRetry, true);
|
|
191
|
+
assert.strictEqual(error.retryAfterSeconds, 5);
|
|
192
|
+
assert.strictEqual(error.statusCode, 429);
|
|
193
|
+
});
|
|
194
|
+
it("creates retriable error on 429 without retry-after", () => {
|
|
195
|
+
const error = errorObjectFromSocketError({
|
|
196
|
+
code: 429,
|
|
197
|
+
message,
|
|
198
|
+
}, handler);
|
|
199
|
+
assertExpectedMessage(error.message);
|
|
200
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);
|
|
201
|
+
assert.strictEqual(error.canRetry, true);
|
|
202
|
+
});
|
|
203
|
+
it("creates retriable error on 500", () => {
|
|
204
|
+
const error = errorObjectFromSocketError({
|
|
205
|
+
code: 500,
|
|
206
|
+
message,
|
|
207
|
+
}, handler);
|
|
208
|
+
assertExpectedMessage(error.message);
|
|
209
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);
|
|
210
|
+
assert.strictEqual(error.canRetry, true);
|
|
211
|
+
assert.strictEqual(error.statusCode, 500);
|
|
212
|
+
});
|
|
213
|
+
it("creates retriable error on 400 with retryAfter", () => {
|
|
214
|
+
const error = errorObjectFromSocketError({
|
|
215
|
+
code: 400,
|
|
216
|
+
message,
|
|
217
|
+
retryAfterMs: 300000,
|
|
218
|
+
}, handler);
|
|
219
|
+
assertExpectedMessage(error.message);
|
|
220
|
+
assert.strictEqual(error.errorType, RouterliciousErrorTypes.throttlingError);
|
|
221
|
+
assert.strictEqual(error.canRetry, true);
|
|
222
|
+
assert.strictEqual(error.retryAfterSeconds, 300);
|
|
223
|
+
assert.strictEqual(error.statusCode, 400);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
//# sourceMappingURL=errorUtils.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorUtils.spec.js","sourceRoot":"","sources":["../../src/test/errorUtils.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,EACN,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,GACrB,MAAM,kBAAkB,CAAC;AAE1B,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC3B;;OAEG;IACH,SAAS,oBAAoB,CAAC,KAAc;QAC3C,OAAO,CACN,KAAK,KAAK,SAAS;YAClB,KAAqC,CAAC,SAAS,KAAK,eAAe,CAAC,eAAe;YACnF,KAAqC,CAAC,iBAAiB,KAAK,SAAS,CACtE,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACzC,EAAE,CAAC,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EACD,OAAO,CACP,CAAC;YACF,qBAAqB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACrC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,SAAS,EAAE,uBAAuB,CAAC,eAAe,CAAC,CAAC;YAC7E,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACzC,MAAM,CAAC,WAAW,CAAE,KAAa,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;YAC1D,MAAM,CAAC,WAAW,CAAE,KAAa,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport assert from \"assert\";\nimport { FluidErrorTypes } from \"@fluidframework/core-interfaces\";\nimport { IThrottlingWarning } from \"@fluidframework/driver-definitions\";\nimport {\n\tRouterliciousErrorTypes,\n\tcreateR11sNetworkError,\n\terrorObjectFromSocketError,\n\tthrowR11sNetworkError,\n} from \"../errorUtils.js\";\n\ndescribe(\"ErrorUtils\", () => {\n\t/**\n\t * Checks if the input is an {@link IThrottlingWarning}.\n\t */\n\tfunction isIThrottlingWarning(input: unknown): input is IThrottlingWarning {\n\t\treturn (\n\t\t\tinput !== undefined &&\n\t\t\t(input as Partial<IThrottlingWarning>).errorType === FluidErrorTypes.throttlingError &&\n\t\t\t(input as Partial<IThrottlingWarning>).retryAfterSeconds !== undefined\n\t\t);\n\t}\n\n\tdescribe(\"createR11sNetworkError()\", () => {\n\t\tit(\"creates non-retriable authorization error on 401\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error = createR11sNetworkError(message, 401);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);\n\t\t\tassert.strictEqual(error.canRetry, false);\n\t\t});\n\t\tit(\"creates non-retriable authorization error on 403\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error = createR11sNetworkError(message, 403);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);\n\t\t\tassert.strictEqual(error.canRetry, false);\n\t\t});\n\t\tit(\"creates non-retriable not-found error on 404\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error = createR11sNetworkError(message, 404);\n\t\t\tassert.strictEqual(\n\t\t\t\terror.errorType,\n\t\t\t\tRouterliciousErrorTypes.fileNotFoundOrAccessDeniedError,\n\t\t\t);\n\t\t\tassert.strictEqual(error.canRetry, false);\n\t\t});\n\t\tit(\"creates retriable error on 429 with retry-after\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error = createR11sNetworkError(message, 429, 5000);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.throttlingError);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t\tassert.strictEqual((error as IThrottlingWarning).retryAfterSeconds, 5);\n\t\t});\n\t\tit(\"creates retriable error on 429 without retry-after\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error = createR11sNetworkError(message, 429);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t});\n\t\tit(\"creates retriable error on 500\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error = createR11sNetworkError(message, 500);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t});\n\t\tit(\"creates retriable error on anything else with retryAfter\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error = createR11sNetworkError(message, 400, 100000);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.throttlingError);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t\tassert.strictEqual((error as any).retryAfterSeconds, 100);\n\t\t});\n\t\tit(\"creates non-retriable error on anything else\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tconst error2 = createR11sNetworkError(message, 400);\n\t\t\tassert.strictEqual(error2.errorType, RouterliciousErrorTypes.genericNetworkError);\n\t\t\tassert.strictEqual(error2.canRetry, false);\n\t\t});\n\t});\n\tdescribe(\"throwR11sNetworkError()\", () => {\n\t\tit(\"throws non-retriable authorization error on 401\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 401);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.authorizationError,\n\t\t\t\t\tcanRetry: false,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t\tit(\"throws non-retriable authorization error on 403\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 403);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.authorizationError,\n\t\t\t\t\tcanRetry: false,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t\tit(\"throws non-retriable not-found error on 404\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 404);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.fileNotFoundOrAccessDeniedError,\n\t\t\t\t\tcanRetry: false,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t\tit(\"throws retriable error on 429 with retry-after\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 429, 5000);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.throttlingError,\n\t\t\t\t\tcanRetry: true,\n\t\t\t\t\tretryAfterSeconds: 5,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t\tit(\"throws retriable error on 429 without retry-after\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 429);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.genericNetworkError,\n\t\t\t\t\tcanRetry: true,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t\tit(\"throws retriable error on 500\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 500);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.genericNetworkError,\n\t\t\t\t\tcanRetry: true,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t\tit(\"throws retriable error on anything else with retryAfter\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 400, 200000);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.throttlingError,\n\t\t\t\t\tcanRetry: true,\n\t\t\t\t\tretryAfterSeconds: 200,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t\tit(\"throws non-retriable error on anything else\", () => {\n\t\t\tconst message = \"test error\";\n\t\t\tassert.throws(\n\t\t\t\t() => {\n\t\t\t\t\tthrowR11sNetworkError(message, 400);\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\terrorType: RouterliciousErrorTypes.genericNetworkError,\n\t\t\t\t\tcanRetry: false,\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t});\n\tdescribe(\"errorObjectFromSocketError()\", () => {\n\t\tconst handler = \"test_handler\";\n\t\tconst message = \"test error\";\n\t\tconst assertExpectedMessage = (actualMessage: string) => {\n\t\t\tassert(\n\t\t\t\tactualMessage.includes(message),\n\t\t\t\t\"R11s error should include socket error message\",\n\t\t\t);\n\t\t\tassert(actualMessage.includes(handler), \"R11s error should include handler name\");\n\t\t};\n\t\tit(\"creates non-retriable authorization error on 401\", () => {\n\t\t\tconst error = errorObjectFromSocketError(\n\t\t\t\t{\n\t\t\t\t\tcode: 401,\n\t\t\t\t\tmessage,\n\t\t\t\t},\n\t\t\t\thandler,\n\t\t\t);\n\t\t\tassertExpectedMessage(error.message);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);\n\t\t\tassert.strictEqual(error.canRetry, false);\n\t\t\tassert.strictEqual((error as any).statusCode, 401);\n\t\t});\n\t\tit(\"creates non-retriable authorization error on 403\", () => {\n\t\t\tconst error = errorObjectFromSocketError(\n\t\t\t\t{\n\t\t\t\t\tcode: 403,\n\t\t\t\t\tmessage,\n\t\t\t\t},\n\t\t\t\thandler,\n\t\t\t);\n\t\t\tassertExpectedMessage(error.message);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.authorizationError);\n\t\t\tassert.strictEqual(error.canRetry, false);\n\t\t\tassert.strictEqual((error as any).statusCode, 403);\n\t\t});\n\t\tit(\"creates non-retriable not-found error on 404\", () => {\n\t\t\tconst error = errorObjectFromSocketError(\n\t\t\t\t{\n\t\t\t\t\tcode: 404,\n\t\t\t\t\tmessage,\n\t\t\t\t},\n\t\t\t\thandler,\n\t\t\t);\n\t\t\tassertExpectedMessage(error.message);\n\t\t\tassert.strictEqual(\n\t\t\t\terror.errorType,\n\t\t\t\tRouterliciousErrorTypes.fileNotFoundOrAccessDeniedError,\n\t\t\t);\n\t\t\tassert.strictEqual(error.canRetry, false);\n\t\t\tassert.strictEqual((error as any).statusCode, 404);\n\t\t});\n\t\tit(\"creates retriable error on 429 with retry-after\", () => {\n\t\t\tconst error = errorObjectFromSocketError(\n\t\t\t\t{\n\t\t\t\t\tcode: 429,\n\t\t\t\t\tmessage,\n\t\t\t\t\tretryAfterMs: 5000,\n\t\t\t\t},\n\t\t\t\thandler,\n\t\t\t);\n\n\t\t\tassert(isIThrottlingWarning(error));\n\t\t\tassertExpectedMessage(error.message);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t\tassert.strictEqual(error.retryAfterSeconds, 5);\n\t\t\tassert.strictEqual((error as any).statusCode, 429);\n\t\t});\n\t\tit(\"creates retriable error on 429 without retry-after\", () => {\n\t\t\tconst error = errorObjectFromSocketError(\n\t\t\t\t{\n\t\t\t\t\tcode: 429,\n\t\t\t\t\tmessage,\n\t\t\t\t},\n\t\t\t\thandler,\n\t\t\t);\n\t\t\tassertExpectedMessage(error.message);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t});\n\t\tit(\"creates retriable error on 500\", () => {\n\t\t\tconst error = errorObjectFromSocketError(\n\t\t\t\t{\n\t\t\t\t\tcode: 500,\n\t\t\t\t\tmessage,\n\t\t\t\t},\n\t\t\t\thandler,\n\t\t\t);\n\t\t\tassertExpectedMessage(error.message);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.genericNetworkError);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t\tassert.strictEqual((error as any).statusCode, 500);\n\t\t});\n\t\tit(\"creates retriable error on 400 with retryAfter\", () => {\n\t\t\tconst error = errorObjectFromSocketError(\n\t\t\t\t{\n\t\t\t\t\tcode: 400,\n\t\t\t\t\tmessage,\n\t\t\t\t\tretryAfterMs: 300000,\n\t\t\t\t},\n\t\t\t\thandler,\n\t\t\t);\n\t\t\tassertExpectedMessage(error.message);\n\t\t\tassert.strictEqual(error.errorType, RouterliciousErrorTypes.throttlingError);\n\t\t\tassert.strictEqual(error.canRetry, true);\n\t\t\tassert.strictEqual((error as any).retryAfterSeconds, 300);\n\t\t\tassert.strictEqual((error as any).statusCode, 400);\n\t\t});\n\t});\n});\n"]}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { strict as assert } from "assert";
|
|
6
|
+
import { useFakeTimers } from "sinon";
|
|
7
|
+
import { MapWithExpiration } from "../mapWithExpiration.js";
|
|
8
|
+
describe("MapWithExpiration", () => {
|
|
9
|
+
let clock;
|
|
10
|
+
before(() => {
|
|
11
|
+
clock = useFakeTimers();
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
clock.reset();
|
|
15
|
+
});
|
|
16
|
+
after(() => {
|
|
17
|
+
clock.restore();
|
|
18
|
+
});
|
|
19
|
+
function assertSize(actual, expected, message) {
|
|
20
|
+
assert.equal(actual.size, expected.size, `'size' mismatch (${message})`);
|
|
21
|
+
}
|
|
22
|
+
function assertForEach(actual, expected, message) {
|
|
23
|
+
const actualValues = [];
|
|
24
|
+
const expectedValues = [];
|
|
25
|
+
actual.forEach((value, key) => {
|
|
26
|
+
actualValues[key] = value;
|
|
27
|
+
});
|
|
28
|
+
expected.forEach((value, key) => {
|
|
29
|
+
expectedValues[key] = value;
|
|
30
|
+
});
|
|
31
|
+
assert.equal(actualValues.join(","), expectedValues.join(","), `'forEach' mismatch (${message})`);
|
|
32
|
+
}
|
|
33
|
+
/** Asserts that actual has each key in expected (and elsewhere we assert that .keys matches) */
|
|
34
|
+
function assertHas(actual, expected) {
|
|
35
|
+
for (const k of expected.keys()) {
|
|
36
|
+
assert(actual.has(k), "'has' mismatch");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Asserts that actual.get returns the same value as expected for all keys (and elsewhere we assert that .keys matches) */
|
|
40
|
+
function assertGet(actual, expected, message) {
|
|
41
|
+
for (const k of expected.keys()) {
|
|
42
|
+
assert.equal(actual.get(k), expected.get(k), `'get' mismatch (${message})`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Helper that takes the name of a function returning an Iterable,
|
|
47
|
+
* and returns a function that ensures actual and expected yield the same result when iterated over.
|
|
48
|
+
* If fnName is undefined, iterate over actual and expected directly
|
|
49
|
+
*/
|
|
50
|
+
const assertIterable = (fnName) => function (actual, expected, message) {
|
|
51
|
+
const actuals = [];
|
|
52
|
+
for (const a of fnName === undefined ? actual : actual[fnName]()) {
|
|
53
|
+
actuals.push(a);
|
|
54
|
+
}
|
|
55
|
+
const expecteds = [];
|
|
56
|
+
for (const e of fnName === undefined ? expected : expected[fnName]()) {
|
|
57
|
+
expecteds.push(e);
|
|
58
|
+
}
|
|
59
|
+
assert.deepEqual(actuals.sort(), expecteds.sort(), `Iterator mismatch (${message})`);
|
|
60
|
+
};
|
|
61
|
+
const assertEntries = assertIterable("entries");
|
|
62
|
+
const assertKeys = assertIterable("keys");
|
|
63
|
+
const assertValues = assertIterable("values");
|
|
64
|
+
const assertSymbolIterator = assertIterable(Symbol.iterator);
|
|
65
|
+
const assertIterator = assertIterable();
|
|
66
|
+
/**
|
|
67
|
+
* This generates a test case per function to validate.
|
|
68
|
+
* They need to be tested independently since these all have side effects
|
|
69
|
+
*/
|
|
70
|
+
function test(testName, testCallback) {
|
|
71
|
+
[
|
|
72
|
+
[assertSize, "check size"],
|
|
73
|
+
[assertForEach, "check forEach"],
|
|
74
|
+
[assertEntries, "check entries"],
|
|
75
|
+
[assertKeys, "check keys"],
|
|
76
|
+
[assertValues, "check values"],
|
|
77
|
+
[assertSymbolIterator, "check Symbol.iterator"],
|
|
78
|
+
[assertIterator, "check Iterator"],
|
|
79
|
+
[assertHas, "check has"],
|
|
80
|
+
[assertGet, "check get"],
|
|
81
|
+
].forEach(([assertFn, caseName]) => {
|
|
82
|
+
it(`${testName} (${caseName})`, () => {
|
|
83
|
+
testCallback(assertFn);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
test("Basic expiry", (assertMatches) => {
|
|
88
|
+
const expiryMs = 10;
|
|
89
|
+
const map = new MapWithExpiration(expiryMs);
|
|
90
|
+
const expected = new Map();
|
|
91
|
+
map.set(1, "one");
|
|
92
|
+
map.set(9, "nine");
|
|
93
|
+
expected.set(1, "one");
|
|
94
|
+
expected.set(9, "nine");
|
|
95
|
+
clock.tick(5);
|
|
96
|
+
assertMatches(map, expected, "Shouldn't be expired after 5ms");
|
|
97
|
+
map.get(1); // Should NOT reset the expiry, only set
|
|
98
|
+
map.set(9, "niner");
|
|
99
|
+
map.set(2, "two");
|
|
100
|
+
expected.set(9, "niner");
|
|
101
|
+
expected.set(2, "two");
|
|
102
|
+
assertMatches(map, expected, "Still shouldn't be expired");
|
|
103
|
+
clock.tick(5);
|
|
104
|
+
expected.delete(1);
|
|
105
|
+
assertMatches(map, expected, "Should be expired after 10ms unless set in the interim");
|
|
106
|
+
});
|
|
107
|
+
test("delete", (assertMatches) => {
|
|
108
|
+
const expiryMs = 10;
|
|
109
|
+
const map = new MapWithExpiration(expiryMs);
|
|
110
|
+
const expected = new Map();
|
|
111
|
+
map.set(1, "one");
|
|
112
|
+
map.set(9, "nine");
|
|
113
|
+
expected.set(1, "one");
|
|
114
|
+
expected.set(9, "nine");
|
|
115
|
+
assertMatches(map, expected, "Should have set some keys");
|
|
116
|
+
map.delete(9);
|
|
117
|
+
expected.delete(9);
|
|
118
|
+
assertMatches(map, expected, "Should be updated by delete");
|
|
119
|
+
});
|
|
120
|
+
test("clear", (assertMatches) => {
|
|
121
|
+
const expiryMs = 10;
|
|
122
|
+
const map = new MapWithExpiration(expiryMs);
|
|
123
|
+
const expected = new Map();
|
|
124
|
+
map.set(1, "one");
|
|
125
|
+
map.set(9, "nine");
|
|
126
|
+
expected.set(1, "one");
|
|
127
|
+
expected.set(9, "nine");
|
|
128
|
+
assertMatches(map, expected, "Should have set some keys");
|
|
129
|
+
map.clear();
|
|
130
|
+
expected.clear();
|
|
131
|
+
assertMatches(map, expected, "Should be empty after clear");
|
|
132
|
+
});
|
|
133
|
+
describe("forEach thisArg", () => {
|
|
134
|
+
function testForEachCases(testName, testFn) {
|
|
135
|
+
it(testName, () => {
|
|
136
|
+
testFn([new Map(), new MapWithExpiration(10)], // We run plain Map and MapWithExpiration through to ensure matching behavior
|
|
137
|
+
["THIS", undefined]);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
testForEachCases("Inline function callback should use thisArg for 'this'", (maps, thisArgs) => {
|
|
141
|
+
for (const thisArg of thisArgs) {
|
|
142
|
+
for (const map of maps) {
|
|
143
|
+
map.set(1, "one");
|
|
144
|
+
map.forEach(function (value, key, m) {
|
|
145
|
+
assert.equal(this, thisArg, "Incorrect value for 'this'");
|
|
146
|
+
}, thisArg);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
testForEachCases(".bind on an inline function callback should supersede thisArg", (maps, thisArgs) => {
|
|
151
|
+
for (const thisArg of thisArgs) {
|
|
152
|
+
for (const map of maps) {
|
|
153
|
+
map.set(1, "one");
|
|
154
|
+
map.forEach(function (value, key, m) {
|
|
155
|
+
assert.equal(this, "BOUND", "Incorrect value for 'this'");
|
|
156
|
+
}.bind("BOUND"), thisArg);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
class Foo {
|
|
161
|
+
cb(valueWhichIsExpectedThis, k, m) {
|
|
162
|
+
assert(!(this instanceof Foo), "'this' should not be a Foo, it should have been overridden");
|
|
163
|
+
assert.equal(this, valueWhichIsExpectedThis, "Incorrect value for 'this'");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
testForEachCases("Class function callback should use thisArg not the class instance", (maps, thisArgs) => {
|
|
167
|
+
const foo = new Foo();
|
|
168
|
+
for (const thisArg of thisArgs) {
|
|
169
|
+
for (const map of maps) {
|
|
170
|
+
map.set(1, thisArg); // We will sneak in thisArg as the value to let us assert about it in cb
|
|
171
|
+
map.forEach(foo.cb, thisArg);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
testForEachCases(".bind on a class function callback should supersede thisArg", (maps, thisArgs) => {
|
|
176
|
+
const foo = new Foo();
|
|
177
|
+
for (const thisArg of thisArgs) {
|
|
178
|
+
for (const map of maps) {
|
|
179
|
+
map.set(1, "BOUND"); // We will sneak in thisArg as the value to let us assert about it in cb
|
|
180
|
+
map.forEach(foo.cb.bind("BOUND"), thisArg);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
// In ESM the the 'this' value is 'undefined', but in CJS it is '{__esModule: true}'.
|
|
185
|
+
// Therefore, we exempt the test value 'undefined' from the below assertion.
|
|
186
|
+
if (this !== undefined) {
|
|
187
|
+
testForEachCases("Arrow functions don't pick up thisArg", (maps, thisArgs) => {
|
|
188
|
+
for (const thisArg of thisArgs) {
|
|
189
|
+
for (const map of maps) {
|
|
190
|
+
map.set(1, "one");
|
|
191
|
+
map.forEach(() => {
|
|
192
|
+
assert.notEqual(this, thisArg, "Expected 'this' to be unchanged for arrow fn");
|
|
193
|
+
}, thisArg);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
it("toString", () => {
|
|
200
|
+
const map = new MapWithExpiration(0);
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
202
|
+
assert.equal(map.toString(), "[object Map]");
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
//# sourceMappingURL=mapWithExpiration.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapWithExpiration.spec.js","sourceRoot":"","sources":["../../src/test/mapWithExpiration.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAmB,aAAa,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,IAAI,KAAsB,CAAC;IAE3B,MA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AC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"assert\";\nimport { SinonFakeTimers, useFakeTimers } from \"sinon\";\nimport { MapWithExpiration } from \"../mapWithExpiration.js\";\n\ndescribe(\"MapWithExpiration\", () => {\n\tlet clock: SinonFakeTimers;\n\n\tbefore(() => {\n\t\tclock = useFakeTimers();\n\t});\n\n\tafterEach(() => {\n\t\tclock.reset();\n\t});\n\n\tafter(() => {\n\t\tclock.restore();\n\t});\n\n\tfunction assertSize(\n\t\tactual: MapWithExpiration<number, string>,\n\t\texpected: Map<number, string>,\n\t\tmessage: string,\n\t) {\n\t\tassert.equal(actual.size, expected.size, `'size' mismatch (${message})`);\n\t}\n\n\tfunction assertForEach(\n\t\tactual: MapWithExpiration<number, string>,\n\t\texpected: Map<number, string>,\n\t\tmessage: string,\n\t) {\n\t\tconst actualValues: string[] = [];\n\t\tconst expectedValues: string[] = [];\n\t\tactual.forEach((value, key) => {\n\t\t\tactualValues[key] = value;\n\t\t});\n\t\texpected.forEach((value, key) => {\n\t\t\texpectedValues[key] = value;\n\t\t});\n\t\tassert.equal(\n\t\t\tactualValues.join(\",\"),\n\t\t\texpectedValues.join(\",\"),\n\t\t\t`'forEach' mismatch (${message})`,\n\t\t);\n\t}\n\n\t/** Asserts that actual has each key in expected (and elsewhere we assert that .keys matches) */\n\tfunction assertHas(actual: MapWithExpiration<number, string>, expected: Map<number, string>) {\n\t\tfor (const k of expected.keys()) {\n\t\t\tassert(actual.has(k), \"'has' mismatch\");\n\t\t}\n\t}\n\n\t/** Asserts that actual.get returns the same value as expected for all keys (and elsewhere we assert that .keys matches) */\n\tfunction assertGet(\n\t\tactual: MapWithExpiration<number, string>,\n\t\texpected: Map<number, string>,\n\t\tmessage: string,\n\t) {\n\t\tfor (const k of expected.keys()) {\n\t\t\tassert.equal(actual.get(k), expected.get(k), `'get' mismatch (${message})`);\n\t\t}\n\t}\n\n\t/**\n\t * Helper that takes the name of a function returning an Iterable,\n\t * and returns a function that ensures actual and expected yield the same result when iterated over.\n\t * If fnName is undefined, iterate over actual and expected directly\n\t */\n\tconst assertIterable = (fnName?: string | typeof Symbol.iterator) =>\n\t\tfunction (\n\t\t\tactual: MapWithExpiration<number, string>,\n\t\t\texpected: Map<number, string>,\n\t\t\tmessage: string,\n\t\t) {\n\t\t\tconst actuals: any[] = [];\n\t\t\tfor (const a of fnName === undefined ? actual : actual[fnName]()) {\n\t\t\t\tactuals.push(a);\n\t\t\t}\n\t\t\tconst expecteds: any[] = [];\n\t\t\tfor (const e of fnName === undefined ? expected : expected[fnName]()) {\n\t\t\t\texpecteds.push(e);\n\t\t\t}\n\t\t\tassert.deepEqual(actuals.sort(), expecteds.sort(), `Iterator mismatch (${message})`);\n\t\t};\n\n\tconst assertEntries = assertIterable(\"entries\");\n\tconst assertKeys = assertIterable(\"keys\");\n\tconst assertValues = assertIterable(\"values\");\n\tconst assertSymbolIterator = assertIterable(Symbol.iterator);\n\tconst assertIterator = assertIterable();\n\n\t/**\n\t * This generates a test case per function to validate.\n\t * They need to be tested independently since these all have side effects\n\t */\n\tfunction test(testName: string, testCallback: (assertFn) => void) {\n\t\t[\n\t\t\t[assertSize, \"check size\"] as const,\n\t\t\t[assertForEach, \"check forEach\"] as const,\n\t\t\t[assertEntries, \"check entries\"] as const,\n\t\t\t[assertKeys, \"check keys\"] as const,\n\t\t\t[assertValues, \"check values\"] as const,\n\t\t\t[assertSymbolIterator, \"check Symbol.iterator\"] as const,\n\t\t\t[assertIterator, \"check Iterator\"] as const,\n\t\t\t[assertHas, \"check has\"] as const,\n\t\t\t[assertGet, \"check get\"] as const,\n\t\t].forEach(([assertFn, caseName]) => {\n\t\t\tit(`${testName} (${caseName})`, () => {\n\t\t\t\ttestCallback(assertFn);\n\t\t\t});\n\t\t});\n\t}\n\n\ttest(\"Basic expiry\", (assertMatches: (\n\t\tactual: MapWithExpiration<number, string>,\n\t\texpected: Map<number, string>,\n\t\tmessage: string,\n\t) => void) => {\n\t\tconst expiryMs = 10;\n\t\tconst map = new MapWithExpiration<number, string>(expiryMs);\n\t\tconst expected = new Map<number, string>();\n\n\t\tmap.set(1, \"one\");\n\t\tmap.set(9, \"nine\");\n\t\texpected.set(1, \"one\");\n\t\texpected.set(9, \"nine\");\n\n\t\tclock.tick(5);\n\t\tassertMatches(map, expected, \"Shouldn't be expired after 5ms\");\n\n\t\tmap.get(1); // Should NOT reset the expiry, only set\n\t\tmap.set(9, \"niner\");\n\t\tmap.set(2, \"two\");\n\t\texpected.set(9, \"niner\");\n\t\texpected.set(2, \"two\");\n\t\tassertMatches(map, expected, \"Still shouldn't be expired\");\n\n\t\tclock.tick(5);\n\t\texpected.delete(1);\n\t\tassertMatches(map, expected, \"Should be expired after 10ms unless set in the interim\");\n\t});\n\n\ttest(\"delete\", (assertMatches: (\n\t\tactual: MapWithExpiration<number, string>,\n\t\texpected: Map<number, string>,\n\t\tmessage: string,\n\t) => void) => {\n\t\tconst expiryMs = 10;\n\t\tconst map = new MapWithExpiration<number, string>(expiryMs);\n\t\tconst expected = new Map<number, string>();\n\n\t\tmap.set(1, \"one\");\n\t\tmap.set(9, \"nine\");\n\t\texpected.set(1, \"one\");\n\t\texpected.set(9, \"nine\");\n\n\t\tassertMatches(map, expected, \"Should have set some keys\");\n\n\t\tmap.delete(9);\n\t\texpected.delete(9);\n\n\t\tassertMatches(map, expected, \"Should be updated by delete\");\n\t});\n\n\ttest(\"clear\", (assertMatches: (\n\t\tactual: MapWithExpiration<number, string>,\n\t\texpected: Map<number, string>,\n\t\tmessage: string,\n\t) => void) => {\n\t\tconst expiryMs = 10;\n\t\tconst map = new MapWithExpiration<number, string>(expiryMs);\n\t\tconst expected = new Map<number, string>();\n\n\t\tmap.set(1, \"one\");\n\t\tmap.set(9, \"nine\");\n\t\texpected.set(1, \"one\");\n\t\texpected.set(9, \"nine\");\n\n\t\tassertMatches(map, expected, \"Should have set some keys\");\n\n\t\tmap.clear();\n\t\texpected.clear();\n\n\t\tassertMatches(map, expected, \"Should be empty after clear\");\n\t});\n\n\tdescribe(\"forEach thisArg\", () => {\n\t\tfunction testForEachCases(\n\t\t\ttestName: string,\n\t\t\ttestFn: (maps: Map<any, any>[], thisArgs: any[]) => void,\n\t\t) {\n\t\t\tit(testName, () => {\n\t\t\t\ttestFn(\n\t\t\t\t\t[new Map(), new MapWithExpiration(10)], // We run plain Map and MapWithExpiration through to ensure matching behavior\n\t\t\t\t\t[\"THIS\", undefined],\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\n\t\ttestForEachCases(\n\t\t\t\"Inline function callback should use thisArg for 'this'\",\n\t\t\t(maps, thisArgs) => {\n\t\t\t\tfor (const thisArg of thisArgs) {\n\t\t\t\t\tfor (const map of maps) {\n\t\t\t\t\t\tmap.set(1, \"one\");\n\t\t\t\t\t\tmap.forEach(function (\n\t\t\t\t\t\t\tthis: any,\n\t\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t\t\tkey: number,\n\t\t\t\t\t\t\tm: Map<number, string>,\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tassert.equal(this, thisArg, \"Incorrect value for 'this'\");\n\t\t\t\t\t\t}, thisArg);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\ttestForEachCases(\n\t\t\t\".bind on an inline function callback should supersede thisArg\",\n\t\t\t(maps, thisArgs) => {\n\t\t\t\tfor (const thisArg of thisArgs) {\n\t\t\t\t\tfor (const map of maps) {\n\t\t\t\t\t\tmap.set(1, \"one\");\n\t\t\t\t\t\tmap.forEach(\n\t\t\t\t\t\t\tfunction (\n\t\t\t\t\t\t\t\tthis: any,\n\t\t\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t\t\t\tkey: number,\n\t\t\t\t\t\t\t\tm: Map<number, string>,\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tassert.equal(this, \"BOUND\", \"Incorrect value for 'this'\");\n\t\t\t\t\t\t\t}.bind(\"BOUND\"),\n\t\t\t\t\t\t\tthisArg,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tclass Foo {\n\t\t\tcb(this: any, valueWhichIsExpectedThis, k, m) {\n\t\t\t\tassert(\n\t\t\t\t\t!(this instanceof Foo),\n\t\t\t\t\t\"'this' should not be a Foo, it should have been overridden\",\n\t\t\t\t);\n\t\t\t\tassert.equal(this, valueWhichIsExpectedThis, \"Incorrect value for 'this'\");\n\t\t\t}\n\t\t}\n\n\t\ttestForEachCases(\n\t\t\t\"Class function callback should use thisArg not the class instance\",\n\t\t\t(maps, thisArgs) => {\n\t\t\t\tconst foo = new Foo();\n\t\t\t\tfor (const thisArg of thisArgs) {\n\t\t\t\t\tfor (const map of maps) {\n\t\t\t\t\t\tmap.set(1, thisArg); // We will sneak in thisArg as the value to let us assert about it in cb\n\t\t\t\t\t\tmap.forEach(foo.cb, thisArg);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\ttestForEachCases(\n\t\t\t\".bind on a class function callback should supersede thisArg\",\n\t\t\t(maps, thisArgs) => {\n\t\t\t\tconst foo = new Foo();\n\t\t\t\tfor (const thisArg of thisArgs) {\n\t\t\t\t\tfor (const map of maps) {\n\t\t\t\t\t\tmap.set(1, \"BOUND\"); // We will sneak in thisArg as the value to let us assert about it in cb\n\t\t\t\t\t\tmap.forEach(foo.cb.bind(\"BOUND\"), thisArg);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\t// In ESM the the 'this' value is 'undefined', but in CJS it is '{__esModule: true}'.\n\t\t// Therefore, we exempt the test value 'undefined' from the below assertion.\n\t\tif (this !== undefined) {\n\t\t\ttestForEachCases(\"Arrow functions don't pick up thisArg\", (maps, thisArgs) => {\n\t\t\t\tfor (const thisArg of thisArgs) {\n\t\t\t\t\tfor (const map of maps) {\n\t\t\t\t\t\tmap.set(1, \"one\");\n\t\t\t\t\t\tmap.forEach(() => {\n\t\t\t\t\t\t\tassert.notEqual(\n\t\t\t\t\t\t\t\tthis,\n\t\t\t\t\t\t\t\tthisArg,\n\t\t\t\t\t\t\t\t\"Expected 'this' to be unchanged for arrow fn\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}, thisArg);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tit(\"toString\", () => {\n\t\tconst map = new MapWithExpiration<number, string>(0);\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tassert.equal(map.toString(), \"[object Map]\");\n\t});\n});\n"]}
|