Skip to content

Commit ab025e1

Browse files
committed
feature: @putout/test: add ability to extend with operators
1 parent db34b60 commit ab025e1

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

packages/test/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ const test = createTest(import.meta.url, {
7070
});
7171
```
7272
73+
And apply new [operators](https://github.com/coderaiser/supertape?tab=readme-ov-file#operators):
74+
75+
```js
76+
const test = createTest(import.meta.url, {
77+
extension: 'wast',
78+
lint: putout,
79+
plugins: [
80+
['remove-unused-variables', rmVars],
81+
],
82+
}, {
83+
render: (operator) => (name) => operator.transform,
84+
});
85+
```
86+
7387
### `report(filename, message: string | string[], plugins?: PutoutPlugin[])`
7488
7589
Check error message (or messages) of a plugin:

packages/test/lib/pre-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module.exports.preTest = function preTest(test, plugin) {
3030
scan,
3131
}] = maybeEntries(plugin);
3232

33+
if (isArray(plugin)) {}
34+
3335
const options = {
3436
checkDuplicates: false,
3537
};

packages/test/lib/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ const parsePlugin = (plugins) => {
6565
return plugins;
6666
};
6767

68-
function createTest(dir, maybeOptions) {
68+
function createTest(dir, maybeOptions, maybeExtends = {}) {
6969
dir = join(dir, 'fixture');
7070

7171
const {
72-
extension = [],
72+
extension = '',
7373
lint = putout,
7474
...options
7575
} = parseOptions(maybeOptions);
@@ -106,6 +106,7 @@ function createTest(dir, maybeOptions) {
106106
format: format(dir, options),
107107
formatMany: formatMany(dir, options),
108108
noFormat: noFormat(dir, options),
109+
...maybeExtends,
109110
});
110111
}
111112

@@ -211,7 +212,6 @@ const transformWithOptions = currify((dir, linterOptions, options, t, name, plug
211212
const [input, isTS, currentExtension] = readFixture(full, extension);
212213

213214
const rule = parseRule(options);
214-
215215
const rules = {
216216
[rule]: ['on', pluginOptions],
217217
};

packages/test/lib/test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import create from './test.js';
44

55
export default create;
66

7-
export const createTest = (url, plugins) => {
7+
export const createTest = (url, plugins, maybeExtends) => {
88
const __filename = fileURLToPath(url);
99
const __dirname = dirname(__filename);
1010

11-
return create(__dirname, plugins);
11+
return create(__dirname, plugins, maybeExtends);
1212
};

packages/test/test/extends.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as removeUnusedVariables from '@putout/plugin-remove-unused-variables';
2+
import {createTest} from '../lib/test.mjs';
3+
4+
const plugins = {
5+
removeUnusedVariables,
6+
};
7+
8+
const test = createTest(import.meta.url, plugins, {
9+
render: (operator) => () => operator.equal(1, 1),
10+
});
11+
12+
test('test: extends', (t) => {
13+
t.render(1, 1);
14+
t.end();
15+
});

0 commit comments

Comments
 (0)