|
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. |
@@ -100,19 +101,35 @@ export default function (config = {}) { |
100 | 101 | meta: {}, |
101 | 102 | steps: [], |
102 | 103 | duration: (runnable && runnable.duration) || 0, |
| 104 | + outputDir: hook.outputDir, |
103 | 105 | }) |
104 | 106 | }) |
105 | 107 |
|
106 | 108 | const writeReport = result => { |
107 | 109 | if (written) return |
108 | 110 | if (!result || !Array.isArray(result.tests)) return |
| 111 | + if (!isMainThread) return |
109 | 112 | written = true |
110 | 113 |
|
| 114 | + const runDirs = [...new Set(result.tests.map(test => test.outputDir).filter(Boolean))] |
| 115 | + if (runDirs.length) { |
| 116 | + for (const dir of runDirs) { |
| 117 | + const runResult = { tests: result.tests.filter(test => test.outputDir === dir), stats: result.stats } |
| 118 | + const runHookFailures = hookFailures.filter(hf => hf.outputDir === dir) |
| 119 | + saveXml(dir, buildXml(runResult, config, runHookFailures)) |
| 120 | + } |
| 121 | + return |
| 122 | + } |
| 123 | + |
111 | 124 | const dir = config.output ? path.resolve(store.codeceptDir || process.cwd(), config.output) : store.outputDir || process.cwd() |
| 125 | + saveXml(dir, buildXml(result, config, hookFailures)) |
| 126 | + } |
| 127 | + |
| 128 | + const saveXml = (dir, xml) => { |
112 | 129 | mkdirp.sync(dir) |
113 | 130 | const file = path.join(dir, config.outputName) |
114 | 131 |
|
115 | | - fs.writeFileSync(file, buildXml(result, config, hookFailures)) |
| 132 | + fs.writeFileSync(file, xml) |
116 | 133 | output.plugin('junitReporter', `JUnit report saved to ${file}`) |
117 | 134 | } |
118 | 135 |
|
|
0 commit comments