1
- import { promises as fs } from 'fs' ;
2
1
import any from '@travi/any' ;
3
2
import * as readme from '@form8ion/readme' ;
4
3
import sinon from 'sinon' ;
5
4
import { assert } from 'chai' ;
6
5
import scaffoldReadme from './readme' ;
7
6
8
- const badgeFactory = ( ) => ( { img : any . url ( ) , link : any . url ( ) , text : any . sentence ( ) } ) ;
9
- const consumerBadges = any . objectWithKeys ( any . listOf ( any . word ) , { factory : badgeFactory } ) ;
10
- const statusBadges = any . objectWithKeys ( any . listOf ( any . word ) , { factory : badgeFactory } ) ;
11
- const contributionBadges = any . objectWithKeys ( any . listOf ( any . word ) , { factory : badgeFactory } ) ;
12
-
13
7
suite ( 'scaffold readme' , ( ) => {
14
8
let sandbox ;
15
9
const projectName = any . word ( ) ;
@@ -19,118 +13,19 @@ suite('scaffold readme', () => {
19
13
setup ( ( ) => {
20
14
sandbox = sinon . createSandbox ( ) ;
21
15
16
+ sandbox . stub ( readme , 'scaffold' ) ;
22
17
sandbox . stub ( readme , 'lift' ) ;
23
- sandbox . stub ( fs , 'writeFile' ) ;
24
18
} ) ;
25
19
26
20
teardown ( ( ) => sandbox . restore ( ) ) ;
27
21
28
- test ( 'that the README has a top-level heading of the project name and includes the description' , async ( ) => {
29
- const badges = { consumer : { } , status : { } , contribution : { } } ;
30
-
31
- await scaffoldReadme ( { projectName, projectRoot, description, badges} ) ;
32
-
33
- assert . calledWith (
34
- fs . writeFile ,
35
- `${ projectRoot } /README.md` ,
36
- sinon . match ( `# ${ projectName }
37
-
38
- ${ description } `)
39
- ) ;
40
- assert . calledWith ( readme . lift , { projectRoot, results : { badges} } ) ;
41
- } ) ;
42
-
43
- suite ( 'documentation' , ( ) => {
44
- const markdownWithBackticksAndForwardSlashes = `\`\`\`sh${ any . sentence ( ) } \`\`\`https://any.url` ;
45
-
46
- test ( 'that usage docs are shown after the contributing badges' , async ( ) => {
47
- const usageDocs = markdownWithBackticksAndForwardSlashes ;
48
- const badges = { consumer : consumerBadges , status : statusBadges , contribution : contributionBadges } ;
49
-
50
- await scaffoldReadme ( {
51
- projectRoot,
52
- badges,
53
- documentation : { usage : usageDocs }
54
- } ) ;
55
-
56
- assert . calledWith (
57
- fs . writeFile ,
58
- `${ projectRoot } /README.md` ,
59
- sinon . match ( `
60
- <!--status-badges start -->
61
- <!--status-badges end -->
62
-
63
- ## Usage
64
-
65
- <!--consumer-badges start -->
66
- <!--consumer-badges end -->
67
-
68
- ${ usageDocs }
69
-
70
- <!--contribution-badges start -->
71
- <!--contribution-badges end -->
72
- ` )
73
- ) ;
74
- } ) ;
75
-
76
- test ( 'that consumer badges are lifted to top level when toc is present and no usage content' , async ( ) => {
77
- const toc = `${ any . word ( ) } \`${ any . word ( ) } \` ${ any . word ( ) } ` ;
78
- const badges = { consumer : consumerBadges , status : statusBadges , contribution : contributionBadges } ;
79
-
80
- await scaffoldReadme ( {
81
- projectRoot,
82
- badges,
83
- documentation : { toc}
84
- } ) ;
85
-
86
- assert . calledWith (
87
- fs . writeFile ,
88
- `${ projectRoot } /README.md` ,
89
- sinon . match ( `
90
- <!--status-badges start -->
91
- <!--status-badges end -->
92
-
93
- <!--consumer-badges start -->
94
- <!--consumer-badges end -->
95
-
96
- ## Table of Contents
97
-
98
- ${ toc }
99
-
100
- <!--contribution-badges start -->
101
- <!--contribution-badges end -->
102
- ` )
103
- ) ;
104
- } ) ;
105
-
106
- test ( 'that contribution docs are shown after the contributing badges' , async ( ) => {
107
- const contributingDocs = markdownWithBackticksAndForwardSlashes ;
108
- const badges = { consumer : consumerBadges , status : statusBadges , contribution : contributionBadges } ;
109
-
110
- await scaffoldReadme ( {
111
- projectRoot,
112
- badges,
113
- documentation : { contributing : contributingDocs }
114
- } ) ;
115
-
116
- assert . calledWith (
117
- fs . writeFile ,
118
- `${ projectRoot } /README.md` ,
119
- sinon . match ( `
120
- <!--status-badges start -->
121
- <!--status-badges end -->
122
-
123
- <!--consumer-badges start -->
124
- <!--consumer-badges end -->
125
-
126
- ## Contributing
22
+ test ( 'that the README created and lifted' , async ( ) => {
23
+ const badges = any . simpleObject ( ) ;
24
+ const documentation = any . simpleObject ( ) ;
127
25
128
- <!--contribution-badges start -->
129
- <!--contribution-badges end -->
26
+ await scaffoldReadme ( { projectName, projectRoot, description, badges, documentation} ) ;
130
27
131
- ${ contributingDocs }
132
- ` )
133
- ) ;
134
- } ) ;
28
+ assert . calledWith ( readme . scaffold , { projectRoot, projectName, description} ) ;
29
+ assert . calledWith ( readme . lift , { projectRoot, results : { badges, documentation} } ) ;
135
30
} ) ;
136
31
} ) ;
0 commit comments