Skip to content

Commit 9368f41

Browse files
committed
test: @putout/engine-reporter: coverage
1 parent 7c3dd5d commit 9368f41

File tree

6 files changed

+99
-9
lines changed

6 files changed

+99
-9
lines changed

.nycrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
"**/.*.*",
99
"**/scripts",
1010
"**/register.mjs",
11-
"packages/engine-reporter",
11+
"packages/engine-reporter/**/subscribe.*",
1212
"packages/*/coverage",
1313
"packages/*/bin",
1414
"packages/*/test",
15-
"packages/engine-reporter",
1615
"packages/cli-choose/**/keypress*",
1716
"coverage",
1817
"**/eslint.config.js",

packages/engine-reporter/.nycrc.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"test",
88
"coverage",
99
".*.*",
10-
"**/index.js",
1110
"**/subscribe.js",
12-
"**/simple-import.*js",
1311
"**/*.config.*"
1412
],
1513
"branches": 100,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {stub} from 'supertape';
2+
3+
export const chooseFormatter = stub().resolves(['dump']);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {stub} from 'supertape';
2+
3+
export const chooseFormatter = stub().resolves([]);

packages/engine-reporter/lib/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import module from 'node:module';
22
import tryCatch from 'try-catch';
3-
import getOptions from 'putout/cli/get-options';
3+
import _getOptions from 'putout/cli/get-options';
44
import {
55
INTERACTIVE_CANCELED,
66
INVALID_CONFIG,
77
} from 'putout/exit-codes';
8-
import {getFormatter} from './formatter/formatter.cjs';
8+
import {getFormatter as _getFormatter} from './formatter/formatter.cjs';
99
import Report from './report.cjs';
1010

1111
const {createRequire} = module;
@@ -15,7 +15,16 @@ const {dependencies} = require('putout/package.json');
1515

1616
const {keys} = Object;
1717

18-
export const createReport = async ({args, cwd, exit}) => {
18+
export const createReport = async (overrides = {}) => {
19+
const {
20+
args,
21+
cwd,
22+
exit,
23+
getOptions = _getOptions,
24+
cliChooseFormatter = '@putout/cli-choose-formatter',
25+
getFormatter = _getFormatter,
26+
} = overrides;
27+
1928
const {interactive, format} = args;
2029

2130
const report = Report();
@@ -34,7 +43,7 @@ export const createReport = async ({args, cwd, exit}) => {
3443
let newFormatter;
3544

3645
if (interactive) {
37-
const {chooseFormatter} = await import('@putout/cli-choose-formatter');
46+
const {chooseFormatter} = await import(cliChooseFormatter);
3847

3948
[newFormatter] = await chooseFormatter(defaultFormatter, keys(dependencies));
4049

packages/engine-reporter/lib/index.spec.js

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import {test, stub} from 'supertape';
2+
import {
3+
INTERACTIVE_CANCELED,
4+
INVALID_CONFIG,
5+
} from 'putout/exit-codes';
26
import {createReport} from './index.js';
37

48
test('putout: engine-reporter: createReport', async (t) => {
@@ -11,6 +15,80 @@ test('putout: engine-reporter: createReport', async (t) => {
1115
exit,
1216
});
1317

14-
t.calledWith(exit, [12, TypeError('plugins is not iterable')]);
18+
t.calledWith(exit, [INVALID_CONFIG, TypeError('plugins is not iterable')]);
19+
t.end();
20+
});
21+
22+
test('putout: engine-reporter: createReport: interactive', async (t) => {
23+
const interactive = true;
24+
const exit = stub();
25+
const cwd = stub();
26+
const getOptions = stub().returns({});
27+
const cliChooseFormatter = './fixture/cli-choose-formatter.js';
28+
29+
const args = {
30+
interactive,
31+
};
32+
33+
await createReport({
34+
args,
35+
cwd,
36+
exit,
37+
getOptions,
38+
cliChooseFormatter,
39+
});
40+
41+
t.calledWith(exit, [INTERACTIVE_CANCELED]);
42+
t.end();
43+
});
44+
45+
test('putout: engine-reporter: createReport: getFormatter', async (t) => {
46+
const exit = stub();
47+
const cwd = stub();
48+
const getOptions = stub().returns({});
49+
const getFormatter = stub().resolves([]);
50+
const cliChooseFormatter = './fixture/cli-choose-formatter-dump.js';
51+
52+
const args = {
53+
interactive: true,
54+
};
55+
56+
await createReport({
57+
args,
58+
cwd,
59+
exit,
60+
getOptions,
61+
cliChooseFormatter,
62+
getFormatter,
63+
});
64+
65+
t.calledWith(getFormatter, ['dump', exit]);
66+
t.end();
67+
});
68+
69+
test('putout: engine-reporter: createReport: report', async (t) => {
70+
const exit = stub();
71+
const cwd = stub();
72+
const getOptions = stub().returns({});
73+
const format = stub();
74+
const getFormatter = stub().resolves([format]);
75+
const cliChooseFormatter = './fixture/cli-choose-formatter-dump.js';
76+
77+
const args = {};
78+
79+
const report = await createReport({
80+
args,
81+
cwd,
82+
exit,
83+
getOptions,
84+
cliChooseFormatter,
85+
getFormatter,
86+
});
87+
88+
const result = await report({
89+
places: [],
90+
});
91+
92+
t.notOk(result);
1593
t.end();
1694
});

0 commit comments

Comments
 (0)