aboutsummaryrefslogtreecommitdiffstats
path: root/packages/test-utils
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-01-27 23:48:07 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-08 21:43:18 +0100
commit785826a05e99c98aae872b909a833a691e4ae9fa (patch)
treed3c0099516852f312973967c621ac82f4d6b1d41 /packages/test-utils
parentbuild: Add test-utils package (diff)
downloadsophie-785826a05e99c98aae872b909a833a691e4ae9fa.tar.gz
sophie-785826a05e99c98aae872b909a833a691e4ae9fa.tar.zst
sophie-785826a05e99c98aae872b909a833a691e4ae9fa.zip
test: Add tests for main window hardening
We try to stub/mock the Electron API to make sure the test environment is as close to the runtime environment for this security critical code. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/test-utils')
-rw-r--r--packages/test-utils/package.json3
-rw-r--r--packages/test-utils/src/fake.ts34
-rw-r--r--packages/test-utils/src/index.ts3
3 files changed, 38 insertions, 2 deletions
diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json
index 9270af2..2f0610a 100644
--- a/packages/test-utils/package.json
+++ b/packages/test-utils/package.json
@@ -12,6 +12,7 @@
12 "dependencies": { 12 "dependencies": {
13 "@types/jest": "^27.4.0", 13 "@types/jest": "^27.4.0",
14 "jest": "^27.4.7", 14 "jest": "^27.4.7",
15 "jest-each": "^27.4.6" 15 "jest-each": "^27.4.6",
16 "type-fest": "^2.11.0"
16 } 17 }
17} 18}
diff --git a/packages/test-utils/src/fake.ts b/packages/test-utils/src/fake.ts
new file mode 100644
index 0000000..57cfa88
--- /dev/null
+++ b/packages/test-utils/src/fake.ts
@@ -0,0 +1,34 @@
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
21import type { PartialDeep } from 'type-fest';
22
23/**
24 * Creates a fake object with some properties possibly missing.
25 *
26 * Interacting with missing properties will cause a test failure due to
27 * trying to access members of `undefined.`
28 *
29 * @param partialImplementation The partial fake implementation.
30 * @returns The same value as `partialImplementation` but with a casted type.
31 */
32export default function fake<T>(partialImplementation: PartialDeep<T>): T {
33 return partialImplementation as T;
34}
diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts
index 5de84f1..1543c6e 100644
--- a/packages/test-utils/src/index.ts
+++ b/packages/test-utils/src/index.ts
@@ -18,5 +18,6 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21// eslint-disable-next-line import/prefer-default-export -- More exports will be added here.
22export { default as each } from './each'; 21export { default as each } from './each';
22
23export { default as fake } from './fake';