Skip to content

Commit

Permalink
Merge pull request #269 from gemini-testing/fix/FEI-12127
Browse files Browse the repository at this point in the history
fix: merge subfolders of reports
  • Loading branch information
xrsd authored Oct 4, 2019
2 parents 88f6e55 + b8ee5db commit bf8e052
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 22 deletions.
25 changes: 16 additions & 9 deletions lib/merge-reports/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ module.exports = class ReportBuilder {
}

async build() {
await moveContentToReportDir({from: this.srcPaths[0], to: this.destPath});
// ignore folder with images as we move them in DataTree._moveImages
await Promise.map(this.srcPaths, async (srcPath) => moveContentToReportDir({
from: srcPath, to: this.destPath, skips: ['data.js', 'images']
}));

const srcReportsData = this._loadReportsData();
const dataTree = DataTree.create(srcReportsData[0], this.destPath);
Expand Down Expand Up @@ -53,17 +56,21 @@ module.exports = class ReportBuilder {
}
};

async function moveContentToReportDir({from, to}) {
async function moveContentToReportDir({from, to, skips = []}) {
const files = await fs.readdir(path.resolve(from));
const filesWithoutSkips = _.isEmpty(skips) ? files : _.difference(files, skips);

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

await Promise.map(filesWithoutSkips, async (fileName) => {
const srcFilePath = path.resolve(from, fileName);
const destFilePath = path.resolve(to, fileName);

await fs.move(srcFilePath, destFilePath, {overwrite: true});
});
const srcFileStat = await fs.stat(srcFilePath);

if (srcFileStat.isDirectory()) {
await fs.ensureDir(destFilePath);
await moveContentToReportDir({from: srcFilePath, to: destFilePath});
} else {
await fs.move(srcFilePath, destFilePath, {overwrite: true});
}
}, {concurrency: 100});
}
55 changes: 42 additions & 13 deletions test/unit/lib/merge-reports/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,62 @@ describe('lib/merge-reports/report-builder', () => {
sandbox.stub(fs, 'move');
sandbox.stub(fs, 'writeFile');
sandbox.stub(fs, 'readdir').resolves([]);
sandbox.stub(fs, 'stat');
sandbox.stub(fs, 'ensureDir');

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

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

it('should move contents of first source report to destination report', async () => {
fs.readdir.resolves(['file-path']);
describe('should move source reports to destination report', () => {
const fsStubReportWithFolder_ = (reportPath, folderPath, filePath) => {
fs.readdir.withArgs(path.resolve(reportPath)).resolves([folderPath]);

const srcFilePath = path.resolve('src-report/path-1', 'file-path');
const destFilePath = path.resolve('dest-report/path', 'file-path');
const folderFullPath = path.resolve(reportPath, folderPath);
fs.readdir.withArgs(folderFullPath).resolves([filePath]);

await buildReport_(['src-report/path-1', 'src-report/path-2'], 'dest-report/path');
fs.stat.withArgs(folderFullPath).resolves({isDirectory: () => true});

assert.calledWith(fs.move, srcFilePath, destFilePath, {overwrite: true});
});
const srcFilePath = path.resolve(reportPath, folderPath, filePath);
fs.stat.withArgs(srcFilePath).resolves({isDirectory: () => false});

it('should not move "data.js" file from first source report to destinatino report', async () => {
fs.readdir.resolves(['file-path', 'data.js']);
return srcFilePath;
};

const srcDataPath = path.resolve('src-report/path-1', 'data.js');
const destPath = path.resolve('dest-report/path');
it('including all subfolders', async () => {
const srcFooFilePath = fsStubReportWithFolder_('foo/src-report', 'folder-path', 'file-path');
const srcBarFilePath = fsStubReportWithFolder_('bar/src-report', 'folder-path', 'file-path');

await buildReport_(['src-report/path-1', 'src-report/path-2'], 'dest-report/path');
const destFilePath = path.resolve('buz/dest-report', 'folder-path', 'file-path');

await buildReport_(['foo/src-report', 'bar/src-report'], 'buz/dest-report');

assert.calledWith(fs.move, srcFooFilePath, destFilePath, {overwrite: true});
assert.calledWith(fs.move, srcBarFilePath, destFilePath, {overwrite: true});
});

it('skipping images folders', async () => {
fsStubReportWithFolder_('foo/src-report', 'images', 'file-path');
fsStubReportWithFolder_('bar/src-report', 'images', 'file-path');

await buildReport_(['foo/src-report', 'bar/src-report'], 'buz/dest-report');

assert.notCalled(fs.move);
});

it('skipping "data.js"', async () => {
fs.readdir.resolves(['file-path', 'data.js']);
fs.stat.resolves({isDirectory: () => false});

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');

assert.neverCalledWith(fs.move, srcDataPath, destPath);
assert.neverCalledWith(fs.move, srcDataPath, destPath);
});
});

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

0 comments on commit bf8e052

Please sign in to comment.