Skip to content

Commit 6f9ebbd

Browse files
committed
attempt to fix up windows slow tests
1 parent ef30e2f commit 6f9ebbd

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

packages/template/vite-typescript/spec/ViteTypeScriptTemplate.slow.spec.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import fs from 'node:fs';
2-
import os from 'node:os';
32
import path from 'node:path';
43

54
import { PACKAGE_MANAGERS, spawnPackageManager } from '@electron-forge/core-utils';
65
import testUtils from '@electron-forge/test-utils';
76
import glob from 'fast-glob';
8-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
7+
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
98

109
// eslint-disable-next-line n/no-missing-import
1110
import { api } from '../../../api/core/dist/api';
@@ -17,14 +16,14 @@ describe('ViteTypeScriptTemplate', () => {
1716
beforeAll(async () => {
1817
await spawnPackageManager(PACKAGE_MANAGERS['yarn'], ['run', 'link:prepare']);
1918
dir = await testUtils.ensureTestDirIsNonexistent();
20-
});
2119

22-
afterAll(async () => {
23-
await spawnPackageManager(PACKAGE_MANAGERS['yarn'], ['run', 'link:remove']);
24-
if (os.platform() !== 'win32') {
25-
// Windows platform `fs.remove(dir)` logic using `npm run test:clear`.
26-
await fs.promises.rm(dir, { force: true, recursive: true });
27-
}
20+
return async () => {
21+
await spawnPackageManager(PACKAGE_MANAGERS['yarn'], ['run', 'link:remove']);
22+
if (process.platform !== 'win32') {
23+
// Windows platform `fs.remove(dir)` logic using `npm run test:clear`.
24+
await fs.promises.rm(dir, { force: true, recursive: true });
25+
}
26+
};
2827
});
2928

3029
describe('template files are copied to project', () => {
@@ -68,7 +67,7 @@ describe('ViteTypeScriptTemplate', () => {
6867
describe('package', () => {
6968
let cwd: string;
7069

71-
beforeAll(async () => {
70+
beforeEach(async () => {
7271
delete process.env.TS_NODE_PROJECT;
7372
// Vite resolves plugins via cwd
7473
cwd = process.cwd();
@@ -89,10 +88,10 @@ describe('ViteTypeScriptTemplate', () => {
8988
// spec via `api.init`. So we should re-link local forge dependencies
9089
// again.
9190
await initLink(PACKAGE_MANAGERS['yarn'], dir);
92-
});
9391

94-
afterAll(() => {
95-
process.chdir(cwd);
92+
return () => {
93+
process.chdir(cwd);
94+
};
9695
});
9796

9897
it('should pass', async () => {

packages/template/webpack-typescript/spec/WebpackTypeScript.slow.spec.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'node:path';
44
import { PACKAGE_MANAGERS, spawnPackageManager } from '@electron-forge/core-utils';
55
import testUtils from '@electron-forge/test-utils';
66
import glob from 'fast-glob';
7-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
7+
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
88

99
// eslint-disable-next-line n/no-missing-import
1010
import { api } from '../../../api/core/dist/api';
@@ -16,6 +16,15 @@ describe('WebpackTypeScriptTemplate', () => {
1616
beforeAll(async () => {
1717
await spawnPackageManager(PACKAGE_MANAGERS['yarn'], ['run', 'link:prepare']);
1818
dir = await testUtils.ensureTestDirIsNonexistent();
19+
20+
return async () => {
21+
await spawnPackageManager(PACKAGE_MANAGERS['yarn'], ['link:remove']);
22+
23+
if (process.platform !== 'win32') {
24+
// Windows platform `fs.remove(dir)` logic using `npm run test:clear`.
25+
await fs.promises.rm(dir, { force: true, recursive: true });
26+
}
27+
};
1928
});
2029

2130
it('should succeed in initializing the typescript template', async () => {
@@ -58,7 +67,7 @@ describe('WebpackTypeScriptTemplate', () => {
5867
describe('package', () => {
5968
let cwd: string;
6069

61-
beforeAll(async () => {
70+
beforeEach(async () => {
6271
delete process.env.TS_NODE_PROJECT;
6372
// Webpack resolves plugins via cwd
6473
cwd = process.cwd();
@@ -79,10 +88,10 @@ describe('WebpackTypeScriptTemplate', () => {
7988
// spec via `api.init`. So we should re-link local forge dependencies
8089
// again.
8190
await initLink(PACKAGE_MANAGERS['yarn'], dir);
82-
});
8391

84-
afterAll(() => {
85-
process.chdir(cwd);
92+
return () => {
93+
process.chdir(cwd);
94+
};
8695
});
8796

8897
it('should pass', async () => {
@@ -92,9 +101,4 @@ describe('WebpackTypeScriptTemplate', () => {
92101
});
93102
});
94103
});
95-
96-
afterAll(async () => {
97-
await spawnPackageManager(PACKAGE_MANAGERS['yarn'], ['link:remove']);
98-
await fs.promises.rm(dir, { recursive: true, force: true });
99-
});
100104
});

0 commit comments

Comments
 (0)