Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

arirubinstein
Copy link
Contributor

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

@arirubinstein arirubinstein self-assigned this Jan 25, 2023
@arirubinstein arirubinstein force-pushed the ari/test_telemetry branch 2 times, most recently from a7ec29a to 9a28827 Compare January 25, 2023 02:00
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]+)\\))?$`,
Copy link
Member

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

Copy link
Contributor Author

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants