@putout/test 15.5.0 → 15.6.0
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 +2 -1
- package/lib/fixture.js +6 -5
- package/lib/test.js +18 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Set environment variable `UPDATE=1` to update `transform` and `format` fixtures
|
|
|
21
21
|
UPDATE=1 tape test/*.js
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
When you need to
|
|
24
|
+
When you need to override extension use `UPDATE_EXTENSION`, for example `UPDATE_EXTENSION=abc` will create files with extension 'abc'.
|
|
25
25
|
|
|
26
26
|
## Plugins API
|
|
27
27
|
|
|
@@ -65,6 +65,7 @@ You can also pass extensions to read from `fixture` directory:
|
|
|
65
65
|
```js
|
|
66
66
|
const test = createTest(import.meta.url, {
|
|
67
67
|
extension: 'wast',
|
|
68
|
+
extensionFix: 'wast',
|
|
68
69
|
lint: putout,
|
|
69
70
|
plugins: [
|
|
70
71
|
['remove-unused-variables', rmVars],
|
package/lib/fixture.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import {tryCatch} from 'try-catch';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const {env} = process;
|
|
5
|
+
const isUpdate = () => Boolean(Number(env.UPDATE));
|
|
6
|
+
|
|
5
7
|
const TS = {
|
|
6
8
|
ENABLED: true,
|
|
7
9
|
DISABLED: false,
|
|
8
10
|
};
|
|
9
11
|
|
|
10
|
-
export const readFixture = (name, extension) => {
|
|
12
|
+
export const readFixture = (name, extension, extensionFix = env.UPDATE_EXTENSION) => {
|
|
11
13
|
const {readFileSync} = globalThis.__putout_test_fs;
|
|
12
14
|
const [eTS, dataTS] = tryCatch(readFileSync, `${name}.ts`, 'utf8');
|
|
13
15
|
|
|
@@ -28,14 +30,13 @@ export const readFixture = (name, extension) => {
|
|
|
28
30
|
];
|
|
29
31
|
|
|
30
32
|
if (extension) {
|
|
31
|
-
const {UPDATE_EXTENSION} = process.env;
|
|
32
33
|
const [e, data] = tryCatch(readFileSync, `${name}.${extension}`, 'utf8');
|
|
33
34
|
|
|
34
35
|
if (!e)
|
|
35
36
|
return [
|
|
36
37
|
data,
|
|
37
38
|
TS.DISABLED,
|
|
38
|
-
|
|
39
|
+
extensionFix || extension,
|
|
39
40
|
];
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -68,7 +69,7 @@ export const rmFixture = (name, extension) => {
|
|
|
68
69
|
if (!isUpdate())
|
|
69
70
|
return;
|
|
70
71
|
|
|
72
|
+
tryCatch(unlinkSync, `${name}.${extension}`);
|
|
71
73
|
tryCatch(unlinkSync, `${name}.js`);
|
|
72
74
|
tryCatch(unlinkSync, `${name}.ts`);
|
|
73
|
-
tryCatch(unlinkSync, `${name}.${extension}`);
|
|
74
75
|
};
|
package/lib/test.js
CHANGED
|
@@ -62,6 +62,7 @@ export function createTest(url, maybeOptions, maybeExtends = {}) {
|
|
|
62
62
|
const dir = join(maybeDirectory(url), 'fixture');
|
|
63
63
|
const {
|
|
64
64
|
extension = '',
|
|
65
|
+
extensionFix,
|
|
65
66
|
lint = putout,
|
|
66
67
|
...options
|
|
67
68
|
} = parseOptions(maybeOptions);
|
|
@@ -71,6 +72,7 @@ export function createTest(url, maybeOptions, maybeExtends = {}) {
|
|
|
71
72
|
const linterOptions = {
|
|
72
73
|
lint,
|
|
73
74
|
extension,
|
|
75
|
+
extensionFix,
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
preTest(test, plugin);
|
|
@@ -160,11 +162,16 @@ const progressWithOptions = (dir, options) => (t) => async (name, pluginOptions,
|
|
|
160
162
|
};
|
|
161
163
|
|
|
162
164
|
const transform = currify((dir, linterOptions, options, t, name, transformed = null, addons = {}) => {
|
|
163
|
-
const {
|
|
165
|
+
const {
|
|
166
|
+
lint,
|
|
167
|
+
extension,
|
|
168
|
+
extensionFix,
|
|
169
|
+
} = linterOptions;
|
|
170
|
+
|
|
164
171
|
const {plugins} = options;
|
|
165
172
|
const full = join(dir, name);
|
|
166
173
|
const isStr = isString(transformed);
|
|
167
|
-
const [input, isTS, currentExtension] = readFixture(full, extension);
|
|
174
|
+
const [input, isTS, currentExtension] = readFixture(full, extension, extensionFix);
|
|
168
175
|
|
|
169
176
|
if (!isStr)
|
|
170
177
|
addons = transformed;
|
|
@@ -266,14 +273,19 @@ const noTransformWithOptions = currify((dir, linterOptions, options, t, name, ru
|
|
|
266
273
|
});
|
|
267
274
|
|
|
268
275
|
const noTransform = currify((dir, linterOptions, options, t, name, addons = {}) => {
|
|
269
|
-
const {
|
|
276
|
+
const {
|
|
277
|
+
lint,
|
|
278
|
+
extension,
|
|
279
|
+
extensionFix,
|
|
280
|
+
} = linterOptions;
|
|
281
|
+
|
|
270
282
|
const full = join(dir, name);
|
|
271
|
-
const [
|
|
283
|
+
const [input, isTS, currentExtension] = readFixture(full, extension, extensionFix);
|
|
284
|
+
const [fixture] = readFixture(full, currentExtension);
|
|
272
285
|
|
|
273
|
-
rmFixture(`${full}-fix
|
|
286
|
+
rmFixture(`${full}-fix`, extensionFix);
|
|
274
287
|
|
|
275
288
|
const {plugins} = options;
|
|
276
|
-
const [input, isTS, currentExtension] = readFixture(full, extension);
|
|
277
289
|
|
|
278
290
|
const {code} = lint(input, {
|
|
279
291
|
isTS,
|