@@ -11,15 +11,20 @@ const {
1111 unlinkSync,
1212} = require ( 'node:fs' ) ;
1313
14- const tryCatch = require ( 'try-catch' ) ;
1514const test = require ( 'supertape' ) ;
1615const putout = require ( 'putout' ) ;
1716const currify = require ( 'currify' ) ;
1817const { createProgress} = require ( '@putout/engine-runner/progress' ) ;
1918
2019const { createError} = require ( './create-error' ) ;
2120const { preTest} = require ( './pre-test' ) ;
22- const maybeArray = ( a ) => isArray ( a ) ? a : [ a ] ;
21+
22+ const {
23+ readFixture,
24+ writeFixture,
25+ rmFixture,
26+ } = require ( './fixture' ) ;
27+
2328const { isArray} = Array ;
2429const isString = ( a ) => typeof a === 'string' ;
2530const isObject = ( a ) => typeof a === 'object' ;
@@ -43,68 +48,6 @@ const fail = (t, message) => {
4348 return __putout_test_fail ( message ) ;
4449} ;
4550
46- const TS = {
47- ENABLED : true ,
48- DISABLED : false ,
49- } ;
50-
51- const readFixture = ( name , ext ) => {
52- const { readFileSync} = global . __putout_test_fs ;
53- const [ eTS , dataTS ] = tryCatch ( readFileSync , `${ name } .ts` , 'utf8' ) ;
54-
55- if ( ! eTS )
56- return [
57- dataTS ,
58- TS . ENABLED ,
59- '.ts' ,
60- ] ;
61-
62- const [ eJS , dataJS ] = tryCatch ( readFileSync , `${ name } .js` , 'utf8' ) ;
63-
64- if ( ! eJS )
65- return [
66- dataJS ,
67- TS . DISABLED ,
68- '.js' ,
69- ] ;
70-
71- for ( const currentExt of maybeArray ( ext ) ) {
72- const [ e , data ] = tryCatch ( readFileSync , `${ name } ${ currentExt } ` , 'utf8' ) ;
73-
74- if ( ! e )
75- return [
76- data ,
77- TS . DISABLED ,
78- currentExt ,
79- ] ;
80- }
81-
82- throw eJS ;
83- } ;
84-
85- const writeFixture = ( { full, code, currentExt} ) => {
86- writeSourceFixture ( {
87- full : `${ full } -fix` ,
88- code,
89- currentExt,
90- } ) ;
91- } ;
92-
93- const writeSourceFixture = ( { full, code, currentExt} ) => {
94- const { writeFileSync} = global . __putout_test_fs ;
95- writeFileSync ( `${ full } ${ currentExt } ` , code ) ;
96- } ;
97-
98- const rmFixture = ( name ) => {
99- const { unlinkSync} = global . __putout_test_fs ;
100-
101- if ( ! isUpdate ( ) )
102- return ;
103-
104- tryCatch ( unlinkSync , `${ name } .js` ) ;
105- tryCatch ( unlinkSync , `${ name } .ts` ) ;
106- } ;
107-
10851module . exports = createTest ;
10952module . exports . createTest = createTest ;
11053
@@ -119,7 +62,7 @@ function createTest(dir, maybeOptions) {
11962 dir = join ( dir , 'fixture' ) ;
12063
12164 const {
122- ext = [ ] ,
65+ extension = [ ] ,
12366 lint = putout ,
12467 ...options
12568 } = parseOptions ( maybeOptions ) ;
@@ -128,7 +71,7 @@ function createTest(dir, maybeOptions) {
12871
12972 const linterOptions = {
13073 lint,
131- ext ,
74+ extension ,
13275 } ;
13376
13477 preTest ( test , plugin ) ;
@@ -353,11 +296,11 @@ const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions,
353296} ;
354297
355298const transform = currify ( ( dir , linterOptions , options , t , name , transformed = null , addons = { } ) => {
356- const { lint, ext } = linterOptions ;
299+ const { lint, extension } = linterOptions ;
357300 const { plugins} = options ;
358301 const full = join ( dir , name ) ;
359302 const isStr = isString ( transformed ) ;
360- const [ input , isTS , currentExt ] = readFixture ( full , ext ) ;
303+ const [ input , isTS ] = readFixture ( full , extension ) ;
361304
362305 if ( ! isStr )
363306 addons = transformed ;
@@ -380,22 +323,21 @@ const transform = currify((dir, linterOptions, options, t, name, transformed = n
380323 writeFixture ( {
381324 full,
382325 code,
383-
384- currentExt,
326+ extension,
385327 } ) ;
386328 return t . pass ( 'fixed fixture updated' ) ;
387329 }
388330
389- const [ output ] = isStr ? [ transformed ] : readFixture ( `${ full } -fix` , ext ) ;
331+ const [ output ] = isStr ? [ transformed ] : readFixture ( `${ full } -fix` , extension ) ;
390332
391333 return t . equal ( code , output ) ;
392334} ) ;
393335
394336const transformWithOptions = currify ( ( dir , linterOptions , options , t , name , pluginOptions ) => {
395- const { lint, ext } = linterOptions ;
337+ const { lint, extension } = linterOptions ;
396338
397339 const full = join ( dir , name ) ;
398- const [ input , isTS , currentExt ] = readFixture ( full , ext ) ;
340+ const [ input , isTS ] = readFixture ( full , extension ) ;
399341
400342 const rule = parseRule ( options ) ;
401343
@@ -413,12 +355,12 @@ const transformWithOptions = currify((dir, linterOptions, options, t, name, plug
413355 writeFixture ( {
414356 full,
415357 code,
416- currentExt ,
358+ extension ,
417359 } ) ;
418360 return t . pass ( 'fixed fixture updated' ) ;
419361 }
420362
421- const [ output ] = readFixture ( `${ full } -fix` , ext ) ;
363+ const [ output ] = readFixture ( `${ full } -fix` , extension ) ;
422364
423365 return t . equal ( code , output ) ;
424366} ) ;
@@ -430,9 +372,9 @@ const parseRule = ({plugins}) => {
430372} ;
431373
432374const noTransformWithOptions = currify ( ( dir , linterOptions , options , t , name , ruleOptions ) => {
433- const { lint, ext } = linterOptions ;
375+ const { lint, extension } = linterOptions ;
434376 const full = join ( dir , name ) ;
435- const [ input , isTS , currentExt ] = readFixture ( full , ext ) ;
377+ const [ input , isTS ] = readFixture ( full , extension ) ;
436378
437379 rmFixture ( `${ full } -fix` ) ;
438380
@@ -448,11 +390,10 @@ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ru
448390 } ) ;
449391
450392 if ( isUpdate ( ) ) {
451- writeSourceFixture ( {
393+ writeFixture ( {
452394 full,
453395 code,
454-
455- currentExt,
396+ extension,
456397 } ) ;
457398
458399 return t . pass ( 'source fixture updated' ) ;
@@ -462,14 +403,14 @@ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ru
462403} ) ;
463404
464405const noTransform = currify ( ( dir , linterOptions , options , t , name , addons = { } ) => {
465- const { lint, ext } = linterOptions ;
406+ const { lint, extension } = linterOptions ;
466407 const full = join ( dir , name ) ;
467- const [ fixture ] = readFixture ( full , ext ) ;
408+ const [ fixture ] = readFixture ( full , extension ) ;
468409
469410 rmFixture ( `${ full } -fix` ) ;
470411
471412 const { plugins} = options ;
472- const [ input , isTS , currentExt ] = readFixture ( full , ext ) ;
413+ const [ input , isTS ] = readFixture ( full , extension ) ;
473414
474415 const { code} = lint ( input , {
475416 isTS,
@@ -481,10 +422,10 @@ const noTransform = currify((dir, linterOptions, options, t, name, addons = {})
481422 } ) ;
482423
483424 if ( isUpdate ( ) ) {
484- writeSourceFixture ( {
425+ writeFixture ( {
485426 full,
486427 code,
487- currentExt ,
428+ extension ,
488429 } ) ;
489430
490431 return t . pass ( 'source fixture updated' ) ;
@@ -513,11 +454,11 @@ const noTransformCode = currify((linterOptions, options, t, input) => {
513454const getMessage = ( { message} ) => message ;
514455
515456const report = ( dir , linterOptions , options ) => ( t ) => ( name , message , plugins ) => {
516- const { lint, ext } = linterOptions ;
457+ const { lint, extension } = linterOptions ;
517458 checkReport ( name , message ) ;
518459
519460 const full = join ( dir , name ) ;
520- const [ source , isTS ] = readFixture ( full , ext ) ;
461+ const [ source , isTS ] = readFixture ( full , extension ) ;
521462
522463 const addT = reportCode ( lint , {
523464 isTS,
@@ -530,9 +471,9 @@ const report = (dir, linterOptions, options) => (t) => (name, message, plugins)
530471} ;
531472
532473const noReport = currify ( ( dir , linterOptions , options , t , name ) => {
533- const { lint, ext } = linterOptions ;
474+ const { lint, extension } = linterOptions ;
534475 const full = join ( dir , name ) ;
535- const [ source , isTS ] = readFixture ( full , ext ) ;
476+ const [ source , isTS ] = readFixture ( full , extension ) ;
536477
537478 rmFixture ( `${ full } -fix` ) ;
538479
@@ -545,9 +486,9 @@ const noReport = currify((dir, linterOptions, options, t, name) => {
545486module . exports . _createNoReport = noReport ;
546487
547488const noReportAfterTransform = currify ( ( dir , linterOptions , options , t , name , addons = { } ) => {
548- const { lint, ext } = linterOptions ;
489+ const { lint, extension } = linterOptions ;
549490 const full = join ( dir , name ) ;
550- const [ source , isTS ] = readFixture ( full , ext ) ;
491+ const [ source , isTS ] = readFixture ( full , extension ) ;
551492
552493 return noReportCodeAfterTransform ( lint , {
553494 isTS,
@@ -558,9 +499,9 @@ const noReportAfterTransform = currify((dir, linterOptions, options, t, name, ad
558499module . exports . _createNoReportAfterTransform = noReportAfterTransform ;
559500
560501const noReportAfterTransformWithOptions = currify ( ( dir , linterOptions , options , t , name , ruleOptions ) => {
561- const { lint, ext } = linterOptions ;
502+ const { lint, extension } = linterOptions ;
562503 const full = join ( dir , name ) ;
563- const [ source , isTS ] = readFixture ( full , ext ) ;
504+ const [ source , isTS ] = readFixture ( full , extension ) ;
564505 const rule = parseRule ( options ) ;
565506
566507 const rules = {
@@ -580,9 +521,9 @@ const noReportAfterTransformWithOptions = currify((dir, linterOptions, options,
580521module . exports . _createNoReportAfterTransformWithOptions = noReportAfterTransformWithOptions ;
581522
582523const reportWithOptions = currify ( ( dir , linterOptions , options , t , name , message , ruleOptions ) => {
583- const { lint, ext } = linterOptions ;
524+ const { lint, extension } = linterOptions ;
584525 const full = join ( dir , name ) ;
585- const [ source , isTS ] = readFixture ( full , ext ) ;
526+ const [ source , isTS ] = readFixture ( full , extension ) ;
586527
587528 const rule = parseRule ( options ) ;
588529
@@ -602,9 +543,9 @@ const reportWithOptions = currify((dir, linterOptions, options, t, name, message
602543} ) ;
603544
604545const noReportWithOptions = currify ( ( dir , linterOptions , options , t , name , ruleOptions ) => {
605- const { lint, ext } = linterOptions ;
546+ const { lint, extension } = linterOptions ;
606547 const full = join ( dir , name ) ;
607- const [ source , isTS ] = readFixture ( full , ext ) ;
548+ const [ source , isTS ] = readFixture ( full , extension ) ;
608549
609550 rmFixture ( `${ full } -fix` ) ;
610551
0 commit comments