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