-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
12,794 additions
and
15,709 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,9 +41,17 @@ | |
"uuid": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/find": "^0.2.4", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/jsonfile": "^6.1.4", | ||
"@types/lodash": "^4.17.5", | ||
"@types/luxon": "^3.4.2", | ||
"@types/node": "^20.14.2", | ||
"@types/uuid": "^9.0.8", | ||
"jasmine": "^5.1.0", | ||
"nyc": "^17.0.0", | ||
"release-it": "^17.3.0" | ||
"release-it": "^17.3.0", | ||
"typescript": "^5.4.5" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import find from "find"; | ||
import fs from "fs-extra"; | ||
import jsonFile from "jsonfile"; | ||
import path from "node:path"; | ||
import { Feature, ReportOption, Step } from "./report-types"; | ||
import { formatToLocalIso } from "./helper"; | ||
|
||
export const collectJsonFiles = (options: ReportOption): Feature[] => { | ||
let jsonOutput: Feature[]; | ||
let files: string[]; | ||
|
||
try { | ||
files = find.fileSync(/\.json$/, path.resolve(process.cwd(), options.dir)); | ||
} catch (e) { | ||
throw new Error( | ||
`There were issues reading JSON-files from '${options.dir}'.`, | ||
{ | ||
cause: e, | ||
} | ||
); | ||
} | ||
|
||
if (files.length > 0) { | ||
files.map((file) => { | ||
// Cucumber json can be empty, it's likely being created by another process (#47) | ||
const data = fs.readFileSync(file).toString() || "[]"; | ||
const stats = fs.statSync(file); | ||
const reportTime = stats.birthtime; | ||
|
||
JSON.parse(data).map((json: Feature) => { | ||
if (options.metadata && !json.metadata) { | ||
json.metadata = options.metadata; | ||
} else { | ||
json = Object.assign( | ||
{ | ||
metadata: { | ||
browser: { | ||
name: "not known", | ||
version: "not known", | ||
}, | ||
device: "not known", | ||
platform: { | ||
name: "not known", | ||
version: "not known", | ||
}, | ||
}, | ||
}, | ||
json | ||
); | ||
} | ||
|
||
if (json.metadata && options.displayReportTime && reportTime) { | ||
json.metadata = Object.assign({ reportTime }, json.metadata); | ||
json.metadata.reportTime = formatToLocalIso(json.metadata.reportTime); | ||
} | ||
|
||
// Only check the feature hooks if there are elements (fail-safe) | ||
const { scenarios } = json; | ||
|
||
if (scenarios) { | ||
json.scenarios = scenarios.map((scenario) => { | ||
const { before, after } = scenario; | ||
|
||
if (before) { | ||
scenario.steps = parseFeatureHooks(before, "Before").concat( | ||
scenario.steps | ||
); | ||
} | ||
if (after) { | ||
scenario.steps = scenario.steps.concat( | ||
parseFeatureHooks(after, "After") | ||
); | ||
} | ||
return scenario; | ||
}); | ||
} | ||
jsonOutput.push(json); | ||
}); | ||
}); | ||
|
||
if (options.saveCollectedJson) { | ||
const file = path.resolve(options.reportPath, "merged-output.json"); | ||
fs.ensureDirSync(options.reportPath); | ||
jsonFile.writeFileSync(file, jsonOutput, { spaces: 2 }); | ||
} | ||
|
||
return jsonOutput; | ||
} | ||
|
||
console.log( | ||
"\x1b[33m%s\x1b[0m", | ||
`WARNING: No JSON files found in '${options.dir}'. NO REPORT CAN BE CREATED!` | ||
); | ||
return []; | ||
}; | ||
|
||
/** | ||
* Add the feature hooks to the steps so the report will pick them up properly | ||
* | ||
* @param {object} data | ||
* @param {string} keyword | ||
* @returns {{ | ||
* arguments: array, | ||
* keyword: string, | ||
* name: string, | ||
* result: { | ||
* status: string, | ||
* }, | ||
* line: number, | ||
* match: { | ||
* location: string | ||
* }, | ||
* embeddings: [] | ||
* }} | ||
*/ | ||
const parseFeatureHooks = (data: Step[], keyword: string): Step => { | ||
return data.map((step) => { | ||
const match = | ||
step.match && step.match.location | ||
? step.match | ||
: { location: "can not be determined" }; | ||
|
||
return { | ||
arguments: step.arguments || [], | ||
keyword: keyword, | ||
name: "Hook", | ||
result: step.result, | ||
match, | ||
embeddings: step.embeddings || [], | ||
}; | ||
}); | ||
}; |
Oops, something went wrong.