1- import { describe , it , expect , afterEach , vi } from 'vitest' ;
1+ import { describe , expect , it , vi } from 'vitest' ;
22import any from '@travi/any' ;
33import { when } from 'jest-when' ;
44
@@ -9,60 +9,44 @@ vi.mock('../steps/index.js');
99
1010describe ( 'job lifter' , ( ) => {
1111 const jobName = any . word ( ) ;
12- const updatedSupportedNodeVersions = any . listOf ( any . simpleObject ) ;
13-
14- afterEach ( ( ) => {
15- vi . clearAllMocks ( ) ;
16- } ) ;
12+ const jobSteps = any . listOf ( any . simpleObject ) ;
13+ const liftedSteps = any . listOf ( any . simpleObject ) ;
14+ const enhancerOptions = any . simpleObject ( ) ;
15+ const nonApplicableEnhancerFactory = ( ) => ( { test : ( ) => false } ) ;
1716
1817 it ( 'should lift the steps of a job' , ( ) => {
1918 const jobWithoutSteps = any . simpleObject ( ) ;
20- const jobSteps = any . listOf ( any . simpleObject ) ;
21- const liftedSteps = any . listOf ( any . simpleObject ) ;
2219 when ( liftSteps ) . calledWith ( jobSteps ) . mockReturnValue ( liftedSteps ) ;
2320
24- expect ( liftJob ( [ jobName , { ...jobWithoutSteps , steps : jobSteps } ] ) )
21+ expect ( liftJob ( [ jobName , { ...jobWithoutSteps , steps : jobSteps } ] , any . listOf ( nonApplicableEnhancerFactory ) ) )
2522 . toEqual ( [ jobName , { ...jobWithoutSteps , steps : liftedSteps } ] ) ;
2623 } ) ;
2724
2825 it ( 'should lift a job that calls a reusable workflow' , ( ) => {
2926 const jobThatCallsReusableWorkflow = { ...any . simpleObject ( ) , uses : any . string ( ) } ;
30- const liftedJob = liftJob ( [ jobName , jobThatCallsReusableWorkflow ] ) ;
27+ const liftedJob = liftJob ( [ jobName , jobThatCallsReusableWorkflow ] , any . listOf ( nonApplicableEnhancerFactory ) ) ;
3128
3229 expect ( liftSteps ) . not . toHaveBeenCalled ( ) ;
3330 expect ( liftedJob ) . toEqual ( [ jobName , jobThatCallsReusableWorkflow ] ) ;
3431 } ) ;
3532
36- it ( 'should replace the node versions in an existing matrix job' , ( ) => {
37- const [ , updatedJobDefinition ] = liftJob (
38- [ jobName , { ...any . simpleObject ( ) , strategy : { matrix : { node : any . listOf ( any . integer ) } } } ] ,
39- updatedSupportedNodeVersions
40- ) ;
41-
42- expect ( updatedJobDefinition . strategy . matrix . node ) . toEqual ( updatedSupportedNodeVersions ) ;
43- } ) ;
44-
45- it ( 'should not add a test strategy to a job that does not already have one defined' , ( ) => {
46- const [ , updatedJobDefinition ] = liftJob ( [ jobName , any . simpleObject ( ) ] , updatedSupportedNodeVersions ) ;
47-
48- expect ( updatedJobDefinition . strategy ) . toBe ( undefined ) ;
49- } ) ;
50-
51- it ( 'should not add a test matrix to a job that does not already have one defined' , ( ) => {
52- const [ , updatedJobDefinition ] = liftJob (
53- [ jobName , { ...any . simpleObject ( ) , strategy : any . simpleObject ( ) } ] ,
54- updatedSupportedNodeVersions
55- ) ;
56-
57- expect ( updatedJobDefinition . strategy . matrix ) . toBe ( undefined ) ;
58- } ) ;
33+ it ( 'should apply a related enhancer' , ( ) => {
34+ const jobLifter = vi . fn ( ) ;
35+ const applicableEnhancer = { test : ( ) => true , lift : jobLifter } ;
36+ const enhancers = [
37+ ...any . listOf ( nonApplicableEnhancerFactory ) ,
38+ applicableEnhancer ,
39+ ...any . listOf ( nonApplicableEnhancerFactory )
40+ ] ;
41+ const existingJobDetails = { ...any . simpleObject ( ) , steps : jobSteps } ;
42+ const liftedJobDetails = any . simpleObject ( ) ;
43+ when ( liftSteps ) . calledWith ( jobSteps ) . mockReturnValue ( liftedSteps ) ;
44+ when ( jobLifter )
45+ . calledWith ( { ...existingJobDetails , steps : liftedSteps } , enhancerOptions )
46+ . mockReturnValue ( liftedJobDetails ) ;
5947
60- it ( 'should not add a list of supported node versions to a job that does not already have one defined' , ( ) => {
61- const [ , updatedJobDefinition ] = liftJob (
62- [ jobName , { ...any . simpleObject ( ) , strategy : { ...any . simpleObject ( ) , matrix : any . simpleObject ( ) } } ] ,
63- updatedSupportedNodeVersions
64- ) ;
48+ const [ , updatedJobDefinition ] = liftJob ( [ 'verify-matrix' , existingJobDetails ] , enhancers , enhancerOptions ) ;
6549
66- expect ( updatedJobDefinition . strategy . matrix . node ) . toBe ( undefined ) ;
50+ expect ( updatedJobDefinition ) . toEqual ( liftedJobDetails ) ;
6751 } ) ;
6852} ) ;
0 commit comments