|
1 | 1 | import fs from 'fs' |
2 | 2 | import path from 'path' |
3 | 3 | import os from 'os' |
| 4 | +import { isMainThread } from 'worker_threads' |
4 | 5 | import { mkdirp } from 'mkdirp' |
5 | 6 | import { DOMImplementation, XMLSerializer } from '@xmldom/xmldom' |
6 | 7 |
|
@@ -45,7 +46,7 @@ const INVALID_XML_CHARS = new RegExp('[\\u0000-\\u0008\\u000B\\u000C\\u000E-\\u0 |
45 | 46 | * Possible config options: |
46 | 47 | * |
47 | 48 | * * `outputName`: file name for the report. Default: `report.xml`. |
48 | | - * * `output`: directory where the report is stored, relative to the project root. Default: the `output` directory. |
| 49 | + * * `output`: directory where the report is stored, relative to the project root. Default: the `output` directory. With `run-workers` and `multiple` runs, each run writes its own report into its run folder (e.g. `output/dev_chromium1`) and this option is ignored. |
49 | 50 | * * `testGroupName`: value of the `name` attribute on the root `<testsuites>` element. Default: `CodeceptJS`. |
50 | 51 | * * `attachMeta`: add the test's meta information (`meta` keys, `tags`, `retries`) as `<properties>`. Default: true. |
51 | 52 | * * `attachSteps`: add the step/substep log as `<system-out>`. Default: true. |
@@ -92,19 +93,35 @@ export default function (config = {}) { |
92 | 93 | meta: {}, |
93 | 94 | steps: [], |
94 | 95 | duration: (runnable && runnable.duration) || 0, |
| 96 | + outputDir: hook.outputDir, |
95 | 97 | }) |
96 | 98 | }) |
97 | 99 |
|
98 | 100 | const writeReport = result => { |
99 | 101 | if (written) return |
100 | 102 | if (!result || !Array.isArray(result.tests)) return |
| 103 | + if (!isMainThread) return |
101 | 104 | written = true |
102 | 105 |
|
| 106 | + const runDirs = [...new Set(result.tests.map(test => test.outputDir).filter(Boolean))] |
| 107 | + if (runDirs.length) { |
| 108 | + for (const dir of runDirs) { |
| 109 | + const runResult = { tests: result.tests.filter(test => test.outputDir === dir), stats: result.stats } |
| 110 | + const runHookFailures = hookFailures.filter(hf => hf.outputDir === dir) |
| 111 | + saveXml(dir, buildXml(runResult, config, runHookFailures)) |
| 112 | + } |
| 113 | + return |
| 114 | + } |
| 115 | + |
103 | 116 | const dir = config.output ? path.resolve(store.codeceptDir || process.cwd(), config.output) : store.outputDir || process.cwd() |
| 117 | + saveXml(dir, buildXml(result, config, hookFailures)) |
| 118 | + } |
| 119 | + |
| 120 | + const saveXml = (dir, xml) => { |
104 | 121 | mkdirp.sync(dir) |
105 | 122 | const file = path.join(dir, config.outputName) |
106 | 123 |
|
107 | | - fs.writeFileSync(file, buildXml(result, config, hookFailures)) |
| 124 | + fs.writeFileSync(file, xml) |
108 | 125 | output.plugin('junitReporter', `JUnit report saved to ${file}`) |
109 | 126 | } |
110 | 127 |
|
|
0 commit comments