aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts')
-rw-r--r--packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts106
1 files changed, 106 insertions, 0 deletions
diff --git a/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts
new file mode 100644
index 0000000..c7c6e22
--- /dev/null
+++ b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts
@@ -0,0 +1,106 @@
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 os from 'node:os';
22
23import Resources from '../../Resources.js';
24import getDistResources from '../getDistResources.js';
25
26const defaultDevServerURL = 'http://localhost:3000/';
27
28const [
29 thisDir,
30 preloadIndexPath,
31 preloadIndexFileURL,
32 rendererIndexFileURL,
33 rendererRootFileURL,
34] =
35 os.platform() === 'win32'
36 ? [
37 'C:\\Program Files\\sophie\\resources\\app.asar\\packages\\main\\dist',
38 'C:\\Program Files\\sophie\\resources\\app.asar\\packages\\preload\\dist\\index.cjs',
39 'file:///C:/Program Files/sophie/resources/app.asar/packages/preload/dist/index.cjs',
40 'file:///C:/Program Files/sophie/resources/app.asar/packages/renderer/dist/index.html',
41 'file:///C:/Program Files/sophie/resources/app.asar/packages/renderer/dist/',
42 ]
43 : [
44 '/opt/sophie/resources/app.asar/packages/main/dist',
45 '/opt/sophie/resources/app.asar/packages/preload/dist/index.cjs',
46 'file:///opt/sophie/resources/app.asar/packages/preload/dist/index.cjs',
47 'file:///opt/sophie/resources/app.asar/packages/renderer/dist/index.html',
48 'file:///opt/sophie/resources/app.asar/packages/renderer/dist/',
49 ];
50
51const fileURLs: [string, string] = [rendererIndexFileURL, rendererRootFileURL];
52
53describe.each([
54 ['not in dev mode', false, undefined, ...fileURLs],
55 [
56 'not in dev mode with VITE_DEV_SERVER_URL set',
57 false,
58 defaultDevServerURL,
59 ...fileURLs,
60 ],
61 ['in dev mode with no VITE_DEV_SERVER_URL', true, undefined, ...fileURLs],
62 [
63 'in dev mode with VITE_DEV_SERVER_URL set',
64 true,
65 defaultDevServerURL,
66 `${defaultDevServerURL}index.html`,
67 defaultDevServerURL,
68 ],
69])(
70 'when %s',
71 (
72 _description: string,
73 devMode: boolean,
74 devServerURL: string | undefined,
75 rendererIndexURL: string,
76 rendererRootURL: string,
77 ) => {
78 let resources: Resources;
79
80 beforeEach(() => {
81 resources = getDistResources(devMode, thisDir, devServerURL);
82 });
83
84 test('getPath returns the path to the requested resource', () => {
85 const path = resources.getPath('preload', 'index.cjs');
86 expect(path).toBe(preloadIndexPath);
87 });
88
89 test('getFileURL returns the file URL to the requested resource', () => {
90 const url = resources.getFileURL('preload', 'index.cjs');
91 expect(url).toBe(preloadIndexFileURL);
92 });
93
94 describe('getRendererURL', () => {
95 test('returns the URL to the requested resource', () => {
96 const url = resources.getRendererURL('index.html');
97 expect(url).toBe(rendererIndexURL);
98 });
99
100 test('returns the root URL', () => {
101 const url = resources.getRendererURL('/');
102 expect(url).toBe(rendererRootURL);
103 });
104 });
105 },
106);