1
- import { testBlock } from "bingo-stratum-testers" ;
2
- import { describe , expect , test } from "vitest" ;
1
+ import { testBlock , testIntake } from "bingo-stratum-testers" ;
2
+ import { describe , expect , it , test } from "vitest" ;
3
3
4
4
import { blockNcc } from "./blockNcc.js" ;
5
5
import { optionsBase } from "./options.fakes.js" ;
6
6
7
7
describe ( "blockNcc" , ( ) => {
8
- test ( "production " , ( ) => {
8
+ test ( "without addons " , ( ) => {
9
9
const creation = testBlock ( blockNcc , {
10
10
options : optionsBase ,
11
11
} ) ;
@@ -100,6 +100,72 @@ describe("blockNcc", () => {
100
100
},
101
101
"block": [Function],
102
102
},
103
+ {
104
+ "addons": {
105
+ "ignores": [
106
+ "/dist",
107
+ ],
108
+ },
109
+ "block": [Function],
110
+ },
111
+ ],
112
+ }
113
+ ` ) ;
114
+ } ) ;
115
+
116
+ test ( "with addons" , ( ) => {
117
+ const creation = testBlock ( blockNcc , {
118
+ addons : {
119
+ entry : "src/action/index.ts" ,
120
+ } ,
121
+ options : optionsBase ,
122
+ } ) ;
123
+
124
+ expect ( creation ) . toMatchInlineSnapshot ( `
125
+ {
126
+ "addons": [
127
+ {
128
+ "addons": {
129
+ "ignores": [
130
+ "dist",
131
+ ],
132
+ },
133
+ "block": [Function],
134
+ },
135
+ {
136
+ "addons": {
137
+ "sections": {
138
+ "Building": {
139
+ "contents": "
140
+ Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`:
141
+
142
+ \`\`\`shell
143
+ pnpm build
144
+ \`\`\`
145
+
146
+ Add \`--watch\` to run the builder in a watch mode that continuously cleans and recreates \`lib/\` as you save files:
147
+
148
+ \`\`\`shell
149
+ pnpm build --watch
150
+ \`\`\`
151
+ ",
152
+ "innerSections": [
153
+ {
154
+ "contents": "
155
+ Run [\`@vercel/ncc\`](https://github.com/vercel/ncc) to create an output \`dist/\` to be used in production.
156
+
157
+ \`\`\`shell
158
+ pnpm build:release
159
+ \`\`\`
160
+ ",
161
+ "heading": "Building for Release",
162
+ },
163
+ ],
164
+ },
165
+ },
166
+ },
167
+ "block": [Function],
168
+ },
103
169
{
104
170
"addons": {
105
171
"ignores": [
@@ -108,8 +174,125 @@ describe("blockNcc", () => {
108
174
},
109
175
"block": [Function],
110
176
},
177
+ {
178
+ "addons": {
179
+ "jobs": [
180
+ {
181
+ "name": "Build",
182
+ "steps": [
183
+ {
184
+ "run": "pnpm build",
185
+ },
186
+ ],
187
+ },
188
+ {
189
+ "name": "Build (Release)",
190
+ "steps": [
191
+ {
192
+ "run": "pnpm build:release",
193
+ },
194
+ ],
195
+ },
196
+ ],
197
+ },
198
+ "block": [Function],
199
+ },
200
+ {
201
+ "addons": {
202
+ "properties": {
203
+ "devDependencies": {
204
+ "@vercel/ncc": "^0.38.3",
205
+ },
206
+ "scripts": {
207
+ "build": "tsc",
208
+ "build:release": "ncc build src/action/index.ts -o dist",
209
+ },
210
+ },
211
+ },
212
+ "block": [Function],
213
+ },
214
+ {
215
+ "addons": {
216
+ "ignores": [
217
+ "/dist",
218
+ ],
219
+ },
220
+ "block": [Function],
221
+ },
111
222
],
112
223
}
113
224
` ) ;
114
225
} ) ;
226
+
227
+ describe ( "intake" , ( ) => {
228
+ it ( "returns an undefined entry when options.packageData does not exist" , ( ) => {
229
+ const actual = testIntake ( blockNcc , {
230
+ files : { } ,
231
+ options : {
232
+ ...optionsBase ,
233
+ packageData : undefined ,
234
+ } ,
235
+ } ) ;
236
+
237
+ expect ( actual ) . toEqual ( { entry : undefined } ) ;
238
+ } ) ;
239
+
240
+ it ( "returns an undefined entry when options.packageData does not contain scripts" , ( ) => {
241
+ const actual = testIntake ( blockNcc , {
242
+ files : { } ,
243
+ options : {
244
+ ...optionsBase ,
245
+ packageData : { } ,
246
+ } ,
247
+ } ) ;
248
+
249
+ expect ( actual ) . toEqual ( { entry : undefined } ) ;
250
+ } ) ;
251
+
252
+ it ( "returns an undefined entry when options.packageData does not contain a build:release script" , ( ) => {
253
+ const actual = testIntake ( blockNcc , {
254
+ files : { } ,
255
+ options : {
256
+ ...optionsBase ,
257
+ packageData : {
258
+ scripts : { } ,
259
+ } ,
260
+ } ,
261
+ } ) ;
262
+
263
+ expect ( actual ) . toEqual ( { entry : undefined } ) ;
264
+ } ) ;
265
+
266
+ it ( "returns an undefined entry when options.packageData contains an unrelated build:release script" , ( ) => {
267
+ const actual = testIntake ( blockNcc , {
268
+ files : { } ,
269
+ options : {
270
+ ...optionsBase ,
271
+ packageData : {
272
+ scripts : {
273
+ "build:release" : "tsup" ,
274
+ } ,
275
+ } ,
276
+ } ,
277
+ } ) ;
278
+
279
+ expect ( actual ) . toEqual ( { entry : undefined } ) ;
280
+ } ) ;
281
+
282
+ it ( "returns a parsed entry when options.packageData contains a matching build:release script" , ( ) => {
283
+ const actual = testIntake ( blockNcc , {
284
+ files : { } ,
285
+ options : {
286
+ ...optionsBase ,
287
+ packageData : {
288
+ scripts : {
289
+ "build:release" : "ncc build src/action/index.ts -o dist" ,
290
+ } ,
291
+ } ,
292
+ } ,
293
+ } ) ;
294
+
295
+ expect ( actual ) . toEqual ( { entry : "src/action/index.ts" } ) ;
296
+ } ) ;
297
+ } ) ;
115
298
} ) ;
0 commit comments