1
+ import deepmerge from 'deepmerge' ;
1
2
import { projectTypes } from '@form8ion/javascript-core' ;
2
3
3
4
import sinon from 'sinon' ;
4
5
import any from '@travi/any' ;
5
6
import { assert } from 'chai' ;
6
7
8
+ import * as semanticReleaseScaffolder from './semantic-release/scaffolder' ;
7
9
import * as commitizenScaffolder from './commitizen' ;
8
10
import * as commitlintScaffolder from './commitlint' ;
9
11
import scaffoldCommitConvention from './scaffolder' ;
@@ -12,31 +14,26 @@ suite('commit-convention scaffolder', () => {
12
14
let sandbox ;
13
15
const projectRoot = any . string ( ) ;
14
16
const packageManager = any . word ( ) ;
15
- const commitizenScripts = any . simpleObject ( ) ;
16
- const commitizenDevDependencies = any . listOf ( any . string ) ;
17
17
const publishedProjectType = any . fromList ( [ projectTypes . PACKAGE , projectTypes . CLI ] ) ;
18
- const contributionBadges = {
19
- 'commit-convention' : {
20
- img : 'https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg' ,
21
- text : 'Conventional Commits' ,
22
- link : 'https://conventionalcommits.org'
23
- }
24
- } ;
25
- const semanticReleaseBadge = {
26
- img : 'https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release' ,
27
- text : 'semantic-release: angular' ,
28
- link : 'https://github.com/semantic-release/semantic-release'
18
+ const mergedResults = any . simpleObject ( ) ;
19
+ const commitizenResults = any . simpleObject ( ) ;
20
+ const semanticReleaseResults = any . simpleObject ( ) ;
21
+ const conventionalCommitsBadge = {
22
+ img : 'https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg' ,
23
+ text : 'Conventional Commits' ,
24
+ link : 'https://conventionalcommits.org'
29
25
} ;
30
26
31
27
setup ( ( ) => {
32
28
sandbox = sinon . createSandbox ( ) ;
33
29
30
+ sandbox . stub ( deepmerge , 'all' ) ;
34
31
sandbox . stub ( commitlintScaffolder , 'default' ) ;
35
32
sandbox . stub ( commitizenScaffolder , 'default' ) ;
33
+ sandbox . stub ( semanticReleaseScaffolder , 'default' ) ;
36
34
37
- commitizenScaffolder . default
38
- . withArgs ( { projectRoot} )
39
- . resolves ( { devDependencies : commitizenDevDependencies , scripts : commitizenScripts } ) ;
35
+ commitizenScaffolder . default . withArgs ( { projectRoot} ) . resolves ( commitizenResults ) ;
36
+ semanticReleaseScaffolder . default . returns ( semanticReleaseResults ) ;
40
37
} ) ;
41
38
42
39
teardown ( ( ) => sandbox . restore ( ) ) ;
@@ -51,53 +48,66 @@ suite('commit-convention scaffolder', () => {
51
48
pathWithinParent : any . string ( ) ,
52
49
projectType : publishedProjectType
53
50
} ) ,
54
- {
55
- packageProperties : { version : '0.0.0-semantically-released' } ,
56
- badges : { contribution : { 'semantic-release' : semanticReleaseBadge } }
57
- }
51
+ semanticReleaseResults
58
52
) ;
59
53
} ) ;
60
54
61
55
test ( 'that the convention is configured' , async ( ) => {
62
56
const commitlintConfig = any . simpleObject ( ) ;
63
- const commitlintDevDependencies = any . listOf ( any . string ) ;
64
- commitlintScaffolder . default
65
- . withArgs ( { projectRoot, config : commitlintConfig } )
66
- . resolves ( { devDependencies : commitlintDevDependencies } ) ;
57
+ const commitlintResults = any . simpleObject ( ) ;
58
+ commitlintScaffolder . default . withArgs ( { projectRoot, config : commitlintConfig } ) . resolves ( commitlintResults ) ;
59
+ deepmerge . all
60
+ . withArgs ( [
61
+ commitizenResults ,
62
+ commitlintResults ,
63
+ {
64
+ vcsIgnore : { files : [ ] , directories : [ ] } ,
65
+ badges : { contribution : { 'commit-convention' : conventionalCommitsBadge } }
66
+ } ,
67
+ { }
68
+ ] )
69
+ . returns ( mergedResults ) ;
67
70
68
- assert . deepEqual (
71
+ assert . equal (
69
72
await scaffoldCommitConvention ( { projectRoot, packageManager, configs : { commitlint : commitlintConfig } } ) ,
70
- {
71
- devDependencies : [ ...commitizenDevDependencies , ...commitlintDevDependencies ] ,
72
- scripts : commitizenScripts ,
73
- vcsIgnore : { files : [ ] , directories : [ ] } ,
74
- badges : { contribution : contributionBadges }
75
- }
73
+ mergedResults
76
74
) ;
77
75
} ) ;
78
76
79
77
test ( 'that commitlint is not configured if no config is provided' , async ( ) => {
78
+ deepmerge . all
79
+ . withArgs ( [
80
+ commitizenResults ,
81
+ {
82
+ vcsIgnore : { files : [ ] , directories : [ ] } ,
83
+ badges : { contribution : { 'commit-convention' : conventionalCommitsBadge } }
84
+ } ,
85
+ { }
86
+ ] )
87
+ . returns ( mergedResults ) ;
88
+
80
89
assert . deepEqual (
81
90
await scaffoldCommitConvention ( { projectRoot, configs : { } , packageManager} ) ,
82
- {
83
- devDependencies : commitizenDevDependencies ,
84
- scripts : commitizenScripts ,
85
- vcsIgnore : { files : [ ] , directories : [ ] } ,
86
- badges : { contribution : contributionBadges }
87
- }
91
+ mergedResults
88
92
) ;
89
93
assert . notCalled ( commitlintScaffolder . default ) ;
90
94
} ) ;
91
95
92
96
test ( 'that semantic-release is configured for packages' , async ( ) => {
93
- const { badges, packageProperties} = await scaffoldCommitConvention ( {
94
- projectRoot,
95
- projectType : publishedProjectType ,
96
- configs : { } ,
97
- packageManager
98
- } ) ;
97
+ deepmerge . all
98
+ . withArgs ( [
99
+ commitizenResults ,
100
+ {
101
+ vcsIgnore : { files : [ ] , directories : [ ] } ,
102
+ badges : { contribution : { 'commit-convention' : conventionalCommitsBadge } }
103
+ } ,
104
+ semanticReleaseResults
105
+ ] )
106
+ . returns ( mergedResults ) ;
99
107
100
- assert . equal ( packageProperties . version , '0.0.0-semantically-released' ) ;
101
- assert . deepEqual ( badges . contribution [ 'semantic-release' ] , semanticReleaseBadge ) ;
108
+ assert . deepEqual (
109
+ await scaffoldCommitConvention ( { projectRoot, projectType : publishedProjectType , configs : { } , packageManager} ) ,
110
+ mergedResults
111
+ ) ;
102
112
} ) ;
103
113
} ) ;
0 commit comments