@@ -63,18 +63,54 @@ describe("generator-biojs-webcomponents:app - Make a new Web Component", () => {
63
63
] ) ;
64
64
} ) ;
65
65
} ) ;
66
- it ( "throws an error if user enters an empty string as toolNameHuman " , async ( ) => {
66
+ it ( "passes if toolNameComputer is correctly formatted " , async ( ) => {
67
67
assert . equal (
68
- await validators . toolNameHuman ( " ") ,
69
- chalk . red ( "This is a mandatory field, please answer." )
68
+ await validators . toolNameComputer ( "tool-name-computer-1 ") ,
69
+ true
70
70
) ;
71
71
} ) ;
72
+ it ( "passes if toolNameHuman is correctly formatted" , async ( ) => {
73
+ assert . equal ( await validators . toolNameHuman ( "Tool Name Human" ) , true ) ;
74
+ } ) ;
75
+ it ( "throws an error if toolNameComputer is wrongly formatted" , async ( ) => {
76
+ let err1 = await validators . toolNameComputer ( "-tool-name" ) ;
77
+ let err2 = await validators . toolNameComputer ( "tool-name-" ) ;
78
+ let err3 = await validators . toolNameComputer ( "toolName-computer" ) ;
79
+ let err4 = await validators . toolNameComputer ( "*toolname-comp" ) ;
80
+ let err5 = await validators . toolNameComputer ( "tool name" ) ;
81
+ if (
82
+ err1 !== true &&
83
+ err2 !== true &&
84
+ err3 !== true &&
85
+ err4 !== true &&
86
+ err5 !== true
87
+ ) {
88
+ assert . ok ( true ) ;
89
+ } else {
90
+ assert . fail ( ) ;
91
+ }
92
+ } ) ;
93
+ it ( "throws an error if toolNameHuman is wrongly formatted" , async ( ) => {
94
+ let err1 = await validators . toolNameHuman ( "tool-name" ) ;
95
+ let err2 = await validators . toolNameHuman ( "toolname1" ) ;
96
+ if ( err1 !== true && err2 !== true ) {
97
+ assert . ok ( true ) ;
98
+ } else {
99
+ assert . fail ( ) ;
100
+ }
101
+ } ) ;
72
102
it ( "throws an error if user enters an empty string as toolNameComputer" , async ( ) => {
73
103
assert . equal (
74
104
await validators . toolNameComputer ( "" ) ,
75
105
chalk . red ( "This is a mandatory field, please answer." )
76
106
) ;
77
107
} ) ;
108
+ it ( "throws an error if user enters an empty string as toolNameHuman" , async ( ) => {
109
+ assert . equal (
110
+ await validators . toolNameHuman ( "" ) ,
111
+ chalk . red ( "This is a mandatory field, please answer." )
112
+ ) ;
113
+ } ) ;
78
114
} ) ;
79
115
80
116
describe ( "generator-biojs-webcomponents:app - Upgrade an existing component by importing build file locally" , ( ) => {
@@ -83,12 +119,16 @@ describe("generator-biojs-webcomponents:app - Upgrade an existing component by i
83
119
assert . file ( "test-component" ) ;
84
120
} ) ;
85
121
} ) ;
122
+ it ( "does not throw an error if user enters path of a project directory which already exists" , async ( ) => {
123
+ let res = await validators . storeArg ( "test-component" ) ;
124
+ assert . equal ( res , true ) ;
125
+ } ) ;
86
126
it ( "makes a new directory named - component-dist" , async ( ) => {
87
127
await validators
88
128
. directoryName ( "component-dist" )
89
129
. then ( ( ) => assert . file ( [ "test-component/component-dist" ] ) ) ;
90
130
} ) ;
91
- it ( "imports the build file" , async ( ) => {
131
+ it ( "imports the build file locally " , async ( ) => {
92
132
await validators
93
133
. importBuildFileLocally (
94
134
path . join ( __dirname , "../generators/app/validator.js" )
@@ -97,6 +137,18 @@ describe("generator-biojs-webcomponents:app - Upgrade an existing component by i
97
137
assert . file ( [ "test-component/component-dist/validator.js" ] ) ;
98
138
} ) ;
99
139
} ) ;
140
+ it ( "overwrites the directory content if user enters o or O" , async ( ) => {
141
+ await validators
142
+ . directoryName ( "o" )
143
+ . then ( ( ) =>
144
+ assert . noFile ( [ "test-component/component-dist/validator.js" ] )
145
+ ) ;
146
+ } ) ;
147
+ it ( "makes a new directory if user enters a new name" , async ( ) => {
148
+ await validators . directoryName ( "new-build-dir" ) . then ( ( ) => {
149
+ assert . file ( "test-component/new-build-dir" ) ;
150
+ } ) ;
151
+ } ) ;
100
152
it ( "throws an error if user enters an empty string as path of build file" , async ( ) => {
101
153
assert . equal (
102
154
await validators . importBuildFileFromNPM ( "" ) ,
@@ -105,7 +157,27 @@ describe("generator-biojs-webcomponents:app - Upgrade an existing component by i
105
157
} ) ;
106
158
} ) ;
107
159
160
+ describe ( "generator-biojs-webcomponents:app - Upgrade an existing component by installing component from npm package" , ( ) => {
161
+ it ( "installs the latest component from its npm package if user enters a valid version" , async ( ) => {
162
+ jest . setTimeout ( 10000 ) ; // Increases timeout for this test
163
+ let res = await validators . checkVersionAndInstallComponent ( "latest" , {
164
+ packageNameToInstallComponent : "is-odd"
165
+ } ) ;
166
+ assert . equal ( res , true ) ;
167
+ } ) ;
168
+ } ) ;
169
+
108
170
describe ( "generator-biojs-webcomponents:app - Upgrade an existing component by importing build file using npm" , ( ) => {
171
+ it ( "runs the generator in the directory passed in arguments" , async ( ) => {
172
+ await validators . storeArg ( "test-component" ) . then ( ( ) => {
173
+ assert . file ( "test-component" ) ;
174
+ } ) ;
175
+ } ) ;
176
+ it ( "makes a new directory named - component-dist" , async ( ) => {
177
+ await validators
178
+ . directoryName ( "component-dist" )
179
+ . then ( ( ) => assert . file ( [ "test-component/component-dist" ] ) ) ;
180
+ } ) ;
109
181
it ( "throws an error if version entered does not exist" , async ( ) => {
110
182
assert . equal (
111
183
await validators . version ( "fkdk" , { packageName : "node" } ) ,
@@ -118,6 +190,15 @@ describe("generator-biojs-webcomponents:app - Upgrade an existing component by i
118
190
)
119
191
) ;
120
192
} ) ;
193
+ it ( "downloads the URL of build file entered is correct" , async ( ) => {
194
+ await validators
195
+ . importBuildFileFromNPM (
196
+ "https://cdn.jsdelivr.net/npm/[email protected] /index.min.js"
197
+ )
198
+ . then ( ( ) => {
199
+ assert . file ( "test-component/component-dist/index.min.js" ) ;
200
+ } ) ;
201
+ } ) ;
121
202
it ( "throws an error if an npm package doesn't exist" , async ( ) => {
122
203
assert . equal (
123
204
await validators . packageName ( "cbaxyz" ) ,
0 commit comments