From 785826a05e99c98aae872b909a833a691e4ae9fa Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 27 Jan 2022 23:48:07 +0100 Subject: test: Add tests for main window hardening MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/test-utils/src/fake.ts | 34 ++++++++++++++++++++++++++++++++++ packages/test-utils/src/index.ts | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 packages/test-utils/src/fake.ts (limited to 'packages/test-utils/src') 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 @@ +/* + * Copyright (C) 2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import type { PartialDeep } from 'type-fest'; + +/** + * Creates a fake object with some properties possibly missing. + * + * Interacting with missing properties will cause a test failure due to + * trying to access members of `undefined.` + * + * @param partialImplementation The partial fake implementation. + * @returns The same value as `partialImplementation` but with a casted type. + */ +export default function fake(partialImplementation: PartialDeep): T { + return partialImplementation as T; +} 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 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -// eslint-disable-next-line import/prefer-default-export -- More exports will be added here. export { default as each } from './each'; + +export { default as fake } from './fake'; -- cgit v1.2.3-54-g00ecf