Skip to content

Commit

Permalink
fix(merge-reports): move only exists content
Browse files Browse the repository at this point in the history
* move files/dirs from 1st source report to destination report
* do not move data.js file
  • Loading branch information
DudaGod committed Sep 12, 2018
1 parent a6bc549 commit 771a983
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
20 changes: 16 additions & 4 deletions lib/merge-reports/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ module.exports = class ReportBuilder {
}

async build() {
await this._copyToReportDir(
['images', 'index.html', 'report.min.js', 'report.min.css'],
{from: this.srcPaths[0], to: this.destPath}
);
await moveContentToReportDir({from: this.srcPaths[0], to: this.destPath});

const srcReportsData = this._loadReportsData();
const dataTree = DataTree.create(srcReportsData[0], this.destPath);
Expand Down Expand Up @@ -64,3 +61,18 @@ module.exports = class ReportBuilder {
await fs.writeFile(destDataPath, formattedData);
}
};

async function moveContentToReportDir({from, to}) {
const files = await fs.readdirAsync(path.resolve(from));

await Promise.map(files, async (fileName) => {
if (fileName === 'data.js') {
return;
}

const srcFilePath = path.resolve(from, fileName);
const destFilePath = path.resolve(to, fileName);

await fs.moveAsync(srcFilePath, destFilePath, {overwrite: true});
});
}
25 changes: 14 additions & 11 deletions test/lib/merge-reports/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,34 @@ describe('lib/merge-reports/report-builder', () => {
sandbox.stub(serverUtils.logger, 'warn');
sandbox.stub(fs, 'moveAsync');
sandbox.stub(fs, 'writeFile');
sandbox.stub(fs, 'readdirAsync').resolves([]);

sandbox.stub(DataTree, 'create').returns(Object.create(DataTree.prototype));
sandbox.stub(DataTree.prototype, 'mergeWith').resolves();
});

afterEach(() => sandbox.restore());

it('should move "images" folder from first source report to destination report', async () => {
const srcFilePath = path.resolve('src-report/path-1', 'images');
const destFilePath = path.resolve('dest-report/path', 'images');
it('should move contents of first source report to destination report', async () => {
fs.readdirAsync.resolves(['file-path']);

const srcFilePath = path.resolve('src-report/path-1', 'file-path');
const destFilePath = path.resolve('dest-report/path', 'file-path');

await buildReport_(['src-report/path-1', 'src-report/path-2'], 'dest-report/path');

assert.calledWith(fs.moveAsync, srcFilePath, destFilePath);
assert.calledWith(fs.moveAsync, srcFilePath, destFilePath, {overwrite: true});
});

['index.html', 'report.min.js', 'report.min.css'].forEach((fileName) => {
it(`should move "${fileName}" file from first source report to destination report`, async () => {
const srcFilePath = path.resolve('src-report/path-1', fileName);
const destFilePath = path.resolve('dest-report/path', fileName);
it('should not move "data.js" file from first source report to destinatino report', async () => {
fs.readdirAsync.resolves(['file-path', 'data.js']);

const srcDataPath = path.resolve('src-report/path-1', 'data.js');
const destPath = path.resolve('dest-report/path');

await buildReport_(['src-report/path-1', 'src-report/path-2'], 'dest-report/path');
await buildReport_(['src-report/path-1', 'src-report/path-2'], 'dest-report/path');

assert.calledWith(fs.moveAsync, srcFilePath, destFilePath);
});
assert.neverCalledWith(fs.moveAsync, srcDataPath, destPath);
});

it('should not fail if data file does not find in source report path', async () => {
Expand Down

0 comments on commit 771a983

Please sign in to comment.