Skip to content

Commit 9257511

Browse files
authored
Screenshots path correction (#2049)
* fix screenshotOutputFolder's absolute path resolving * fix screenshotOnFail's mocha dir absolute path resolving
1 parent 3cbe027 commit 9257511

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

lib/plugin/screenshotOnFail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = function (config) {
9999
try {
100100
if (options.reportDir) {
101101
fileName = path.join(options.reportDir, fileName);
102-
const mochaReportDir = path.join(process.cwd(), options.reportDir);
102+
const mochaReportDir = path.resolve(process.cwd(), options.reportDir);
103103
if (!fileExists(mochaReportDir)) {
104104
fs.mkdirSync(mochaReportDir);
105105
}

lib/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,17 @@ module.exports.deleteDir = function (dir_path) {
270270
}
271271
};
272272

273+
/**
274+
* Returns absolute filename to save screenshot.
275+
* @param fileName {string} - filename.
276+
*/
273277
module.exports.screenshotOutputFolder = function (fileName) {
274278
const fileSep = path.sep;
275279

276280
if (!fileName.includes(fileSep) || fileName.includes('record_')) {
277281
return path.join(global.output_dir, fileName);
278282
}
279-
return path.join(global.codecept_dir, fileName);
283+
return path.resolve(global.codecept_dir, fileName);
280284
};
281285

282286
module.exports.beautify = function (code) {

test/unit/utils_test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,32 @@ describe('utils', () => {
286286
os.platform.restore();
287287
});
288288
});
289+
290+
describe('#screenshotOutputFolder', () => {
291+
let _oldGlobalOutputDir;
292+
let _oldGlobalCodeceptDir;
293+
294+
before(() => {
295+
_oldGlobalOutputDir = global.output_dir;
296+
_oldGlobalCodeceptDir = global.codecept_dir;
297+
298+
global.output_dir = '/Users/someuser/workbase/project1/test_output';
299+
global.codecept_dir = '/Users/someuser/workbase/project1/tests/e2e';
300+
});
301+
302+
after(() => {
303+
global.output_dir = _oldGlobalOutputDir;
304+
global.codecept_dir = _oldGlobalCodeceptDir;
305+
});
306+
307+
it('returns the joined filename for filename only', () => {
308+
const _path = utils.screenshotOutputFolder('screenshot1.failed.png');
309+
_path.should.eql('/Users/someuser/workbase/project1/test_output/screenshot1.failed.png');
310+
});
311+
312+
it('returns the given filename for absolute one', () => {
313+
const _path = utils.screenshotOutputFolder('/Users/someuser/workbase/project1/test_output/screenshot1.failed.png');
314+
_path.should.eql('/Users/someuser/workbase/project1/test_output/screenshot1.failed.png');
315+
});
316+
});
289317
});

0 commit comments

Comments
 (0)