Skip to content

Commit 5c9bc3d

Browse files
committed
feature: @putout/cli-process-file: get rid of mock-require
1 parent 8c538f6 commit 5c9bc3d

File tree

3 files changed

+13
-71
lines changed

3 files changed

+13
-71
lines changed

packages/cli-process-file/lib/process-file.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
const process = require('node:process');
44
const tryToCatch = require('try-to-catch');
5-
const eslint = require('@putout/eslint');
5+
const _eslint = require('@putout/eslint');
66
const {parseMatch} = require('putout/parse-match');
77
const {mergeOptions} = require('putout/merge-options');
88
const parseError = require('putout/parse-error');
9-
const {putoutAsync} = require('putout');
9+
const {putoutAsync: _putoutAsync} = require('putout');
1010
const once = require('once');
1111

1212
const {simpleImport: _simpleImport} = require('./simple-import');
@@ -29,6 +29,8 @@ module.exports = ({fix, fixCount, logError, raw}) => async function processFile(
2929
again,
3030
env = getEnv(),
3131
simpleImport = _simpleImport,
32+
eslint = _eslint,
33+
putoutAsync = _putoutAsync,
3234
} = overrides;
3335

3436
const {configurePrinter} = await import('./printer/printer.mjs');

packages/cli-process-file/lib/process-file.spec.js

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
const montag = require('montag');
44
const {test, stub} = require('supertape');
5-
const mockRequire = require('mock-require');
65

76
const parseOptions = require('putout/parse-options');
8-
const putout = require('putout');
7+
98
const processFile = require('./process-file');
109

1110
const {assign} = Object;
1211
const noop = () => {};
13-
const {reRequire, stopAll} = mockRequire;
1412
const {stringify} = JSON;
1513

1614
test('putout: cli: process-file: eslint', async (t) => {
@@ -22,14 +20,10 @@ test('putout: cli: process-file: eslint', async (t) => {
2220
const log = stub();
2321
const write = stub();
2422

25-
mockRequire('@putout/eslint', eslint);
26-
2723
const options = {
2824
dir: '.',
2925
};
3026

31-
const processFile = reRequire('./process-file');
32-
3327
const fn = processFile({
3428
fix,
3529
log,
@@ -42,10 +36,9 @@ test('putout: cli: process-file: eslint', async (t) => {
4236
index: 0,
4337
length: 1,
4438
options,
39+
eslint,
4540
});
4641

47-
stopAll();
48-
4942
const expected = {
5043
code: source,
5144
fix,
@@ -65,14 +58,10 @@ test('putout: cli: process-file: ts from preProcessor', async (t) => {
6558
const log = stub();
6659
const write = stub();
6760

68-
mockRequire('@putout/eslint', eslint);
69-
7061
const options = {
7162
dir: '.',
7263
};
7364

74-
const processFile = reRequire('./process-file');
75-
7665
const fn = processFile({
7766
fix,
7867
log,
@@ -85,10 +74,9 @@ test('putout: cli: process-file: ts from preProcessor', async (t) => {
8574
index: 0,
8675
length: 1,
8776
options,
77+
eslint,
8878
});
8979

90-
stopAll();
91-
9280
const expected = {
9381
code: source,
9482
fix,
@@ -110,8 +98,6 @@ test('putout: cli: process-file: tsx from preProcessor', async (t) => {
11098
dir: '.',
11199
};
112100

113-
const processFile = reRequire('./process-file');
114-
115101
const fn = processFile({
116102
fix,
117103
log,
@@ -156,10 +142,6 @@ test('putout: cli: process-file: options for inner data', async (t) => {
156142
plugins: ['putout-config'],
157143
};
158144

159-
mockRequire('@putout/eslint', eslint);
160-
161-
const processFile = reRequire('./process-file');
162-
163145
const fn = processFile({
164146
fix,
165147
log,
@@ -172,10 +154,9 @@ test('putout: cli: process-file: options for inner data', async (t) => {
172154
index: 0,
173155
length: 1,
174156
options,
157+
eslint,
175158
});
176159

177-
stopAll();
178-
179160
const expected = [{
180161
message: `Use 'String (on/off)' instead of 'Boolean (true/false)'`,
181162
position: {
@@ -223,14 +204,10 @@ test('putout: cli: process-file: ruler', async (t) => {
223204
plugins: ['putout-config'],
224205
};
225206

226-
mockRequire('@putout/eslint', eslint);
227-
228207
const ruler = {
229208
enableAll: true,
230209
};
231210

232-
const processFile = reRequire('./process-file');
233-
234211
const fn = processFile({
235212
fix,
236213
log,
@@ -243,11 +220,10 @@ test('putout: cli: process-file: ruler', async (t) => {
243220
source,
244221
index: 0,
245222
length: 1,
223+
eslint,
246224
options,
247225
});
248226

249-
stopAll();
250-
251227
const expected = [{
252228
message: `Use 'String (on/off)' instead of 'Boolean (true/false)'`,
253229
position: {
@@ -280,16 +256,10 @@ test('putout: cli: process-file: configurePrinter', async (t) => {
280256
const log = stub();
281257
const write = stub();
282258

283-
mockRequire('putout', {
284-
putoutAsync,
285-
});
286-
287259
const options = {
288260
dir: '.',
289261
};
290262

291-
const processFile = reRequire('./process-file');
292-
293263
const fn = processFile({
294264
fix,
295265
log,
@@ -304,10 +274,9 @@ test('putout: cli: process-file: configurePrinter', async (t) => {
304274
length: 1,
305275

306276
source,
277+
putoutAsync,
307278
});
308279

309-
stopAll();
310-
311280
const expected = ['log123("hello")', {
312281
dir: '.',
313282
fix: false,
@@ -342,11 +311,6 @@ test('putout: cli: process-file: configurePrinter: overrides', async (t) => {
342311
const log = stub();
343312
const write = stub();
344313

345-
mockRequire('putout', {
346-
...putout,
347-
putoutAsync,
348-
});
349-
350314
const options = {
351315
dir: '.',
352316
printer: ['putout', {
@@ -356,8 +320,6 @@ test('putout: cli: process-file: configurePrinter: overrides', async (t) => {
356320
}],
357321
};
358322

359-
const processFile = reRequire('./process-file');
360-
361323
const fn = processFile({
362324
fix,
363325
log,
@@ -372,10 +334,9 @@ test('putout: cli: process-file: configurePrinter: overrides', async (t) => {
372334
length: 1,
373335

374336
source,
337+
putoutAsync,
375338
});
376339

377-
stopAll();
378-
379340
const expected = [
380341
source, {
381342
dir: '.',
@@ -408,19 +369,10 @@ test('putout: cli: process-file: plugin not found', async (t) => {
408369
const log = stub();
409370
const write = stub();
410371

411-
mockRequire('putout', {
412-
...putout,
413-
putoutAsync,
414-
});
415-
416372
const options = {
417373
dir: '.',
418374
};
419375

420-
reRequire('@putout/eslint');
421-
422-
const processFile = reRequire('./process-file');
423-
424376
const fn = processFile({
425377
fix,
426378
log,
@@ -435,10 +387,9 @@ test('putout: cli: process-file: plugin not found', async (t) => {
435387
length: 1,
436388

437389
source,
390+
putoutAsync,
438391
});
439392

440-
stopAll();
441-
442393
const expected = {
443394
code: `__putout_processor_yaml({hello: 'world'});`,
444395
places: [{
@@ -734,13 +685,6 @@ test('putout: cli: process-file: recursion: infinite loop', async (t) => {
734685
lint,
735686
});
736687

737-
mockRequire('./simple-import', {
738-
simpleImport,
739-
});
740-
741-
reRequire('putout');
742-
const processFile = reRequire('./process-file');
743-
744688
const fn = processFile({
745689
fix,
746690
log,
@@ -755,6 +699,7 @@ test('putout: cli: process-file: recursion: infinite loop', async (t) => {
755699
options: {
756700
dir: '.',
757701
},
702+
simpleImport,
758703
});
759704

760705
const expected = {
@@ -776,8 +721,6 @@ test('putout: cli: process-file: recursion: infinite loop', async (t) => {
776721
}],
777722
};
778723

779-
stopAll();
780-
781724
t.deepEqual(result, expected);
782725
t.end();
783726
});

packages/cli-process-file/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@
3737
"cli"
3838
],
3939
"devDependencies": {
40-
"@putout/eslint-flat": "^3.0.0",
4140
"@putout/operate": "^13.0.0",
4241
"c8": "^10.0.0",
4342
"eslint": "^9.0.0",
4443
"eslint-plugin-n": "^17.0.0",
4544
"eslint-plugin-putout": "^26.0.0",
4645
"madrun": "^11.0.0",
47-
"mock-import": "^4.2.1",
48-
"mock-require": "^3.0.3",
4946
"montag": "^1.2.1",
5047
"nodemon": "^3.0.1",
5148
"putout": "*",

0 commit comments

Comments
 (0)