Skip to content

Commit 97ee231

Browse files
authored
fix: do not throw when trying to merge single report (#661)
* fix: do not throw when trying to merge single report
1 parent ee266a0 commit 97ee231

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/merge-reports/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function validateOpts({srcPaths, destPath, headers}) {
6868
}
6969

7070
if (srcPaths.length === 1) {
71-
throw new Error(`Nothing to merge, only one source report is passed: ${srcPaths[0]}`);
71+
console.warn(`Only one source report is passed: ${srcPaths[0]}, which is usually not what you want. Now, a copy of source report will just be created.`);
7272
}
7373

7474
if (srcPaths.includes(destPath)) {

test/unit/lib/merge-reports/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {IMAGES_PATH, SNAPSHOTS_PATH, ERROR_DETAILS_PATH, LOCAL_DATABASE_NAME, DAT
1010

1111
describe('lib/merge-reports', () => {
1212
const sandbox = sinon.sandbox.create();
13-
let htmlReporter, serverUtils, mergeReports, axiosStub;
13+
let htmlReporter, serverUtils, mergeReports, axiosStub, consoleWarnBackup;
1414

1515
const execMergeReports_ = async ({toolAdapter = stubToolAdapter(), paths = [], opts = {}}) => {
1616
opts = _.defaults(opts, {destination: 'default-dest-report/path'});
@@ -19,6 +19,9 @@ describe('lib/merge-reports', () => {
1919
};
2020

2121
beforeEach(() => {
22+
consoleWarnBackup = console.warn;
23+
console.warn = sandbox.stub();
24+
2225
serverUtils = _.clone(originalServerUtils);
2326
axiosStub = {get: sandbox.stub().rejects()};
2427

@@ -42,7 +45,10 @@ describe('lib/merge-reports', () => {
4245
});
4346
});
4447

45-
afterEach(() => sandbox.restore());
48+
afterEach(() => {
49+
console.warn = consoleWarnBackup;
50+
sandbox.restore();
51+
});
4652

4753
describe('options validation', () => {
4854
describe('should throw error if', () => {
@@ -53,13 +59,6 @@ describe('lib/merge-reports', () => {
5359
);
5460
});
5561

56-
it('only one source report path is specified', async () => {
57-
await assert.isRejected(
58-
execMergeReports_({paths: ['src-report/path']}),
59-
'Nothing to merge, only one source report is passed: src-report/path'
60-
);
61-
});
62-
6362
it('destination report path exists in passed source reports paths', async () => {
6463
await assert.isRejected(
6564
execMergeReports_({
@@ -141,6 +140,17 @@ describe('lib/merge-reports', () => {
141140
);
142141
});
143142
});
143+
144+
describe('should warn if', () => {
145+
it('only one source report path is specified', async () => {
146+
await execMergeReports_({paths: ['src-report/path'], opts: {destPath: 'dest-report/path', headers: []}});
147+
148+
assert.calledWithMatch(
149+
console.warn,
150+
/Only one source report is passed/
151+
);
152+
});
153+
});
144154
});
145155

146156
describe('should send headers to request json urls', () => {

0 commit comments

Comments
 (0)