Repository: ROpdebee/mb-userscripts
Pull request #713 (2023-12-01 03:59:59)

build(deps): update dependency fake-indexeddb to v5
[![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [fake-indexeddb](https://togithub.com/dumbmatter/fakeIndexedDB) | [`4.0.2` -> `5.0.1`](https://renovatebot.com/diffs/npm/fake-indexeddb/4.0.2/5.0.1) | [![age](https://developer.mend.io/api/mc/badges/age/npm/fake-indexeddb/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/fake-indexeddb/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/fake-indexeddb/4.0.2/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/fake-indexeddb/4.0.2/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>dumbmatter/fakeIndexedDB (fake-indexeddb)</summary>

### [`v5.0.1`](https://togithub.com/dumbmatter/fakeIndexedDB/blob/HEAD/CHANGELOG.md#501-2023-10-25)

[Compare Source](https://togithub.com/dumbmatter/fakeIndexedDB/compare/v5.0.0...v5.0.1)

-   [#&#8203;89](https://togithub.com/dumbmatter/fakeIndexedDB/issues/89) - Fixed bug where ArrayBuffer views were not being correctly handled when used as keys.

-   [#&#8203;88](https://togithub.com/dumbmatter/fakeIndexedDB/issues/88) - Added explanation to README.md about how to use fake-indexeddb v5+ with jsdom, since a `structuredClone` polyfill is not included anymore.

### [`v5.0.0`](https://togithub.com/dumbmatter/fakeIndexedDB/blob/HEAD/CHANGELOG.md#500-2023-10-13)

[Compare Source](https://togithub.com/dumbmatter/fakeIndexedDB/compare/v4.0.2...v5.0.0)

-   Dropped support for Node.js 16, which allows me to get rid of the `structuredClone` polyfill, which reduces the package size by roughly 50%.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on the first day of the month" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/ROpdebee/mb-userscripts).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->


renovate[bot]: ### Edited/Blocked Notification

Renovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR.

You can manually request rebase by checking the rebase/retry box above.

 ⚠ **Warning**: custom changes will be lost.

Patch:
diff --git a/jest.config.cjs b/jest.config.cjs
index 93a52c33..f630184d 100644
--- a/jest.config.cjs
+++ b/jest.config.cjs
@@ -17,7 +17,7 @@ const esModules = [
 
 /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
 module.exports = {
-    testEnvironment: 'setup-polly-jest/jest-environment-jsdom',
+    testEnvironment: './tests/unit/utils/extended-jsdom-env.ts',
     moduleNameMapper: {
         '^@lib/(.*)$': '<rootDir>/src/lib/$1',
         '^@test-utils/(.*)$': '<rootDir>/tests/unit/utils/$1',
@@ -26,7 +26,6 @@ module.exports = {
     setupFilesAfterEnv: [
         'jest-extended/all',
         './tests/unit/utils/setup-gm-mocks.ts',
-        './tests/unit/utils/fix-jsdom-env.ts',
     ],
     collectCoverageFrom: [
         'src/**/*.{js,ts}',
diff --git a/package-lock.json b/package-lock.json
index a85c59d7..305d00a0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -76,7 +76,7 @@
         "eslint-plugin-switch-case": "1.1.2",
         "eslint-plugin-unicorn": "49.0.0",
         "eslint-plugin-xss": "0.1.12",
-        "fake-indexeddb": "4.0.2",
+        "fake-indexeddb": "5.0.1",
         "glob": "10.3.10",
         "jest": "29.7.0",
         "jest-environment-jsdom": "29.7.0",
@@ -5332,15 +5332,6 @@
         "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
       }
     },
-    "node_modules/base64-arraybuffer-es6": {
-      "version": "0.7.0",
-      "resolved": "https://registry.npmjs.org/base64-arraybuffer-es6/-/base64-arraybuffer-es6-0.7.0.tgz",
-      "integrity": "sha512-ESyU/U1CFZDJUdr+neHRhNozeCv72Y7Vm0m1DCbjX3KBjT6eYocvAJlSk6+8+HkVwXlT1FNxhGW6q3UKAlCvvw==",
-      "dev": true,
-      "engines": {
-        "node": ">=6.0.0"
-      }
-    },
     "node_modules/binary-extensions": {
       "version": "2.2.0",
       "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
@@ -7639,12 +7630,12 @@
       }
     },
     "node_modules/fake-indexeddb": {
-      "version": "4.0.2",
-      "resolved": "https://registry.npmjs.org/fake-indexeddb/-/fake-indexeddb-4.0.2.tgz",
-      "integrity": "sha512-SdTwEhnakbgazc7W3WUXOJfGmhH0YfG4d+dRPOFoYDRTL6U5t8tvrmkf2W/C3W1jk2ylV7Wrnj44RASqpX/lEw==",
+      "version": "5.0.1",
+      "resolved": "https://registry.npmjs.org/fake-indexeddb/-/fake-indexeddb-5.0.1.tgz",
+      "integrity": "sha512-vxybH29Owtc6khV/Usy47B1g+eKwyhFiX8nwpCC4td320jvwrKQDH6vNtcJZgUzVxmfsSIlHzLKQzT76JMCO7A==",
       "dev": true,
-      "dependencies": {
-        "realistic-structured-clone": "^3.0.0"
+      "engines": {
+        "node": ">=18"
       }
     },
     "node_modules/fast-deep-equal": {
@@ -13441,32 +13432,6 @@
         "node": ">=8.10.0"
       }
     },
-    "node_modules/realistic-structured-clone": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/realistic-structured-clone/-/realistic-structured-clone-3.0.0.tgz",
-      "integrity": "sha512-rOjh4nuWkAqf9PWu6JVpOWD4ndI+JHfgiZeMmujYcPi+fvILUu7g6l26TC1K5aBIp34nV+jE1cDO75EKOfHC5Q==",
-      "dev": true,
-      "dependencies": {
-        "domexception": "^1.0.1",
-        "typeson": "^6.1.0",
-        "typeson-registry": "^1.0.0-alpha.20"
-      }
-    },
-    "node_modules/realistic-structured-clone/node_modules/domexception": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.1.tgz",
-      "integrity": "sha512-raigMkn7CJNNo6Ihro1fzG7wr3fHuYVytzquZKX5n0yizGsTcYgzdIUwj1X9pK0VvjeihV+XiclP+DjwbsSKug==",
-      "dev": true,
-      "dependencies": {
-        "webidl-conversions": "^4.0.2"
-      }
-    },
-    "node_modules/realistic-structured-clone/node_modules/webidl-conversions": {
-      "version": "4.0.2",
-      "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",
-      "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==",
-      "dev": true
-    },
     "node_modules/regenerate": {
       "version": "1.4.2",
       "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz",
@@ -14917,64 +14882,6 @@
         "node": ">=14.17"
       }
     },
-    "node_modules/typeson": {
-      "version": "6.1.0",
-      "resolved": "https://registry.npmjs.org/typeson/-/typeson-6.1.0.tgz",
-      "integrity": "sha512-6FTtyGr8ldU0pfbvW/eOZrEtEkczHRUtduBnA90Jh9kMPCiFNnXIon3vF41N0S4tV1HHQt4Hk1j4srpESziCaA==",
-      "dev": true,
-      "engines": {
-        "node": ">=0.1.14"
-      }
-    },
-    "node_modules/typeson-registry": {
-      "version": "1.0.0-alpha.39",
-      "resolved": "https://registry.npmjs.org/typeson-registry/-/typeson-registry-1.0.0-alpha.39.tgz",
-      "integrity": "sha512-NeGDEquhw+yfwNhguLPcZ9Oj0fzbADiX4R0WxvoY8nGhy98IbzQy1sezjoEFWOywOboj/DWehI+/aUlRVrJnnw==",
-      "dev": true,
-      "dependencies": {
-        "base64-arraybuffer-es6": "^0.7.0",
-        "typeson": "^6.0.0",
-        "whatwg-url": "^8.4.0"
-      },
-      "engines": {
-        "node": ">=10.0.0"
-      }
-    },
-    "node_modules/typeson-registry/node_modules/tr46": {
-      "version": "2.1.0",
-      "resolved": "https://registry.npmjs.org/tr46/-/tr46-2.1.0.tgz",
-      "integrity": "sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==",
-      "dev": true,
-      "dependencies": {
-        "punycode": "^2.1.1"
-      },
-      "engines": {
-        "node": ">=8"
-      }
-    },
-    "node_modules/typeson-registry/node_modules/webidl-conversions": {
-      "version": "6.1.0",
-      "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz",
-      "integrity": "sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==",
-      "dev": true,
-      "engines": {
-        "node": ">=10.4"
-      }
-    },
-    "node_modules/typeson-registry/node_modules/whatwg-url": {
-      "version": "8.7.0",
-      "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.7.0.tgz",
-      "integrity": "sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==",
-      "dev": true,
-      "dependencies": {
-        "lodash": "^4.7.0",
-        "tr46": "^2.1.0",
-        "webidl-conversions": "^6.1.0"
-      },
-      "engines": {
-        "node": ">=10"
-      }
-    },
     "node_modules/undici-types": {
       "version": "5.26.5",
       "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
diff --git a/package.json b/package.json
index 814ef4e3..f8dc8922 100644
--- a/package.json
+++ b/package.json
@@ -84,7 +84,7 @@
     "eslint-plugin-switch-case": "1.1.2",
     "eslint-plugin-unicorn": "49.0.0",
     "eslint-plugin-xss": "0.1.12",
-    "fake-indexeddb": "4.0.2",
+    "fake-indexeddb": "5.0.1",
     "glob": "10.3.10",
     "jest": "29.7.0",
     "jest-environment-jsdom": "29.7.0",


Test patch:
diff --git a/tests/types/setup-polly-jest.d.ts b/tests/types/setup-polly-jest.d.ts
new file mode 100644
index 00000000..339049a1
--- /dev/null
+++ b/tests/types/setup-polly-jest.d.ts
@@ -0,0 +1,4 @@
+declare module 'setup-polly-jest/jest-environment-jsdom' {
+    import JestJSDOMEnvironment from 'jest-environment-jsdom';
+    export default class JSDOMEnvironment extends JestJSDOMEnvironment {}
+}
diff --git a/tests/unit/mb_caa_dimensions/InfoCache.test.ts b/tests/unit/mb_caa_dimensions/InfoCache.test.ts
index 46a50cfc..f28b5463 100644
--- a/tests/unit/mb_caa_dimensions/InfoCache.test.ts
+++ b/tests/unit/mb_caa_dimensions/InfoCache.test.ts
@@ -1,3 +1,4 @@
+/* eslint-disable jest/prefer-strict-equal -- Need to use toEqual because fake-indexeddb uses structuredClone, see https://github.com/jestjs/jest/issues/14011 */
 import 'fake-indexeddb/auto';
 
 import type { IDBPDatabase, OpenDBCallbacks } from 'idb';
@@ -84,7 +85,7 @@ describe('indexedDB-backed info cache', () => {
             mockDateNow.mockReturnValueOnce(123);
             await cache.putDimensions('test', dummyDimensions);
 
-            await expect(cache.getDimensions('test')).resolves.toStrictEqual({
+            await expect(cache.getDimensions('test')).resolves.toEqual({
                 ...dummyDimensions,
                 addedDatetime: 123,
             });
@@ -114,7 +115,7 @@ describe('indexedDB-backed info cache', () => {
             mockDateNow.mockReturnValueOnce(123);
             await cache.putFileInfo('test', dummyFileInfo);
 
-            await expect(cache.getFileInfo('test')).resolves.toStrictEqual({
+            await expect(cache.getFileInfo('test')).resolves.toEqual({
                 ...dummyFileInfo,
                 addedDatetime: 123,
             });
@@ -201,19 +202,19 @@ describe('database migrations', () => {
         it('should retain all old entries', async () => {
             const cache = await createCache();
 
-            await expect(cache.getDimensions('test')).resolves.toStrictEqual({
+            await expect(cache.getDimensions('test')).resolves.toEqual({
                 ...dummyDimensions,
                 addedDatetime: 123,
             });
-            await expect(cache.getDimensions('test2')).resolves.toStrictEqual({
+            await expect(cache.getDimensions('test2')).resolves.toEqual({
                 ...dummyDimensions,
                 addedDatetime: 456,
             });
-            await expect(cache.getFileInfo('test')).resolves.toStrictEqual({
+            await expect(cache.getFileInfo('test')).resolves.toEqual({
                 ...dummyFileInfo,
                 addedDatetime: 123,
             });
-            await expect(cache.getFileInfo('test2')).resolves.toStrictEqual({
+            await expect(cache.getFileInfo('test2')).resolves.toEqual({
                 ...dummyFileInfo,
                 addedDatetime: 456,
             });
@@ -225,11 +226,11 @@ describe('database migrations', () => {
             // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
             const db: IDBPDatabase = cache['db'];
 
-            await expect(db.getFromIndex('dimensionsStore', 'addedDatetimeIdx', IDBKeyRange.upperBound(200))).resolves.toStrictEqual({
+            await expect(db.getFromIndex('dimensionsStore', 'addedDatetimeIdx', IDBKeyRange.upperBound(200))).resolves.toEqual({
                 ...dummyDimensions,
                 addedDatetime: 123,
             });
-            await expect(db.getFromIndex('fileInfoStore', 'addedDatetimeIdx', IDBKeyRange.upperBound(200))).resolves.toStrictEqual({
+            await expect(db.getFromIndex('fileInfoStore', 'addedDatetimeIdx', IDBKeyRange.upperBound(200))).resolves.toEqual({
                 ...dummyFileInfo,
                 addedDatetime: 123,
             });
diff --git a/tests/unit/utils/extended-jsdom-env.ts b/tests/unit/utils/extended-jsdom-env.ts
new file mode 100644
index 00000000..9ed2e2fc
--- /dev/null
+++ b/tests/unit/utils/extended-jsdom-env.ts
@@ -0,0 +1,36 @@
+import { webcrypto } from 'node:crypto';
+import { TextDecoder, TextEncoder } from 'node:util';
+
+import JSDOMEnvironment from 'setup-polly-jest/jest-environment-jsdom';
+
+export default class ExtendedJSDOMEnvironment extends JSDOMEnvironment {
+    public constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
+        super(...args);
+
+        this.patchTextEncoder();
+        this.patchCrypto();
+        this.patchStructuredClone();
+    }
+
+    private patchTextEncoder(): void {
+        // JSDom removes TextEncoder and TextDecoder from the node global env, restore them
+        // @ts-expect-error: Some incompatibilities between node and web.
+        this.global.TextDecoder = TextDecoder;
+        this.global.TextEncoder = TextEncoder;
+    }
+
+    private patchCrypto(): void {
+        // Crypto has been patched by JSDOM, so needs to be restored too.
+
+        // Reset ArrayBuffer to use Node's version over the JSDOM mock. The
+        // crypto APIs expect a real ArrayBuffer instead.
+        this.global.ArrayBuffer = ArrayBuffer;
+        // @ts-expect-error: Some incompatibilities between node and web.
+        this.global.crypto.subtle = webcrypto.subtle;
+    }
+
+    private patchStructuredClone(): void {
+        // JSDOM also removes structuredClone, which is needed by fake-indexeddb.
+        this.global.structuredClone = structuredClone;
+    }
+}
diff --git a/tests/unit/utils/fix-jsdom-env.ts b/tests/unit/utils/fix-jsdom-env.ts
deleted file mode 100644
index 0ed88f84..00000000
--- a/tests/unit/utils/fix-jsdom-env.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-// JSDom removes TextEncoder and TextDecoder from the node global env, restore them
-import { TextDecoder, TextEncoder } from 'node:util';
-// @ts-expect-error: Some incompatibilities between node and web.
-global.TextDecoder = TextDecoder;
-global.TextEncoder = TextEncoder;
-
-// Same for crypto
-import { webcrypto } from 'node:crypto';
-const cryptoDigest = webcrypto.subtle.digest.bind(webcrypto.subtle);
-// @ts-expect-error: Some incompatibilities between node and web.
-crypto.subtle = webcrypto.subtle;
-crypto.subtle.digest = (algorithm, data): Promise<ArrayBuffer> => {
-    if (data instanceof ArrayBuffer) {
-        // Need to copy the given data, otherwise node's webcrypto digest function
-        // throws an error stating that the data isn't an ArrayBuffer. This
-        // probably has something to do with the FileReader that's polyfilled by
-        // jest, used in lib/util/blob.
-        data = new Uint8Array(data);
-    }
-    return cryptoDigest(algorithm, data);
-};
diff --git a/tests/unit/utils/tsconfig.json b/tests/unit/utils/tsconfig.json
index 97aa9498..2bb5a70d 100644
--- a/tests/unit/utils/tsconfig.json
+++ b/tests/unit/utils/tsconfig.json
@@ -4,6 +4,9 @@
     "references": [
         { "path": "../../../src/lib" },
     ],
+    "files": [
+        "../../types/setup-polly-jest.d.ts"
+    ],
     "compilerOptions": {
         "skipLibCheck": true
     }