|
1 | 1 | import fs from 'node:fs'; |
2 | 2 | import path from 'node:path'; |
3 | 3 |
|
| 4 | +import { |
| 5 | + PACKAGE_MANAGERS, |
| 6 | + spawnPackageManager, |
| 7 | +} from '@electron-forge/core-utils'; |
| 8 | +import { ensureTestDirIsNonexistent } from '@electron-forge/test-utils'; |
4 | 9 | import { CrossSpawnOptions, spawn } from '@malept/cross-spawn-promise'; |
5 | 10 | import { afterAll, beforeAll, describe, expect, it } from 'vitest'; |
6 | 11 |
|
7 | 12 | import { getElectronExecutablePath } from '../src/util/getElectronExecutablePath'; |
8 | 13 |
|
9 | 14 | describe('FusesPlugin', () => { |
10 | | - const appPath = path.join(__dirname, 'fixture', 'app'); |
11 | | - |
12 | | - const spawnOptions: CrossSpawnOptions = { |
13 | | - cwd: appPath, |
14 | | - shell: true, |
15 | | - }; |
| 15 | + const fixtureDir = path.join(__dirname, 'fixture', 'app'); |
| 16 | + const forgeVersion = JSON.parse( |
| 17 | + fs.readFileSync( |
| 18 | + path.resolve(__dirname, '..', '..', '..', '..', 'lerna.json'), |
| 19 | + 'utf-8', |
| 20 | + ), |
| 21 | + ).version; |
| 22 | + let appPath: string; |
16 | 23 |
|
17 | 24 | const packageJSON = JSON.parse( |
18 | | - fs.readFileSync(path.join(appPath, 'package.json.tmpl'), { |
19 | | - encoding: 'utf-8', |
20 | | - }), |
| 25 | + fs.readFileSync(path.join(fixtureDir, 'package.json.tmpl'), 'utf-8'), |
21 | 26 | ); |
22 | 27 |
|
23 | 28 | const { name: appName } = packageJSON; |
24 | 29 |
|
25 | | - const outDir = path.join(appPath, 'out', 'fuses-test-app'); |
26 | | - |
27 | 30 | beforeAll(async () => { |
28 | 31 | delete process.env.TS_NODE_PROJECT; |
29 | | - await fs.promises.copyFile( |
| 32 | + appPath = await ensureTestDirIsNonexistent(); |
| 33 | + await fs.promises.cp(fixtureDir, appPath, { recursive: true }); |
| 34 | + const packageJSONTemplate = await fs.promises.readFile( |
30 | 35 | path.join(appPath, 'package.json.tmpl'), |
| 36 | + 'utf-8', |
| 37 | + ); |
| 38 | + await fs.promises.writeFile( |
31 | 39 | path.join(appPath, 'package.json'), |
| 40 | + packageJSONTemplate.replace(/ELECTRON_FORGE\/VERSION/g, forgeVersion), |
32 | 41 | ); |
| 42 | + await fs.promises.rm(path.join(appPath, 'package.json.tmpl')); |
| 43 | + await spawnPackageManager(PACKAGE_MANAGERS.yarn, ['install'], { |
| 44 | + cwd: appPath, |
| 45 | + }); |
33 | 46 | }); |
34 | 47 |
|
35 | 48 | afterAll(async () => { |
36 | | - await fs.promises.rm(path.resolve(outDir, '../'), { |
37 | | - recursive: true, |
38 | | - force: true, |
39 | | - }); |
40 | | - |
41 | | - await fs.promises.rm(path.join(appPath, 'package.json')); |
| 49 | + await fs.promises.rm(appPath, { recursive: true, force: true }); |
42 | 50 | }); |
43 | 51 |
|
44 | 52 | it('should flip Fuses', async () => { |
| 53 | + const spawnOptions: CrossSpawnOptions = { |
| 54 | + cwd: appPath, |
| 55 | + shell: true, |
| 56 | + }; |
45 | 57 | await spawn('yarn', ['package'], spawnOptions); |
46 | 58 |
|
| 59 | + const outDir = path.join(appPath, 'out', appName); |
47 | 60 | const electronExecutablePath = getElectronExecutablePath({ |
48 | 61 | appName, |
49 | 62 | basePath: path.join( |
|
0 commit comments