@qavajs/html-formatter
Advanced tools
Comparing version 0.16.0 to 0.17.0
@@ -0,1 +1,4 @@ | ||
# 0.17.0 | ||
- implemented runtime streaming | ||
# 0.16.0 | ||
@@ -2,0 +5,0 @@ - added dark theme |
@@ -1,20 +0,101 @@ | ||
const JsonFormatter = require('./json_formatter'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
class HTMLFormatter extends JsonFormatter { | ||
const { Formatter } = require('@cucumber/cucumber'); | ||
const { write, readFileSync } = require('node:fs'); | ||
const path = require('node:path'); | ||
class HTMLStream { | ||
constructor(fd, ender) { | ||
this.fd = fd; | ||
this.position = 0; | ||
this.ender = Buffer.from(ender); | ||
} | ||
write(data) { | ||
const dataBuffer = Buffer.from(data); | ||
const buffer = Buffer.concat([dataBuffer, this.ender]); | ||
write(this.fd, buffer, 0, buffer.length, this.position, () => {}); | ||
this.position += dataBuffer.length; | ||
} | ||
} | ||
class HTMLFormatter extends Formatter { | ||
hooks = {}; | ||
constructor(options) { | ||
super(options); | ||
this.metadata = options.parsedArgvOptions.htmlConfig?.metadata ?? {}; | ||
const log = this.log.bind(this); | ||
this.log = function(json) { | ||
const htmlTemplate = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf-8'); | ||
log(htmlTemplate | ||
.replace('METADATA', () => JSON.stringify(this.metadata)) | ||
.replace('SOURCE_DATA', () => JSON.stringify(JSON.parse(json)))); | ||
const metadata = JSON.stringify(options.parsedArgvOptions.htmlConfig?.metadata ?? {}); | ||
const htmlTemplate = readFileSync(path.resolve(__dirname, './index.html'), 'utf-8') | ||
.replace('METADATA', metadata); | ||
const [left, right] = htmlTemplate.split('SOURCE_DATA'); | ||
this.htmlStream = new HTMLStream(this.stream.fd, right); | ||
this.htmlStream.write(left); | ||
options.eventBroadcaster.on('envelope', this.processEnvelope.bind(this)); | ||
} | ||
processEnvelope(envelope) { | ||
if (envelope.testCaseFinished) { | ||
return this.finishTest(envelope); | ||
} | ||
if (envelope.hook) { | ||
return this.hooks[envelope.hook.id] = envelope.hook; | ||
} | ||
} | ||
finishTest(envelope) { | ||
if (envelope.testCaseFinished.willBeRetried) return; | ||
const testCase = this.eventDataCollector.getTestCaseAttempt(envelope.testCaseFinished.testCaseStartedId); | ||
const feature = { | ||
description: testCase.gherkinDocument.feature.description, | ||
id: 'feature' + testCase.pickle.id, | ||
line: testCase.gherkinDocument.feature.location.line, | ||
keyword: testCase.gherkinDocument.feature.keyword, | ||
name: testCase.gherkinDocument.feature.name, | ||
uri: testCase.gherkinDocument.uri, | ||
tags: this.formatTags(testCase.gherkinDocument.feature.tags) | ||
}; | ||
const steps = testCase.testCase.testSteps; | ||
for (const step of steps) { | ||
const pickle = testCase.pickle.steps.find(pickle => step.pickleStepId === pickle.id); | ||
step.name = pickle ? pickle.text : this.hookText(steps, step); | ||
step.arguments = pickle ? [{ ...(pickle.argument?.dataTable ?? pickle.argument?.docString) }] : undefined; | ||
const result = testCase.stepResults[step.id]; | ||
step.result = { | ||
status: result.status.toLowerCase(), | ||
duration: result.duration.seconds * 1_000_000_000 + result.duration.nanos, | ||
error_message: result.message | ||
}; | ||
step.embeddings = testCase.stepAttachments[step.id]?.map(attachment => ({ | ||
...attachment, | ||
data: attachment.body, | ||
mime_type: attachment.mediaType | ||
})); | ||
} | ||
const scenario = { | ||
feature, | ||
steps, | ||
name: testCase.pickle.name, | ||
id: testCase.pickle.id, | ||
keyword: 'Scenario', | ||
tags: this.formatTags(testCase.pickle.tags), | ||
type: 'scenario' | ||
}; | ||
this.htmlStream.write(JSON.stringify(scenario) + ','); | ||
} | ||
formatTags(tags) { | ||
return tags.map(tag => ({ name: tag.name, line: tag.location?.line })); | ||
} | ||
hookText(steps, step) { | ||
const hook = this.hooks[step.hookId]; | ||
if (hook?.name) return hook.name; | ||
const stepsBefore = steps.slice(0, steps.findIndex((element) => element === step)); | ||
return stepsBefore.every(element => element.pickleStepId === undefined) ? 'Before' : 'After'; | ||
} | ||
} | ||
module.exports = HTMLFormatter; |
const { Formatter } = require('@cucumber/cucumber'); | ||
class JsonFormatter extends Formatter { | ||
@@ -25,16 +26,12 @@ | ||
const testCase = this.eventDataCollector.getTestCaseAttempt(envelope.testCaseFinished.testCaseStartedId); | ||
let feature = this.json.find(feature => feature.name === testCase.gherkinDocument.feature.name); | ||
if (!feature) { | ||
feature = { | ||
description: testCase.gherkinDocument.feature.description, | ||
id: 'feature' + testCase.pickle.id, | ||
line: testCase.gherkinDocument.feature.location.line, | ||
keyword: testCase.gherkinDocument.feature.keyword, | ||
name: testCase.gherkinDocument.feature.name, | ||
uri: testCase.gherkinDocument.uri, | ||
elements: [], | ||
tags: this.formatTags(testCase.gherkinDocument.feature.tags) | ||
}; | ||
this.json.push(feature); | ||
} | ||
const feature = { | ||
description: testCase.gherkinDocument.feature.description, | ||
id: 'feature' + testCase.pickle.id, | ||
line: testCase.gherkinDocument.feature.location.line, | ||
keyword: testCase.gherkinDocument.feature.keyword, | ||
name: testCase.gherkinDocument.feature.name, | ||
uri: testCase.gherkinDocument.uri, | ||
elements: [], | ||
tags: this.formatTags(testCase.gherkinDocument.feature.tags) | ||
}; | ||
const steps = testCase.testCase.testSteps; | ||
@@ -45,3 +42,3 @@ for (const step of steps) { | ||
step.arguments = pickle ? [{ ...(pickle.argument?.dataTable ?? pickle.argument?.docString) }] : undefined; | ||
const result= testCase.stepResults[step.id]; | ||
const result = testCase.stepResults[step.id]; | ||
step.result = { | ||
@@ -60,2 +57,3 @@ status: result.status.toLowerCase(), | ||
steps, | ||
feature, | ||
name: testCase.pickle.name, | ||
@@ -66,12 +64,12 @@ id: testCase.pickle.id, | ||
type: 'scenario' | ||
} | ||
feature.elements.push(scenario); | ||
}; | ||
this.json.push(scenario); | ||
} | ||
finishLaunch() { | ||
this.log(JSON.stringify(this.json, null, 2)) | ||
this.log(JSON.stringify(this.json, null, 2)); | ||
} | ||
formatTags(tags) { | ||
return tags.map(tag => ({ name: tag.name, line: tag.location?.line })) | ||
return tags.map(tag => ({ name: tag.name, line: tag.location?.line })); | ||
} | ||
@@ -83,3 +81,3 @@ | ||
const stepsBefore = steps.slice(0, steps.findIndex((element) => element === step)); | ||
return stepsBefore.every(element => element.pickleStepId === undefined) ? 'Before' : 'After' | ||
return stepsBefore.every(element => element.pickleStepId === undefined) ? 'Before' : 'After'; | ||
} | ||
@@ -86,0 +84,0 @@ } |
{ | ||
"name": "@qavajs/html-formatter", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"main": "formatter/formatter.js", | ||
@@ -65,22 +65,22 @@ "authors": [ | ||
"eslint": "^8.41.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-react": "^7.34.3", | ||
"eslint-plugin-react-hooks": "^4.6.2", | ||
"eslint-plugin-testing-library": "^5.11.0", | ||
"eslint-plugin-vitest": "^0.3.1", | ||
"eslint-plugin-vitest": "^0.5.4", | ||
"history": "^4.10.1", | ||
"jsdom": "^22.1.0", | ||
"prettier": "^3.0.3", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"jsdom": "^24.1.0", | ||
"prettier": "^3.3.2", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"react-router-dom": "^5.3.4", | ||
"recharts": "^2.12.7", | ||
"sass": "^1.62.1", | ||
"sass": "^1.77.6", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.3.3", | ||
"typescript": "^5.5.3", | ||
"vite": "^4.5.1", | ||
"vite-plugin-singlefile": "^0.13.5", | ||
"vite-plugin-svgr": "^3.2.0", | ||
"vitest": "^1.2.0", | ||
"vitest": "^1.6.0", | ||
"vitest-dom": "^0.1.1" | ||
@@ -87,0 +87,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1293900
264
1