Skip to content

fix base64 issue with cucumberjs 10+ #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions lib/generate-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function generateReport(options) {

if (!options.reportPath) {
throw new Error(
'An output path for the reports should be defined, no path was provided.'
'An output path for the reports should be defined, no path was provided.',
);
}

Expand Down Expand Up @@ -125,27 +125,27 @@ function generateReport(options) {
// Percentages
suite.featureCount.ambiguousPercentage = _calculatePercentage(
suite.featureCount.ambiguous,
suite.featureCount.total
suite.featureCount.total,
);
suite.featureCount.failedPercentage = _calculatePercentage(
suite.featureCount.failed,
suite.featureCount.total
suite.featureCount.total,
);
suite.featureCount.notDefinedPercentage = _calculatePercentage(
suite.featureCount.notDefined,
suite.featureCount.total
suite.featureCount.total,
);
suite.featureCount.pendingPercentage = _calculatePercentage(
suite.featureCount.pending,
suite.featureCount.total
suite.featureCount.total,
);
suite.featureCount.skippedPercentage = _calculatePercentage(
suite.featureCount.skipped,
suite.featureCount.total
suite.featureCount.total,
);
suite.featureCount.passedPercentage = _calculatePercentage(
suite.featureCount.passed,
suite.featureCount.total
suite.featureCount.total,
);

/**
Expand All @@ -164,7 +164,7 @@ function generateReport(options) {
jsonFile.writeFileSync(
path.resolve(reportPath, 'enriched-output.json'),
suite,
{ spaces: 2 }
{ spaces: 2 },
);
}

Expand All @@ -174,13 +174,13 @@ function generateReport(options) {
/* istanbul ignore else */
if (!disableLog) {
console.log(
'\x1b[34m%s\x1b[0m',
`\n
'\x1b[34m%s\x1b[0m',
`\n
=====================================================================================
Multiple Cucumber HTML report generated in:

${path.join(reportPath, INDEX_HTML)}
=====================================================================================\n`
=====================================================================================\n`,
);
}

Expand Down Expand Up @@ -259,51 +259,51 @@ function generateReport(options) {
// Percentages
feature.scenarios.ambiguousPercentage = _calculatePercentage(
feature.scenarios.ambiguous,
feature.scenarios.total
feature.scenarios.total,
);
feature.scenarios.failedPercentage = _calculatePercentage(
feature.scenarios.failed,
feature.scenarios.total
feature.scenarios.total,
);
feature.scenarios.notDefinedPercentage = _calculatePercentage(
feature.scenarios.notDefined,
feature.scenarios.total
feature.scenarios.total,
);
feature.scenarios.passedPercentage = _calculatePercentage(
feature.scenarios.passed,
feature.scenarios.total
feature.scenarios.total,
);
feature.scenarios.pendingPercentage = _calculatePercentage(
feature.scenarios.pending,
feature.scenarios.total
feature.scenarios.total,
);
feature.scenarios.skippedPercentage = _calculatePercentage(
feature.scenarios.skipped,
feature.scenarios.total
feature.scenarios.total,
);
suite.scenarios.ambiguousPercentage = _calculatePercentage(
suite.scenarios.ambiguous,
suite.scenarios.total
suite.scenarios.total,
);
suite.scenarios.failedPercentage = _calculatePercentage(
suite.scenarios.failed,
suite.scenarios.total
suite.scenarios.total,
);
suite.scenarios.notDefinedPercentage = _calculatePercentage(
suite.scenarios.notDefined,
suite.scenarios.total
suite.scenarios.total,
);
suite.scenarios.passedPercentage = _calculatePercentage(
suite.scenarios.passed,
suite.scenarios.total
suite.scenarios.total,
);
suite.scenarios.pendingPercentage = _calculatePercentage(
suite.scenarios.pending,
suite.scenarios.total
suite.scenarios.total,
);
suite.scenarios.skippedPercentage = _calculatePercentage(
suite.scenarios.skipped,
suite.scenarios.total
suite.scenarios.total,
);
});
}
Expand Down Expand Up @@ -335,7 +335,7 @@ function generateReport(options) {
if (scenario.hasOwnProperty('description') && scenario.description) {
scenario.description = scenario.description.replace(
new RegExp('\r?\n', 'g'),
'<br />'
'<br />',
);
}

Expand Down Expand Up @@ -408,6 +408,7 @@ function generateReport(options) {
step.attachments = [];
step.embeddings.forEach((embedding, embeddingIndex) => {
/* istanbul ignore else */
embedding.data = atob(embedding.data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are using atob, we need to escape the Non- ASCII chracters to avoid the Invalid character error.
embedding.data = decodeURIComponent(escape(embedding.data, 'base64'));

But since escape is depericated, try embedding.data = Buffer.from(embedding.data, 'base64') instead

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, decoding an image/png will break the image in the attachment. Use embedding.data = Buffer.from(embedding.data, 'base64') for any non image/png media type

if (
embedding.mime_type === 'application/json' ||
(embedding.media && embedding.media.type === 'application/json')
Expand Down Expand Up @@ -456,11 +457,11 @@ function generateReport(options) {
if (step.doc_string !== undefined) {
step.id = `${uuid()}.${scenario.id}.${step.name}`.replace(
/[^a-zA-Z0-9-_]/g,
'-'
'-',
);
step.restWireData = _escapeHtml(step.doc_string.value).replace(
new RegExp('\r?\n', 'g'),
'<br />'
'<br />',
);
}

Expand Down Expand Up @@ -522,7 +523,7 @@ function generateReport(options) {
} catch (err) {
return fs.readFileSync(
path.join(__dirname, '..', 'templates', fileName),
'utf-8'
'utf-8',
);
}
} else {
Expand All @@ -540,7 +541,7 @@ function generateReport(options) {
return typeof string === 'string' || string instanceof String
? string.replace(
/[^0-9A-Za-z ]/g,
(chr) => '&#' + chr.charCodeAt(0) + ';'
(chr) => '&#' + chr.charCodeAt(0) + ';',
)
: string;
}
Expand Down Expand Up @@ -568,13 +569,13 @@ function generateReport(options) {
_.template(_readTemplateFile(FEATURES_OVERVIEW_INDEX_TEMPLATE))({
suite: suite,
featuresOverview: _.template(
_readTemplateFile(FEATURES_OVERVIEW_TEMPLATE)
_readTemplateFile(FEATURES_OVERVIEW_TEMPLATE),
)({
suite: suite,
_: _,
}),
featuresScenariosOverviewChart: _.template(
_readTemplateFile(SCENARIOS_OVERVIEW_CHART_TEMPLATE)
_readTemplateFile(SCENARIOS_OVERVIEW_CHART_TEMPLATE),
)({
overviewPage: true,
scenarios: suite.scenarios,
Expand All @@ -584,10 +585,10 @@ function generateReport(options) {
{
suite: suite,
_: _,
}
},
),
featuresOverviewChart: _.template(
_readTemplateFile(FEATURES_OVERVIEW_CHART_TEMPLATE)
_readTemplateFile(FEATURES_OVERVIEW_CHART_TEMPLATE),
)({
suite: suite,
_: _,
Expand All @@ -599,7 +600,7 @@ function generateReport(options) {
pageTitle: pageTitle,
reportName: reportName,
pageFooter: pageFooter,
})
}),
);
}

Expand All @@ -617,15 +618,15 @@ function generateReport(options) {
suite.features.forEach((feature) => {
const featurePage = path.resolve(
reportPath,
`${FEATURE_FOLDER}/${feature.id}.html`
`${FEATURE_FOLDER}/${feature.id}.html`,
);
fs.writeFileSync(
featurePage,
_.template(_readTemplateFile(FEATURE_OVERVIEW_INDEX_TEMPLATE))({
feature: feature,
suite: suite,
featureScenariosOverviewChart: _.template(
_readTemplateFile(SCENARIOS_OVERVIEW_CHART_TEMPLATE)
_readTemplateFile(SCENARIOS_OVERVIEW_CHART_TEMPLATE),
)({
overviewPage: false,
feature: feature,
Expand All @@ -634,7 +635,7 @@ function generateReport(options) {
_: _,
}),
featureMetadataOverview: _.template(
_readTemplateFile(FEATURE_METADATA_OVERVIEW_TEMPLATE)
_readTemplateFile(FEATURE_METADATA_OVERVIEW_TEMPLATE),
)({
metadata: feature.metadata,
_: _,
Expand All @@ -652,7 +653,7 @@ function generateReport(options) {
reportName: reportName,
pageFooter: pageFooter,
plainDescription: plainDescription,
})
}),
);
// Copy the assets, but first check if they don't exist and not useCDN
if (
Expand All @@ -662,9 +663,9 @@ function generateReport(options) {
fs.copySync(
path.resolve(
path.dirname(require.resolve('../package.json')),
'templates/assets'
'templates/assets',
),
path.resolve(reportPath, 'assets')
path.resolve(reportPath, 'assets'),
);
}
});
Expand All @@ -680,7 +681,7 @@ function generateReport(options) {
*/
function formatDuration(duration) {
return Duration.fromMillis(
durationInMS ? duration : duration / 1000000
durationInMS ? duration : duration / 1000000,
).toFormat('hh:mm:ss.SSS');
}
}
Expand Down