@putout/test 13.2.0 → 13.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/fixture.js +56 -0
- package/lib/test.js +38 -97
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/fixture.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const tryCatch = require('try-catch');
|
|
5
|
+
|
|
6
|
+
const isUpdate = () => Boolean(Number(process.env.UPDATE));
|
|
7
|
+
const TS = {
|
|
8
|
+
ENABLED: true,
|
|
9
|
+
DISABLED: false,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports.readFixture = (name, extension) => {
|
|
13
|
+
const {readFileSync} = global.__putout_test_fs;
|
|
14
|
+
const [eTS, dataTS] = tryCatch(readFileSync, `${name}.ts`, 'utf8');
|
|
15
|
+
|
|
16
|
+
if (!eTS)
|
|
17
|
+
return [
|
|
18
|
+
dataTS,
|
|
19
|
+
TS.ENABLED,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const [eJS, dataJS] = tryCatch(readFileSync, `${name}.js`, 'utf8');
|
|
23
|
+
|
|
24
|
+
if (!eJS)
|
|
25
|
+
return [
|
|
26
|
+
dataJS,
|
|
27
|
+
TS.DISABLED,
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
if (extension) {
|
|
31
|
+
const [e, data] = tryCatch(readFileSync, `${name}.${extension}`, 'utf8');
|
|
32
|
+
|
|
33
|
+
if (!e)
|
|
34
|
+
return [
|
|
35
|
+
data,
|
|
36
|
+
TS.DISABLED,
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
throw eJS;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports.writeFixture = ({full, code, extension}) => {
|
|
44
|
+
const {writeFileSync} = global.__putout_test_fs;
|
|
45
|
+
writeFileSync(`${full}-fix.${extension}`, code);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports.rmFixture = (name) => {
|
|
49
|
+
const {unlinkSync} = global.__putout_test_fs;
|
|
50
|
+
|
|
51
|
+
if (!isUpdate())
|
|
52
|
+
return;
|
|
53
|
+
|
|
54
|
+
tryCatch(unlinkSync, `${name}.js`);
|
|
55
|
+
tryCatch(unlinkSync, `${name}.ts`);
|
|
56
|
+
};
|
package/lib/test.js
CHANGED
|
@@ -11,7 +11,6 @@ const {
|
|
|
11
11
|
unlinkSync,
|
|
12
12
|
} = require('node:fs');
|
|
13
13
|
|
|
14
|
-
const tryCatch = require('try-catch');
|
|
15
14
|
const test = require('supertape');
|
|
16
15
|
const putout = require('putout');
|
|
17
16
|
const currify = require('currify');
|
|
@@ -19,7 +18,13 @@ const {createProgress} = require('@putout/engine-runner/progress');
|
|
|
19
18
|
|
|
20
19
|
const {createError} = require('./create-error');
|
|
21
20
|
const {preTest} = require('./pre-test');
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
readFixture,
|
|
24
|
+
writeFixture,
|
|
25
|
+
rmFixture,
|
|
26
|
+
} = require('./fixture');
|
|
27
|
+
|
|
23
28
|
const {isArray} = Array;
|
|
24
29
|
const isString = (a) => typeof a === 'string';
|
|
25
30
|
const isObject = (a) => typeof a === 'object';
|
|
@@ -43,68 +48,6 @@ const fail = (t, message) => {
|
|
|
43
48
|
return __putout_test_fail(message);
|
|
44
49
|
};
|
|
45
50
|
|
|
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
|
-
|
|
108
51
|
module.exports = createTest;
|
|
109
52
|
module.exports.createTest = createTest;
|
|
110
53
|
|
|
@@ -119,7 +62,7 @@ function createTest(dir, maybeOptions) {
|
|
|
119
62
|
dir = join(dir, 'fixture');
|
|
120
63
|
|
|
121
64
|
const {
|
|
122
|
-
|
|
65
|
+
extension = [],
|
|
123
66
|
lint = putout,
|
|
124
67
|
...options
|
|
125
68
|
} = parseOptions(maybeOptions);
|
|
@@ -128,7 +71,7 @@ function createTest(dir, maybeOptions) {
|
|
|
128
71
|
|
|
129
72
|
const linterOptions = {
|
|
130
73
|
lint,
|
|
131
|
-
|
|
74
|
+
extension,
|
|
132
75
|
};
|
|
133
76
|
|
|
134
77
|
preTest(test, plugin);
|
|
@@ -353,11 +296,11 @@ const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions,
|
|
|
353
296
|
};
|
|
354
297
|
|
|
355
298
|
const transform = currify((dir, linterOptions, options, t, name, transformed = null, addons = {}) => {
|
|
356
|
-
const {lint,
|
|
299
|
+
const {lint, extension} = linterOptions;
|
|
357
300
|
const {plugins} = options;
|
|
358
301
|
const full = join(dir, name);
|
|
359
302
|
const isStr = isString(transformed);
|
|
360
|
-
const [input, isTS
|
|
303
|
+
const [input, isTS] = readFixture(full, extension);
|
|
361
304
|
|
|
362
305
|
if (!isStr)
|
|
363
306
|
addons = transformed;
|
|
@@ -380,22 +323,21 @@ const transform = currify((dir, linterOptions, options, t, name, transformed = n
|
|
|
380
323
|
writeFixture({
|
|
381
324
|
full,
|
|
382
325
|
code,
|
|
383
|
-
|
|
384
|
-
currentExt,
|
|
326
|
+
extension,
|
|
385
327
|
});
|
|
386
328
|
return t.pass('fixed fixture updated');
|
|
387
329
|
}
|
|
388
330
|
|
|
389
|
-
const [output] = isStr ? [transformed] : readFixture(`${full}-fix`,
|
|
331
|
+
const [output] = isStr ? [transformed] : readFixture(`${full}-fix`, extension);
|
|
390
332
|
|
|
391
333
|
return t.equal(code, output);
|
|
392
334
|
});
|
|
393
335
|
|
|
394
336
|
const transformWithOptions = currify((dir, linterOptions, options, t, name, pluginOptions) => {
|
|
395
|
-
const {lint,
|
|
337
|
+
const {lint, extension} = linterOptions;
|
|
396
338
|
|
|
397
339
|
const full = join(dir, name);
|
|
398
|
-
const [input, isTS
|
|
340
|
+
const [input, isTS] = readFixture(full, extension);
|
|
399
341
|
|
|
400
342
|
const rule = parseRule(options);
|
|
401
343
|
|
|
@@ -413,12 +355,12 @@ const transformWithOptions = currify((dir, linterOptions, options, t, name, plug
|
|
|
413
355
|
writeFixture({
|
|
414
356
|
full,
|
|
415
357
|
code,
|
|
416
|
-
|
|
358
|
+
extension,
|
|
417
359
|
});
|
|
418
360
|
return t.pass('fixed fixture updated');
|
|
419
361
|
}
|
|
420
362
|
|
|
421
|
-
const [output] = readFixture(`${full}-fix`,
|
|
363
|
+
const [output] = readFixture(`${full}-fix`, extension);
|
|
422
364
|
|
|
423
365
|
return t.equal(code, output);
|
|
424
366
|
});
|
|
@@ -430,9 +372,9 @@ const parseRule = ({plugins}) => {
|
|
|
430
372
|
};
|
|
431
373
|
|
|
432
374
|
const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
|
|
433
|
-
const {lint,
|
|
375
|
+
const {lint, extension} = linterOptions;
|
|
434
376
|
const full = join(dir, name);
|
|
435
|
-
const [input, isTS
|
|
377
|
+
const [input, isTS] = readFixture(full, extension);
|
|
436
378
|
|
|
437
379
|
rmFixture(`${full}-fix`);
|
|
438
380
|
|
|
@@ -448,11 +390,10 @@ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ru
|
|
|
448
390
|
});
|
|
449
391
|
|
|
450
392
|
if (isUpdate()) {
|
|
451
|
-
|
|
393
|
+
writeFixture({
|
|
452
394
|
full,
|
|
453
395
|
code,
|
|
454
|
-
|
|
455
|
-
currentExt,
|
|
396
|
+
extension,
|
|
456
397
|
});
|
|
457
398
|
|
|
458
399
|
return t.pass('source fixture updated');
|
|
@@ -462,14 +403,14 @@ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ru
|
|
|
462
403
|
});
|
|
463
404
|
|
|
464
405
|
const noTransform = currify((dir, linterOptions, options, t, name, addons = {}) => {
|
|
465
|
-
const {lint,
|
|
406
|
+
const {lint, extension} = linterOptions;
|
|
466
407
|
const full = join(dir, name);
|
|
467
|
-
const [fixture] = readFixture(full,
|
|
408
|
+
const [fixture] = readFixture(full, extension);
|
|
468
409
|
|
|
469
410
|
rmFixture(`${full}-fix`);
|
|
470
411
|
|
|
471
412
|
const {plugins} = options;
|
|
472
|
-
const [input, isTS
|
|
413
|
+
const [input, isTS] = readFixture(full, extension);
|
|
473
414
|
|
|
474
415
|
const {code} = lint(input, {
|
|
475
416
|
isTS,
|
|
@@ -481,10 +422,10 @@ const noTransform = currify((dir, linterOptions, options, t, name, addons = {})
|
|
|
481
422
|
});
|
|
482
423
|
|
|
483
424
|
if (isUpdate()) {
|
|
484
|
-
|
|
425
|
+
writeFixture({
|
|
485
426
|
full,
|
|
486
427
|
code,
|
|
487
|
-
|
|
428
|
+
extension,
|
|
488
429
|
});
|
|
489
430
|
|
|
490
431
|
return t.pass('source fixture updated');
|
|
@@ -513,11 +454,11 @@ const noTransformCode = currify((linterOptions, options, t, input) => {
|
|
|
513
454
|
const getMessage = ({message}) => message;
|
|
514
455
|
|
|
515
456
|
const report = (dir, linterOptions, options) => (t) => (name, message, plugins) => {
|
|
516
|
-
const {lint,
|
|
457
|
+
const {lint, extension} = linterOptions;
|
|
517
458
|
checkReport(name, message);
|
|
518
459
|
|
|
519
460
|
const full = join(dir, name);
|
|
520
|
-
const [source, isTS] = readFixture(full,
|
|
461
|
+
const [source, isTS] = readFixture(full, extension);
|
|
521
462
|
|
|
522
463
|
const addT = reportCode(lint, {
|
|
523
464
|
isTS,
|
|
@@ -530,9 +471,9 @@ const report = (dir, linterOptions, options) => (t) => (name, message, plugins)
|
|
|
530
471
|
};
|
|
531
472
|
|
|
532
473
|
const noReport = currify((dir, linterOptions, options, t, name) => {
|
|
533
|
-
const {lint,
|
|
474
|
+
const {lint, extension} = linterOptions;
|
|
534
475
|
const full = join(dir, name);
|
|
535
|
-
const [source, isTS] = readFixture(full,
|
|
476
|
+
const [source, isTS] = readFixture(full, extension);
|
|
536
477
|
|
|
537
478
|
rmFixture(`${full}-fix`);
|
|
538
479
|
|
|
@@ -545,9 +486,9 @@ const noReport = currify((dir, linterOptions, options, t, name) => {
|
|
|
545
486
|
module.exports._createNoReport = noReport;
|
|
546
487
|
|
|
547
488
|
const noReportAfterTransform = currify((dir, linterOptions, options, t, name, addons = {}) => {
|
|
548
|
-
const {lint,
|
|
489
|
+
const {lint, extension} = linterOptions;
|
|
549
490
|
const full = join(dir, name);
|
|
550
|
-
const [source, isTS] = readFixture(full,
|
|
491
|
+
const [source, isTS] = readFixture(full, extension);
|
|
551
492
|
|
|
552
493
|
return noReportCodeAfterTransform(lint, {
|
|
553
494
|
isTS,
|
|
@@ -558,9 +499,9 @@ const noReportAfterTransform = currify((dir, linterOptions, options, t, name, ad
|
|
|
558
499
|
module.exports._createNoReportAfterTransform = noReportAfterTransform;
|
|
559
500
|
|
|
560
501
|
const noReportAfterTransformWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
|
|
561
|
-
const {lint,
|
|
502
|
+
const {lint, extension} = linterOptions;
|
|
562
503
|
const full = join(dir, name);
|
|
563
|
-
const [source, isTS] = readFixture(full,
|
|
504
|
+
const [source, isTS] = readFixture(full, extension);
|
|
564
505
|
const rule = parseRule(options);
|
|
565
506
|
|
|
566
507
|
const rules = {
|
|
@@ -580,9 +521,9 @@ const noReportAfterTransformWithOptions = currify((dir, linterOptions, options,
|
|
|
580
521
|
module.exports._createNoReportAfterTransformWithOptions = noReportAfterTransformWithOptions;
|
|
581
522
|
|
|
582
523
|
const reportWithOptions = currify((dir, linterOptions, options, t, name, message, ruleOptions) => {
|
|
583
|
-
const {lint,
|
|
524
|
+
const {lint, extension} = linterOptions;
|
|
584
525
|
const full = join(dir, name);
|
|
585
|
-
const [source, isTS] = readFixture(full,
|
|
526
|
+
const [source, isTS] = readFixture(full, extension);
|
|
586
527
|
|
|
587
528
|
const rule = parseRule(options);
|
|
588
529
|
|
|
@@ -602,9 +543,9 @@ const reportWithOptions = currify((dir, linterOptions, options, t, name, message
|
|
|
602
543
|
});
|
|
603
544
|
|
|
604
545
|
const noReportWithOptions = currify((dir, linterOptions, options, t, name, ruleOptions) => {
|
|
605
|
-
const {lint,
|
|
546
|
+
const {lint, extension} = linterOptions;
|
|
606
547
|
const full = join(dir, name);
|
|
607
|
-
const [source, isTS] = readFixture(full,
|
|
548
|
+
const [source, isTS] = readFixture(full, extension);
|
|
608
549
|
|
|
609
550
|
rmFixture(`${full}-fix`);
|
|
610
551
|
|