-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reporting): output steps as metadata
steps and failure index are added to the metadata of the step, and the reporter from testcafe has been rewired to use a custom version of spec by default re #48
- Loading branch information
Showing
11 changed files
with
587 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ node_modules/ | |
package-lock.json | ||
.history | ||
.yarn/cache | ||
.DS_Store | ||
.yarn/install-state.gz | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require('./rewire-compiler'); | ||
require('./rewire-argument-parser'); | ||
require('./rewire-reporter'); | ||
|
||
require('testcafe/lib/cli/cli'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require('./rewire-compiler'); | ||
require('./rewire-runner'); | ||
require('./rewire-reporter'); | ||
|
||
module.exports = require('testcafe'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { existsSync } = require('fs'); | ||
const { join } = require('path'); | ||
const { GeneralError } = require('testcafe/lib/errors/runtime'); | ||
const { RUNTIME_ERRORS } = require('testcafe/lib/errors/types'); | ||
const TestcafeReporter = require('testcafe/lib/reporter'); | ||
|
||
const isReporterPluginFactory = (value) => { | ||
return typeof value === 'function'; | ||
}; | ||
|
||
const requireReporterPluginFactory = (reporterName) => { | ||
try { | ||
const gherkinReporterPath = join(__dirname, 'reporters', reporterName); | ||
return reporterName.includes('gtc-reporter') && existsSync(gherkinReporterPath.concat('.js')) | ||
? require(gherkinReporterPath) | ||
: require('testcafe-reporter-' + reporterName); | ||
} catch (err) { | ||
throw new GeneralError(RUNTIME_ERRORS.cannotFindReporterForAlias, reporterName); | ||
} | ||
}; | ||
|
||
const getPluginFactory = (reporterFactorySource) => { | ||
if (!isReporterPluginFactory(reporterFactorySource)) { | ||
return requireReporterPluginFactory(reporterFactorySource); | ||
} | ||
return reporterFactorySource; | ||
}; | ||
|
||
const processReporterName = (value) => { | ||
if (isReporterPluginFactory(value)) return value.name || 'function () {}'; | ||
|
||
return value; | ||
}; | ||
|
||
TestcafeReporter._addDefaultReporter = function (reporters) { | ||
reporters.push({ | ||
name: 'gtc-reporter-spec', | ||
output: process.stdout, | ||
}); | ||
}; | ||
|
||
TestcafeReporter.getReporterPlugins = function (reporters = []) { | ||
if (!reporters.length) { | ||
TestcafeReporter._addDefaultReporter(reporters); | ||
} | ||
return Promise.all( | ||
reporters.map(async ({ name, output, options }) => { | ||
const pluginFactory = getPluginFactory(name); | ||
const processedName = processReporterName(name); | ||
const outStream = output ? await TestcafeReporter._ensureOutStream(output) : void 0; | ||
return { | ||
plugin: pluginFactory(options), | ||
name: processedName, | ||
outStream, | ||
}; | ||
}) | ||
); | ||
}; | ||
|
||
module.exports = TestcafeReporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
const _renderErrors = function (errs) { | ||
this.setIndent(3).newline(); | ||
|
||
errs.forEach((err, idx) => { | ||
var prefix = this.chalk.red(`${idx + 1}) `); | ||
|
||
this.newline().write(this.formatError(err, prefix)).newline().newline(); | ||
}); | ||
}; | ||
|
||
const _renderWarnings = function (warnings) { | ||
this.newline() | ||
.setIndent(1) | ||
.write(this.chalk.bold.yellow(`Warnings (${warnings.length}):`)) | ||
.newline(); | ||
|
||
warnings.forEach((msg) => { | ||
this.setIndent(1).write(this.chalk.bold.yellow(`--`)).newline().setIndent(2).write(msg).newline(); | ||
}); | ||
}; | ||
|
||
const reportTaskStart = function (startTime, userAgents, testCount) { | ||
this.startTime = startTime; | ||
this.testCount = testCount; | ||
|
||
this.setIndent(1).useWordWrap(true).write(this.chalk.bold('Running tests in:')).newline(); | ||
|
||
userAgents.forEach((ua) => { | ||
this.write(`- ${this.chalk.blue(ua)}`).newline(); | ||
}); | ||
|
||
this.newline(); | ||
}; | ||
|
||
const reportFixtureStart = function (name) { | ||
this.currentFixtureName = name; | ||
}; | ||
|
||
const reportTestDone = function (name, testRunInfo, meta) { | ||
const hasErr = !!testRunInfo.errs.length; | ||
let symbol = null; | ||
let nameStyle = null; | ||
|
||
if (testRunInfo.skipped) { | ||
this.skipped++; | ||
|
||
symbol = this.chalk.cyan('-'); | ||
nameStyle = this.chalk.cyan; | ||
} else if (hasErr) { | ||
symbol = this.chalk.red.bold(this.symbols.err); | ||
nameStyle = this.chalk.red.bold; | ||
} else { | ||
symbol = this.chalk.green(this.symbols.ok); | ||
nameStyle = this.chalk.grey; | ||
} | ||
|
||
name = `${this.currentFixtureName} - ${name}`; | ||
|
||
let title = `${symbol} ${nameStyle(name)}`; | ||
|
||
if (testRunInfo.unstable) { | ||
title = title.concat(this.chalk.yellow(' (unstable)')); | ||
} | ||
|
||
if (testRunInfo.screenshotPath) { | ||
title = title.concat(` (screenshots: ${this.chalk.grey.underline(testRunInfo.screenshotPath)})`); | ||
} | ||
|
||
this.setIndent(1).useWordWrap(true).write(title); | ||
|
||
if (hasErr) { | ||
this.setIndent(2).useWordWrap(true); | ||
const keywords = { Context: 'Given ', Action: 'When ', Outcome: 'Then ' }; | ||
meta.steps | ||
.map((step) => keywords[step.type].concat(step.text)) | ||
.forEach((phrase, index) => { | ||
let color; | ||
let symbol; | ||
if (index < meta.failIndex) { | ||
color = 'green'; | ||
symbol = this.symbols.ok; | ||
} else if (index === meta.failIndex) { | ||
color = 'red'; | ||
symbol = this.symbols.err; | ||
} else { | ||
color = 'grey'; | ||
symbol = '-'; | ||
} | ||
this.write(this.chalk[color](symbol, phrase)); | ||
this.newline(); | ||
}); | ||
this._renderErrors(testRunInfo.errs); | ||
} | ||
|
||
this.afterErrList = hasErr; | ||
|
||
this.newline(); | ||
}; | ||
|
||
const reportTaskDone = function (endTime, passed, warnings) { | ||
var durationMs = endTime - this.startTime; | ||
var durationStr = this.moment.duration(durationMs).format('h[h] mm[m] ss[s]'); | ||
var footer = | ||
passed === this.testCount | ||
? this.chalk.bold.green(`${this.testCount} passed`) | ||
: this.chalk.bold.red(`${this.testCount - passed}/${this.testCount} failed`); | ||
|
||
footer += this.chalk.gray(` (${durationStr})`); | ||
|
||
this.setIndent(1).useWordWrap(true); | ||
|
||
if (!this.afterErrList) this.newline(); | ||
|
||
this.newline().write(footer).newline(); | ||
|
||
if (this.skipped > 0) { | ||
this.write(this.chalk.cyan(`${this.skipped} skipped`)).newline(); | ||
} | ||
|
||
if (warnings.length) this._renderWarnings(warnings); | ||
}; | ||
|
||
module.exports = () => { | ||
return { | ||
noColors: false, | ||
startTime: null, | ||
afterErrList: false, | ||
currentFixtureName: null, | ||
testCount: 0, | ||
skipped: 0, | ||
reportTaskStart, | ||
reportFixtureStart, | ||
reportTestDone, | ||
reportTaskDone, | ||
_renderErrors, | ||
_renderWarnings, | ||
}; | ||
}; |
Oops, something went wrong.