-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: suite metadata for cucumber (#243)
- Loading branch information
1 parent
a5e41b7
commit 0f471ae
Showing
17 changed files
with
685 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
const { getPercentage, getPrettyDuration } = require('../helpers/helper') | ||
|
||
class BasePlatform { | ||
|
||
/** | ||
* @param {string|number} text | ||
*/ | ||
bold(text) { | ||
throw new Error('Not Implemented'); | ||
} | ||
|
||
break() { | ||
throw new Error('Not Implemented'); | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('..').Target} target | ||
* @param {import('test-results-parser').ITestSuite} suite | ||
*/ | ||
getSuiteSummaryText(target, suite) { | ||
const suite_title = this.getSuiteTitle(suite); | ||
const suite_results_text = this.#getSuiteResultsText(suite); | ||
const duration_text = this.#getSuiteDurationText(target, suite); | ||
|
||
const texts = [ | ||
this.bold(suite_title), | ||
this.break(), | ||
this.break(), | ||
suite_results_text, | ||
this.break(), | ||
duration_text, | ||
]; | ||
|
||
const metadata_text = this.getSuiteMetaDataText(suite); | ||
|
||
if (metadata_text) { | ||
texts.push(this.break()); | ||
texts.push(this.break()); | ||
texts.push(metadata_text); | ||
} | ||
|
||
return texts.join(''); | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('test-results-parser').ITestSuite} suite | ||
* @returns {string} | ||
*/ | ||
getSuiteTitle(suite) { | ||
const emoji = suite.status === 'PASS' ? '✅' : suite.total === suite.skipped ? '⏭️' : '❌'; | ||
return `${emoji} ${suite.name}`; | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('test-results-parser').ITestSuite} suite | ||
* @returns {string} | ||
*/ | ||
#getSuiteResultsText(suite) { | ||
const suite_results = this.getSuiteResults(suite); | ||
return `${this.bold('Results')}: ${suite_results}`; | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('test-results-parser').ITestSuite} suite | ||
* @returns {string} | ||
*/ | ||
getSuiteResults(suite) { | ||
return `${suite.passed} / ${suite.total} Passed (${getPercentage(suite.passed, suite.total)}%)`; | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('..').Target} target | ||
* @param {import('test-results-parser').ITestSuite} suite | ||
*/ | ||
#getSuiteDurationText(target, suite) { | ||
const duration = this.getSuiteDuration(target, suite); | ||
return `${this.bold('Duration')}: ${duration}` | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('..').Target} target | ||
* @param {import('test-results-parser').ITestSuite} suite | ||
*/ | ||
getSuiteDuration(target, suite) { | ||
return getPrettyDuration(suite.duration, target.inputs.duration); | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('test-results-parser').ITestSuite} suite | ||
* @returns {string} | ||
*/ | ||
getSuiteMetaDataText(suite) { | ||
if (!suite || !suite.metadata) { | ||
return; | ||
} | ||
|
||
const texts = []; | ||
|
||
if (suite.metadata.platform && suite.metadata.platform.name && suite.metadata.platform.version) { | ||
texts.push(`${suite.metadata.platform.name} ${suite.metadata.platform.version}`) | ||
} | ||
|
||
if (suite.metadata.browser && suite.metadata.browser.name && suite.metadata.browser.version) { | ||
texts.push(`${suite.metadata.browser.name} ${suite.metadata.browser.version}`) | ||
} | ||
|
||
return texts.join(' • '); | ||
} | ||
} | ||
|
||
module.exports = { BasePlatform } |
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,18 @@ | ||
const { BasePlatform } = require("./base.platform"); | ||
|
||
class ChatPlatform extends BasePlatform { | ||
|
||
/** | ||
* @param {string|number} text | ||
*/ | ||
bold(text) { | ||
return `<b>${text}</b>`; | ||
} | ||
|
||
break() { | ||
return '<br>'; | ||
} | ||
|
||
} | ||
|
||
module.exports = { ChatPlatform } |
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,25 @@ | ||
const { TARGET } = require("../helpers/constants"); | ||
const { SlackPlatform } = require('./slack.platform'); | ||
const { TeamsPlatform } = require('./teams.platform'); | ||
const { ChatPlatform } = require('./chat.platform'); | ||
|
||
/** | ||
* | ||
* @param {string} name | ||
*/ | ||
function getPlatform(name) { | ||
switch (name) { | ||
case TARGET.SLACK: | ||
return new SlackPlatform(); | ||
case TARGET.TEAMS: | ||
return new TeamsPlatform(); | ||
case TARGET.CHAT: | ||
return new ChatPlatform(); | ||
default: | ||
throw new Error('Invalid Platform'); | ||
} | ||
} | ||
|
||
module.exports = { | ||
getPlatform | ||
} |
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,17 @@ | ||
const { BasePlatform } = require("./base.platform"); | ||
|
||
class SlackPlatform extends BasePlatform { | ||
|
||
/** | ||
* @param {string|number} text | ||
*/ | ||
bold(text) { | ||
return `*${text}*`; | ||
} | ||
|
||
break() { | ||
return '\n'; | ||
} | ||
} | ||
|
||
module.exports = { SlackPlatform } |
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,16 @@ | ||
const { BasePlatform } = require("./base.platform"); | ||
|
||
class TeamsPlatform extends BasePlatform { | ||
/** | ||
* @param {string|number} text | ||
*/ | ||
bold(text) { | ||
return `**${text}**`; | ||
} | ||
|
||
break() { | ||
return '\n\n'; | ||
} | ||
} | ||
|
||
module.exports = { TeamsPlatform } |
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
Oops, something went wrong.