-
Notifications
You must be signed in to change notification settings - Fork 193
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
fix: add ava to junit parser #6847
Conversation
a7ec29a
to
9a28827
Compare
9a28827
to
85fec23
Compare
const resultsBody = fs.readFileSync(process.argv[2] || 'results.txt', 'utf-8'); | ||
const packageTestRegex = new RegExp(`> (.+?)@(.+?) test$`, 'gms'); | ||
const resultRegex = new RegExp( | ||
`^ ([✔✘-])(( \\[skip\\])?( \\[todo\\])?( \\[expected fail\\])?( \\[fail\\]:)?)(.+?)(\\(([\\d. smd]+)\\))?$`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, this is really rough—and brittle against upstream changes like the rather recent avajs/ava#3082 .
If the reason for not using TAP output is lack of timing information, I think we'd be better off adding that capability to the local patch of ava (which we can even push for upstreaming).
diff --git a/node_modules/ava/lib/reporters/tap.js b/node_modules/ava/lib/reporters/tap.js
index b1989a4..eb30806 100644
--- a/node_modules/ava/lib/reporters/tap.js
+++ b/node_modules/ava/lib/reporters/tap.js
@@ -52,6 +52,7 @@ export default class TapReporter {
this.extensions = options.extensions;
this.stdStream = options.stdStream;
this.reportStream = options.reportStream;
+ this.durationThreshold = options.durationThreshold || 100;
this.crashCount = 0;
this.filesWithMissingAvaImports = new Set();
@@ -96,7 +97,13 @@ export default class TapReporter {
}
writeTest(evt, flags) {
- this.reportStream.write(supertap.test(this.prefixTitle(evt.testFile, evt.title), {
+ let title = this.prefixTitle(evt.testFile, evt.title);
+ if (evt.type === 'test-passed' && evt.duration > this.durationThreshold) {
+ // Add `# time=...` per TAP specification proposal
+ // https://github.com/TestAnything/Specification/issues/16
+ title += ` # time=${evt.duration}ms`;
+ }
+ this.reportStream.write(supertap.test(title, {
comment: evt.logs,
error: evt.err ? dumpError(evt.err) : null,
index: ++this.i,
Sample output
$ npx ava --tap 2>/dev/null | tail
ok 67 - publish-kit › subscribeEach(publishKit subscriber)
ok 68 - publish-kit › subscribeEach(durablePublishKit subscriber)
ok 69 - publish-kit › durable publish kit upgrade trauma (full-vat integration) # time=20305ms
1..69
# tests 69
# pass 68
# skip 1
# fail 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff --git a/node_modules/ava/index.js b/node_modules/ava/index.js
new file mode 100644
index 0000000..bee62d8
--- /dev/null
+++ b/node_modules/ava/index.js
@@ -0,0 +1,2 @@
+// XXX work around https://github.com/import-js/eslint-plugin-import/issues/1810
+export {default} from './lib/worker/main.cjs';
diff --git a/node_modules/ava/lib/reporters/tap.js b/node_modules/ava/lib/reporters/tap.js
index b1989a4..264ba7b 100644
--- a/node_modules/ava/lib/reporters/tap.js
+++ b/node_modules/ava/lib/reporters/tap.js
@@ -96,7 +96,7 @@ export default class TapReporter {
}
writeTest(evt, flags) {
- this.reportStream.write(supertap.test(this.prefixTitle(evt.testFile, evt.title), {
+ this.reportStream.write(supertap.test(this.prefixTitle(evt.testFile, evt.title + ` dur=${evt.duration}`), {
comment: evt.logs,
error: evt.err ? dumpError(evt.err) : null,
index: ++this.i,
@@ -108,7 +108,7 @@ export default class TapReporter {
writeCrash(evt, title) {
this.crashCount++;
- this.reportStream.write(supertap.test(title || evt.err.summary || evt.type, {
+ this.reportStream.write(supertap.test((title || evt.err.summary || evt.type) + ` dur=${evt.duration}`, {
comment: evt.logs,
error: evt.err ? dumpError(evt.err) : null,
index: ++this.i,
refs: #6846
Description
Adds a script that parses the stdout from a yarn test run, and produces junit XML for consumption of a test analysis tool