Skip to content

Commit 2aedfea

Browse files
authored
Merge pull request #120 from gemini-testing/fix/output-to-file-path
fix: the output to file path on 'before all' hook
2 parents 71ba589 + 1378e75 commit 2aedfea

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/reporters/flat.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ const ICON_FAIL = chalk.red('\u2718');
1414
const ICON_WARN = chalk.bold.yellow('!');
1515
const ICON_RETRY = chalk.yellow('⟳');
1616

17-
const getSkipReason = (test, skipReason) => test && (getSkipReason(test.parent) || test.skipReason) || skipReason;
18-
19-
const getRelativeFilePath = (file) => {
20-
return file ? path.relative(process.cwd(), file) : 'undefined';
21-
};
17+
const getSkipReason = (test) => test && (getSkipReason(test.parent) || test.skipReason);
18+
const getFilePath = (test) => test && test.file || getFilePath(test.parent);
19+
const getRelativeFilePath = (file) => file ? path.relative(process.cwd(), file) : undefined;
2220

2321
module.exports = class FlatReporter {
2422
constructor() {
@@ -146,12 +144,13 @@ module.exports = class FlatReporter {
146144
}
147145

148146
static _getTestInfo(test) {
147+
const file = getFilePath(test);
148+
149149
return {
150150
title: test.fullTitle(),
151151
browser: test.browserId,
152-
file: getRelativeFilePath(test.file),
152+
file: getRelativeFilePath(file),
153153
error: test.err ? (test.err.stack || test.err.message || test.err) : undefined
154154
};
155155
}
156-
157156
};

test/lib/reporter/flat.js

+15
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,21 @@ describe('Flat reporter', () => {
228228
assert.include(stdout, test.file);
229229
});
230230

231+
it('should log path to file of failed hook', () => {
232+
test = mkTestStub_({
233+
file: null,
234+
parent: {
235+
file: 'path-to-test'
236+
}
237+
});
238+
239+
sandbox.stub(path, 'relative').returns(`relative/${test.parent.file}`);
240+
241+
emit(RunnerEvents.TEST_FAIL, test);
242+
243+
assert.include(stdout, 'relative/path-to-test');
244+
});
245+
231246
it('should log browser of failed suite', () => {
232247
test = mkTestStub_({
233248
browserId: 'bro1'

0 commit comments

Comments
 (0)