1
1
import fs from 'node:fs' ;
2
- import os from 'node:os' ;
3
2
import path from 'node:path' ;
4
3
5
4
import { PACKAGE_MANAGERS , spawnPackageManager } from '@electron-forge/core-utils' ;
6
5
import testUtils from '@electron-forge/test-utils' ;
7
6
import glob from 'fast-glob' ;
8
- import { afterAll , beforeAll , describe , expect , it } from 'vitest' ;
7
+ import { beforeAll , beforeEach , describe , expect , it } from 'vitest' ;
9
8
10
9
// eslint-disable-next-line n/no-missing-import
11
10
import { api } from '../../../api/core/dist/api' ;
@@ -17,14 +16,14 @@ describe('ViteTypeScriptTemplate', () => {
17
16
beforeAll ( async ( ) => {
18
17
await spawnPackageManager ( PACKAGE_MANAGERS [ 'yarn' ] , [ 'run' , 'link:prepare' ] ) ;
19
18
dir = await testUtils . ensureTestDirIsNonexistent ( ) ;
20
- } ) ;
21
19
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
+ } ;
28
27
} ) ;
29
28
30
29
describe ( 'template files are copied to project' , ( ) => {
@@ -68,7 +67,7 @@ describe('ViteTypeScriptTemplate', () => {
68
67
describe ( 'package' , ( ) => {
69
68
let cwd : string ;
70
69
71
- beforeAll ( async ( ) => {
70
+ beforeEach ( async ( ) => {
72
71
delete process . env . TS_NODE_PROJECT ;
73
72
// Vite resolves plugins via cwd
74
73
cwd = process . cwd ( ) ;
@@ -89,10 +88,10 @@ describe('ViteTypeScriptTemplate', () => {
89
88
// spec via `api.init`. So we should re-link local forge dependencies
90
89
// again.
91
90
await initLink ( PACKAGE_MANAGERS [ 'yarn' ] , dir ) ;
92
- } ) ;
93
91
94
- afterAll ( ( ) => {
95
- process . chdir ( cwd ) ;
92
+ return ( ) => {
93
+ process . chdir ( cwd ) ;
94
+ } ;
96
95
} ) ;
97
96
98
97
it ( 'should pass' , async ( ) => {
0 commit comments