Skip to content

Commit

Permalink
fix(server-utils): fix empty directories creation in project root (#393)
Browse files Browse the repository at this point in the history
test(server-utils): update test for copyFileAsync

refactor(server-utils): simplify test for copyFileAsync

Co-authored-by: Mikhail Smyslov <musmyslov@yandex-team.ru>
  • Loading branch information
mikhailsmyslov and Mikhail Smyslov authored Aug 17, 2021
1 parent 4aad970 commit 355c941
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/server-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function createPath(kind, result, stateName) {
}

function copyFileAsync(srcPath, destPath, reportDir = '') {
return makeDirFor(destPath)
.then(() => fs.copy(srcPath, path.resolve(reportDir, destPath)));
const resolvedDestPath = path.resolve(reportDir, destPath);
return makeDirFor(resolvedDestPath).then(() => fs.copy(srcPath, resolvedDestPath));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions test/unit/lib/server-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ describe('server-utils', () => {
});

it('should create directory and copy image', () => {
const fromPath = '/from/image.png',
toPath = '/to/image.png';
const fromPath = '/from/image.png';
const toPath = 'to/image.png';
const pathToReport = '/report-dir';

return utils.copyFileAsync(fromPath, toPath)
return utils.copyFileAsync(fromPath, toPath, pathToReport)
.then(() => {
assert.calledWithMatch(fs.mkdirs, '/to');
assert.calledWith(fs.mkdirs, '/report-dir/to');
assert.calledWithMatch(fs.copy, fromPath, toPath);
});
});
Expand Down

0 comments on commit 355c941

Please sign in to comment.