diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-05-09 01:25:21 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-05-16 00:55:03 +0200 |
commit | cdb4247b8cb2c4c0f04a3360689340a23992be32 (patch) | |
tree | 43eca0f82018d04889a1197a16933d144b028d1b /packages | |
parent | chore(deps): bump dependencies (diff) | |
download | sophie-cdb4247b8cb2c4c0f04a3360689340a23992be32.tar.gz sophie-cdb4247b8cb2c4c0f04a3360689340a23992be32.tar.zst sophie-cdb4247b8cb2c4c0f04a3360689340a23992be32.zip |
test: prefer jest API instead of jest-each
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages')
5 files changed, 11 insertions, 41 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.spec.ts b/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.spec.ts index ae10677..dc15d68 100644 --- a/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.spec.ts +++ b/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.spec.ts | |||
@@ -21,7 +21,7 @@ | |||
21 | import { URL } from 'node:url'; | 21 | import { URL } from 'node:url'; |
22 | 22 | ||
23 | import { jest } from '@jest/globals'; | 23 | import { jest } from '@jest/globals'; |
24 | import { each, fake } from '@sophie/test-utils'; | 24 | import { fake } from '@sophie/test-utils'; |
25 | import type { | 25 | import type { |
26 | OnBeforeRequestListenerDetails, | 26 | OnBeforeRequestListenerDetails, |
27 | PermissionRequestHandlerHandlerDetails, | 27 | PermissionRequestHandlerHandlerDetails, |
@@ -100,7 +100,7 @@ it('should set permission request and before request handlers', () => { | |||
100 | expect(onBeforeRequest).toBeDefined(); | 100 | expect(onBeforeRequest).toBeDefined(); |
101 | }); | 101 | }); |
102 | 102 | ||
103 | each(permissions.map((permission) => [permission])).it( | 103 | it.each(permissions.map((permission) => [permission]))( |
104 | 'should reject %s permission requests', | 104 | 'should reject %s permission requests', |
105 | (permission: Permission) => { | 105 | (permission: Permission) => { |
106 | hardenSession(getFakeResources(false), false, fakeSession); | 106 | hardenSession(getFakeResources(false), false, fakeSession); |
@@ -114,7 +114,7 @@ each(permissions.map((permission) => [permission])).it( | |||
114 | }, | 114 | }, |
115 | ); | 115 | ); |
116 | 116 | ||
117 | each([ | 117 | it.each([ |
118 | [ | 118 | [ |
119 | false, | 119 | false, |
120 | 'GET', | 120 | 'GET', |
@@ -141,7 +141,7 @@ each([ | |||
141 | [true, 'GET', 'https://clients2.google.com/service/update2/crx/aaaa', false], | 141 | [true, 'GET', 'https://clients2.google.com/service/update2/crx/aaaa', false], |
142 | [true, 'GET', 'https://clients2.googleusercontent.com/crx/aaaa', false], | 142 | [true, 'GET', 'https://clients2.googleusercontent.com/crx/aaaa', false], |
143 | [true, 'GET', 'https://example.com', true], | 143 | [true, 'GET', 'https://example.com', true], |
144 | ]).it( | 144 | ])( |
145 | 'in dev mode: %s the request %s %s should be cancelled: %s', | 145 | 'in dev mode: %s the request %s %s should be cancelled: %s', |
146 | (devMode: boolean, method: string, url: string, cancel: boolean) => { | 146 | (devMode: boolean, method: string, url: string, cancel: boolean) => { |
147 | hardenSession(getFakeResources(devMode), devMode, fakeSession); | 147 | hardenSession(getFakeResources(devMode), devMode, fakeSession); |
diff --git a/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts index 635a6b4..8040601 100644 --- a/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts +++ b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts | |||
@@ -20,8 +20,6 @@ | |||
20 | 20 | ||
21 | import os from 'node:os'; | 21 | import os from 'node:os'; |
22 | 22 | ||
23 | import { each } from '@sophie/test-utils'; | ||
24 | |||
25 | import Resources from '../../Resources'; | 23 | import Resources from '../../Resources'; |
26 | import getDistResources from '../getDistResources'; | 24 | import getDistResources from '../getDistResources'; |
27 | 25 | ||
@@ -52,7 +50,7 @@ const [ | |||
52 | 50 | ||
53 | const fileURLs: [string, string] = [rendererIndexFileURL, rendererRootFileURL]; | 51 | const fileURLs: [string, string] = [rendererIndexFileURL, rendererRootFileURL]; |
54 | 52 | ||
55 | each([ | 53 | describe.each([ |
56 | ['not in dev mode', false, undefined, ...fileURLs], | 54 | ['not in dev mode', false, undefined, ...fileURLs], |
57 | [ | 55 | [ |
58 | 'not in dev mode with VITE_DEV_SERVER_URL set', | 56 | 'not in dev mode with VITE_DEV_SERVER_URL set', |
@@ -68,12 +66,12 @@ each([ | |||
68 | `${defaultDevServerURL}index.html`, | 66 | `${defaultDevServerURL}index.html`, |
69 | defaultDevServerURL, | 67 | defaultDevServerURL, |
70 | ], | 68 | ], |
71 | ]).describe( | 69 | ])( |
72 | 'when %s', | 70 | 'when %s', |
73 | ( | 71 | ( |
74 | _description: string, | 72 | _description: string, |
75 | devMode: boolean, | 73 | devMode: boolean, |
76 | devServerURL: string, | 74 | devServerURL: string | undefined, |
77 | rendererIndexURL: string, | 75 | rendererIndexURL: string, |
78 | rendererRootURL: string, | 76 | rendererRootURL: string, |
79 | ) => { | 77 | ) => { |
diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 8f7bb0e..4def218 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json | |||
@@ -10,9 +10,6 @@ | |||
10 | "types": "yarn g:types" | 10 | "types": "yarn g:types" |
11 | }, | 11 | }, |
12 | "dependencies": { | 12 | "dependencies": { |
13 | "@types/jest": "^27.5.0", | ||
14 | "jest": "^28.1.0", | ||
15 | "jest-each": "^28.1.0", | ||
16 | "type-fest": "^2.12.2" | 13 | "type-fest": "^2.12.2" |
17 | } | 14 | } |
18 | } | 15 | } |
diff --git a/packages/test-utils/src/each.ts b/packages/test-utils/src/each.ts deleted file mode 100644 index c5271ae..0000000 --- a/packages/test-utils/src/each.ts +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | import eachModule from 'jest-each'; | ||
22 | |||
23 | // Workaround for jest ESM loader incorrectly wrapping the import in another layer of `default`. | ||
24 | const each = | ||
25 | (eachModule as Partial<typeof import('jest-each')>).default ?? eachModule; | ||
26 | |||
27 | export default each; | ||
diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts index 1543c6e..c4db5b0 100644 --- a/packages/test-utils/src/index.ts +++ b/packages/test-utils/src/index.ts | |||
@@ -18,6 +18,8 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | export { default as each } from './each'; | 21 | /* |
22 | 22 | eslint-disable-next-line import/prefer-default-export -- | |
23 | Keep API consistent for more helpers in the future. | ||
24 | */ | ||
23 | export { default as fake } from './fake'; | 25 | export { default as fake } from './fake'; |