@@ -4,7 +4,7 @@ import * as core from '@form8ion/core';
4
4
import * as huskyPlugin from '@form8ion/husky' ;
5
5
import * as commitConventionPlugin from '@form8ion/commit-convention' ;
6
6
7
- import { afterEach , describe , expect , it , vi } from 'vitest' ;
7
+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
8
8
import any from '@travi/any' ;
9
9
import { when } from 'jest-when' ;
10
10
@@ -14,14 +14,14 @@ import * as npmConfigPlugin from '../npm-config/index.js';
14
14
import * as enginesEnhancer from './enhancers/engines.js' ;
15
15
import * as projectTypes from '../project-type/index.js' ;
16
16
import * as dialects from '../dialects/index.js' ;
17
- import * as packageLifter from '../package/lifter.js' ;
17
+ import liftPackage from '../package/lifter.js' ;
18
18
import * as packageManagers from '../package-managers/index.js' ;
19
19
import { determineCurrent as packageManagerResolver } from '../package-managers/index.js' ;
20
20
import lift from './lift.js' ;
21
21
22
22
vi . mock ( 'node:fs' ) ;
23
23
vi . mock ( '@form8ion/core' ) ;
24
- vi . mock ( '../package/lifter' ) ;
24
+ vi . mock ( '../package/lifter.js ' ) ;
25
25
vi . mock ( '../package-managers/index.js' ) ;
26
26
27
27
describe ( 'lift' , ( ) => {
@@ -35,42 +35,63 @@ describe('lift', () => {
35
35
const enhancerResults = any . simpleObject ( ) ;
36
36
const vcsDetails = any . simpleObject ( ) ;
37
37
const results = { ...any . simpleObject ( ) , scripts, tags, dependencies, devDependencies, packageManager : manager } ;
38
+ const pathWithinParent = any . string ( ) ;
39
+ const packageDetails = any . simpleObject ( ) ;
40
+ const internalEnhancers = {
41
+ huskyPlugin,
42
+ enginesEnhancer,
43
+ coveragePlugin,
44
+ commitConventionPlugin,
45
+ dialects,
46
+ codeStylePlugin,
47
+ npmConfigPlugin,
48
+ projectTypes,
49
+ packageManagers
50
+ } ;
38
51
39
- afterEach ( ( ) => {
40
- vi . clearAllMocks ( ) ;
41
- } ) ;
42
-
43
- it ( 'should lift results that are specific to js projects' , async ( ) => {
44
- const packageDetails = any . simpleObject ( ) ;
45
- const pathWithinParent = any . string ( ) ;
52
+ beforeEach ( ( ) => {
46
53
when ( packageManagerResolver )
47
54
. calledWith ( { projectRoot, packageManager : manager } )
48
55
. mockResolvedValue ( packageManager ) ;
49
56
when ( fs . readFile )
50
57
. calledWith ( `${ projectRoot } /package.json` , 'utf8' )
51
58
. mockResolvedValue ( JSON . stringify ( packageDetails ) ) ;
52
- when ( core . applyEnhancers ) . calledWith ( {
53
- results,
54
- enhancers : [
55
- huskyPlugin ,
56
- enginesEnhancer ,
57
- coveragePlugin ,
58
- commitConventionPlugin ,
59
- dialects ,
60
- codeStylePlugin ,
61
- npmConfigPlugin ,
62
- projectTypes ,
63
- packageManagers
64
- ] ,
65
- options : { projectRoot, packageManager, vcs : vcsDetails , packageDetails}
66
- } ) . mockResolvedValue ( enhancerResults ) ;
59
+ } ) ;
60
+
61
+ afterEach ( ( ) => {
62
+ vi . clearAllMocks ( ) ;
63
+ } ) ;
64
+
65
+ it ( 'should lift results that are specific to js projects' , async ( ) => {
66
+ when ( core . applyEnhancers )
67
+ . calledWith ( {
68
+ results,
69
+ enhancers : internalEnhancers ,
70
+ options : { projectRoot, packageManager, vcs : vcsDetails , packageDetails}
71
+ } )
72
+ . mockResolvedValue ( enhancerResults ) ;
67
73
68
74
const liftResults = await lift ( { projectRoot, vcs : vcsDetails , results, pathWithinParent} ) ;
69
75
70
76
expect ( liftResults ) . toEqual ( enhancerResults ) ;
71
- expect ( packageLifter . default ) . toHaveBeenCalledWith ( deepmerge . all ( [
77
+ expect ( liftPackage ) . toHaveBeenCalledWith ( deepmerge . all ( [
72
78
{ projectRoot, scripts, tags, dependencies, devDependencies, packageManager, vcs : vcsDetails , pathWithinParent} ,
73
79
enhancerResults
74
80
] ) ) ;
75
81
} ) ;
82
+
83
+ it ( 'should apply provided enhancers' , async ( ) => {
84
+ const enhancers = any . simpleObject ( ) ;
85
+ when ( core . applyEnhancers )
86
+ . calledWith ( {
87
+ results,
88
+ enhancers : { ...enhancers , ...internalEnhancers } ,
89
+ options : { projectRoot, packageManager, vcs : vcsDetails , packageDetails}
90
+ } )
91
+ . mockResolvedValue ( enhancerResults ) ;
92
+
93
+ const liftResults = await lift ( { projectRoot, vcs : vcsDetails , results, pathWithinParent, enhancers} ) ;
94
+
95
+ expect ( liftResults ) . toEqual ( enhancerResults ) ;
96
+ } ) ;
76
97
} ) ;
0 commit comments