1
1
import path from 'node:path' ;
2
2
3
- import { describe , expect , it , vi } from 'vitest' ;
3
+ import globalDirs from 'global-dirs' ;
4
+ import { beforeEach , describe , expect , it , vi } from 'vitest' ;
4
5
5
6
import { findTemplate } from '../../src/api/init-scripts/find-template' ;
6
7
@@ -14,14 +15,20 @@ describe('findTemplate', () => {
14
15
* for the fixtures to be installed in your local `node_modules`.
15
16
*/
16
17
describe ( 'local modules' , ( ) => {
17
- it ( 'should find an @electron-forge/template based on name' , async ( ) => {
18
- await expect ( findTemplate ( 'fixture' ) ) . resolves . toEqual ( { name : 'electron-forge- template-fixture' } ) ;
18
+ it ( 'should find an @electron-forge/template based on partial name' , async ( ) => {
19
+ await expect ( findTemplate ( 'fixture' ) ) . resolves . toEqual ( expect . objectContaining ( { name : '@ electron-forge/ template-fixture' } ) ) ;
19
20
} ) ;
20
- it ( 'should find an @electron-forge/template based on name' , async ( ) => {
21
- await expect ( findTemplate ( 'fixture-two' ) ) . resolves . toEqual ( { name : 'electron-forge-template-fixture' } ) ;
21
+
22
+ it ( 'should find an @electron-forge/template based on full name' , async ( ) => {
23
+ await expect ( findTemplate ( '@electron-forge/template-fixture' ) ) . resolves . toEqual ( expect . objectContaining ( { name : '@electron-forge/template-fixture' } ) ) ;
22
24
} ) ;
23
- it ( 'should find an @electron-forge/template based on name' , async ( ) => {
24
- await expect ( findTemplate ( 'electron-forge-template-fixture-two' ) ) . resolves . toEqual ( { name : 'electron-forge-template-fixture' } ) ;
25
+ it ( 'should find an electron-forge-template based on partial name' , async ( ) => {
26
+ await expect ( findTemplate ( 'fixture-two' ) ) . resolves . toEqual ( expect . objectContaining ( { name : 'electron-forge-template-fixture' } ) ) ;
27
+ } ) ;
28
+ it ( 'should find an @electron-forge-template based on full name' , async ( ) => {
29
+ await expect ( findTemplate ( 'electron-forge-template-fixture-two' ) ) . resolves . toEqual (
30
+ expect . objectContaining ( { name : 'electron-forge-template-fixture-two' } )
31
+ ) ;
25
32
} ) ;
26
33
} ) ;
27
34
@@ -31,23 +38,22 @@ describe('findTemplate', () => {
31
38
* `node_modules` in order for the `require.resolve` custom path to work.
32
39
*/
33
40
describe ( 'global modules' , ( ) => {
34
- vi . mock ( import ( 'global-dirs' ) , async ( importOriginal ) => {
35
- const mod = await importOriginal ( ) ;
36
- return {
37
- default : {
38
- ...mod . default ,
39
- npm : {
40
- ...mod . default . npm ,
41
- packages : path . resolve ( __dirname , '..' , 'fixture' , 'global-stub' , 'node_modules' ) ,
42
- } ,
43
- } ,
44
- } ;
41
+ beforeEach ( ( ) => {
42
+ vi . spyOn ( globalDirs , 'npm' , 'get' ) . mockReturnValue ( {
43
+ binaries : '' ,
44
+ prefix : '' ,
45
+ packages : path . resolve ( __dirname , '..' , 'fixture' , 'global-stub' , 'node_modules' ) ,
46
+ } ) ;
45
47
} ) ;
46
48
it ( 'should find an @electron-forge/template based on name' , async ( ) => {
47
- await expect ( findTemplate ( 'global' ) ) . resolves . toEqual ( { name : 'electron-forge-template-fixture-global' } ) ;
49
+ await expect ( findTemplate ( 'global' ) ) . resolves . toEqual (
50
+ expect . objectContaining ( { template : { name : 'electron-forge-template-fixture-global' } , type : 'global' } )
51
+ ) ;
48
52
} ) ;
49
53
it ( 'should find an electron-forge-template based on name' , async ( ) => {
50
- await expect ( findTemplate ( 'global-two' ) ) . resolves . toEqual ( { name : 'electron-forge-template-fixture-global' } ) ;
54
+ await expect ( findTemplate ( 'global-two' ) ) . resolves . toEqual (
55
+ expect . objectContaining ( { template : { name : 'electron-forge-template-fixture-global' } , type : 'global' } )
56
+ ) ;
51
57
} ) ;
52
58
} ) ;
53
59
0 commit comments