Skip to content

Commit 0b686ec

Browse files
committed
feature: @putout/engine-reporter: get rid of mock-require
1 parent e899de3 commit 0b686ec

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

packages/engine-reporter/lib/formatter/formatter.cjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const {simpleImport} = require('putout/simple-import');
4-
const {createAsyncLoader} = require('@putout/engine-loader');
3+
const {simpleImport: _simpleImport} = require('putout/simple-import');
4+
const {createAsyncLoader: _createAsyncLoader} = require('@putout/engine-loader');
55

66
const tryToCatch = require('try-to-catch');
77
const {
@@ -12,7 +12,12 @@ const {
1212
const {isArray} = Array;
1313
const maybeArray = (a) => isArray(a) ? a : [a, {}];
1414

15-
module.exports.getFormatter = async (formatterOptional, exit) => {
15+
module.exports.getFormatter = async (formatterOptional, exit, overrides = {}) => {
16+
const {
17+
createAsyncLoader = _createAsyncLoader,
18+
simpleImport = _simpleImport,
19+
} = overrides;
20+
1621
const [formatterName = 'none', formatterOptions] = maybeArray(formatterOptional);
1722
const loadFormatter = createAsyncLoader('formatter');
1823

packages/engine-reporter/lib/formatter/formatter.spec.cjs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const {test, stub} = require('supertape');
4-
const mockRequire = require('mock-require');
54

65
const {
76
NO_FORMATTER,
@@ -10,8 +9,6 @@ const {
109

1110
const {getFormatter} = require('./formatter.cjs');
1211

13-
const {reRequire, stopAll} = mockRequire;
14-
1512
test('putout: cli: formatter: get formatter', async (t) => {
1613
const exit = stub();
1714

@@ -53,15 +50,10 @@ test('putout: cli: formatter: get formatter: options', async (t) => {
5350

5451
test('putout: cli: formatter: get reporter: exit: NO_FORMATTER', async (t) => {
5552
const exit = stub();
56-
const {getFormatter} = reRequire('./formatter.cjs');
57-
5853
await getFormatter('xxx', exit);
5954

6055
const expected = [NO_FORMATTER, Error(`Cannot find package 'putout-formatter-xxx'`)];
6156

62-
stopAll();
63-
reRequire('./formatter.cjs');
64-
6557
t.calledWith(exit, expected, 'should call exit');
6658
t.end();
6759
});
@@ -70,18 +62,12 @@ test('putout: cli: formatter: get reporter: exit: CANNOT_LOAD_FORMATTER', async
7062
const exit = stub();
7163
const createAsyncLoader = stub().returns(stub().rejects(Error('@putout/formatter-xxx: Syntax error')));
7264

73-
mockRequire('@putout/engine-loader', {
65+
await getFormatter('xxx', exit, {
7466
createAsyncLoader,
7567
});
7668

77-
const {getFormatter} = reRequire('./formatter.cjs');
78-
await getFormatter('xxx', exit);
79-
8069
const expected = [CANNOT_LOAD_FORMATTER, Error(`@putout/formatter-xxx: Syntax error`)];
8170

82-
stopAll();
83-
reRequire('./formatter.cjs');
84-
8571
t.calledWith(exit, expected, 'should call exit');
8672
t.end();
8773
});
@@ -90,18 +76,12 @@ test('putout: cli: formatter: get reporter: pass load', async (t) => {
9076
const exit = stub();
9177
const simpleImport = stub().rejects(Error('simple import'));
9278

93-
mockRequire('putout/simple-import', {
79+
await getFormatter('xxx', exit, {
9480
simpleImport,
9581
});
9682

97-
const {getFormatter} = reRequire('./formatter.cjs');
98-
await getFormatter('xxx', exit);
99-
10083
const expected = [CANNOT_LOAD_FORMATTER, Error(`@putout/formatter-xxx: simple import`)];
10184

102-
stopAll();
103-
reRequire('./formatter.cjs');
104-
10585
t.calledWith(exit, expected, 'should call exit');
10686
t.end();
10787
});

packages/engine-reporter/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"eslint-plugin-n": "^17.0.0",
5050
"eslint-plugin-putout": "^29.0.0",
5151
"madrun": "^11.0.0",
52-
"mock-require": "^3.0.3",
5352
"montag": "^1.0.0",
5453
"nodemon": "^3.0.1",
5554
"supertape": "^11.0.3"

0 commit comments

Comments
 (0)