1
- import path from 'node:path' ;
2
1
import { setTimeout } from 'node:timers/promises' ;
3
2
import { testSuite , expect } from 'manten' ;
4
3
import { createFixture } from 'fs-fixture' ;
@@ -222,14 +221,73 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
222
221
} , 10_000 ) ;
223
222
} ) ;
224
223
225
- describe ( 'ignore' , ( { test } ) => {
226
- test ( 'file path & glob' , async ( { onTestFinish, onTestFail } ) => {
224
+ describe ( 'include' , ( { test } ) => {
225
+ test ( 'file path & glob' , async ( ) => {
226
+ const entryFile = 'index.js' ;
227
+ const fileA = 'file-a' ;
228
+ const fileB = 'directory/file-b' ;
229
+ await using fixture = await createFixture ( {
230
+ [ entryFile ] : `
231
+ import fs from 'fs/promises';
232
+ Promise.all([
233
+ fs.readFile('./${ fileA } ', 'utf8'),
234
+ fs.readFile('./${ fileB } ', 'utf8')
235
+ ]).then(console.log, console.error);
236
+ ` . trim ( ) ,
237
+ [ fileA ] : 'content-a' ,
238
+ [ fileB ] : 'content-b' ,
239
+ } ) ;
240
+
241
+ const tsxProcess = tsx (
242
+ [
243
+ 'watch' ,
244
+ '--clear-screen=false' ,
245
+ `--include=${ fileA } ` ,
246
+ '--include=directory/*' ,
247
+ entryFile ,
248
+ ] ,
249
+ fixture . path ,
250
+ ) ;
251
+
252
+ await processInteract (
253
+ tsxProcess . stdout ! ,
254
+ [
255
+ ( data ) => {
256
+ if ( data . includes ( "'content-a', 'content-b'" ) ) {
257
+ fixture . writeFile ( fileA , 'update-a' ) ;
258
+ return true ;
259
+ }
260
+ } ,
261
+ ( data ) => {
262
+ if ( data . includes ( "'update-a', 'content-b'" ) ) {
263
+ fixture . writeFile ( fileB , 'update-b' ) ;
264
+ return true ;
265
+ }
266
+ } ,
267
+ ( data ) => {
268
+ if ( data . includes ( "'update-a', 'update-b'" ) ) {
269
+ return true ;
270
+ }
271
+ } ,
272
+ ] ,
273
+ 9000 ,
274
+ ) ;
275
+
276
+ tsxProcess . kill ( ) ;
277
+
278
+ const tsxProcessResolved = await tsxProcess ;
279
+ expect ( tsxProcessResolved . stderr ) . toBe ( '' ) ;
280
+ } , 10_000 ) ;
281
+ } ) ;
282
+
283
+ describe ( 'exclude (ignore)' , ( { test } ) => {
284
+ test ( 'file path & glob' , async ( { onTestFail } ) => {
227
285
const entryFile = 'index.js' ;
228
286
const fileA = 'file-a.js' ;
229
287
const fileB = 'directory/file-b.js' ;
230
288
const depA = 'node_modules/a/index.js' ;
231
289
232
- const fixtureGlob = await createFixture ( {
290
+ await using fixtureGlob = await createFixture ( {
233
291
[ fileA ] : 'export default "logA"' ,
234
292
[ fileB ] : 'export default "logB"' ,
235
293
[ depA ] : 'export default "logC"' ,
@@ -241,14 +299,12 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
241
299
` . trim ( ) ,
242
300
} ) ;
243
301
244
- onTestFinish ( async ( ) => await fixtureGlob . rm ( ) ) ;
245
-
246
302
const tsxProcess = tsx (
247
303
[
248
304
'watch' ,
249
305
'--clear-screen=false' ,
250
306
`--ignore=${ fileA } ` ,
251
- `--ignore= ${ path . join ( fixtureGlob . path , ' directory/*') } ` ,
307
+ '--exclude= directory/*',
252
308
entryFile ,
253
309
] ,
254
310
fixtureGlob . path ,
@@ -300,64 +356,5 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
300
356
expect ( p . stderr ) . toBe ( '' ) ;
301
357
} , 10_000 ) ;
302
358
} ) ;
303
-
304
- describe ( 'watch additional files' , ( { test } ) => {
305
- test ( 'file path & glob' , async ( ) => {
306
- const entryFile = 'index.js' ;
307
- const fileA = 'file-a' ;
308
- const fileB = 'directory/file-b' ;
309
- await using fixture = await createFixture ( {
310
- [ entryFile ] : `
311
- import fs from 'fs/promises';
312
- Promise.all([
313
- fs.readFile('./${ fileA } ', 'utf8'),
314
- fs.readFile('./${ fileB } ', 'utf8')
315
- ]).then(console.log, console.error);
316
- ` . trim ( ) ,
317
- [ fileA ] : 'content-a' ,
318
- [ fileB ] : 'content-b' ,
319
- } ) ;
320
-
321
- const tsxProcess = tsx (
322
- [
323
- 'watch' ,
324
- '--clear-screen=false' ,
325
- `--include=${ fileA } ` ,
326
- '--include=directory/*' ,
327
- entryFile ,
328
- ] ,
329
- fixture . path ,
330
- ) ;
331
-
332
- await processInteract (
333
- tsxProcess . stdout ! ,
334
- [
335
- ( data ) => {
336
- if ( data . includes ( "'content-a', 'content-b'" ) ) {
337
- fixture . writeFile ( fileA , 'update-a' ) ;
338
- return true ;
339
- }
340
- } ,
341
- ( data ) => {
342
- if ( data . includes ( "'update-a', 'content-b'" ) ) {
343
- fixture . writeFile ( fileB , 'update-b' ) ;
344
- return true ;
345
- }
346
- } ,
347
- ( data ) => {
348
- if ( data . includes ( "'update-a', 'update-b'" ) ) {
349
- return true ;
350
- }
351
- } ,
352
- ] ,
353
- 9000 ,
354
- ) ;
355
-
356
- tsxProcess . kill ( ) ;
357
-
358
- const tsxProcessResolved = await tsxProcess ;
359
- expect ( tsxProcessResolved . stderr ) . toBe ( '' ) ;
360
- } , 10_000 ) ;
361
- } ) ;
362
359
} ) ;
363
360
} ) ;
0 commit comments