Skip to content

Commit

Permalink
test: migrate snapshots to snap
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Mar 13, 2024
1 parent aa2a482 commit 24fafdd
Show file tree
Hide file tree
Showing 25 changed files with 190 additions and 310 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"homepage": "https://github.com/MoLow/reporters#readme",
"devDependencies": {
"@matteo.collina/snap": "^0.2.1",
"c8": "^7.13.0",
"eslint": "^7.32.0 || ^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": ".\n",
"exitCode": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "node:internal/test_runner/harness:50\n throw err;\n ^\n\nError: Bail\n *\n at bail.next (<anonymous>)\n *\n *\n *\n *\n *\n *\n *\n *\nEmitted 'error' event on Duplex instance at:\n *\n *\n *\n\nNode.js *\n",
"stdout": "X\n\u001b[31m✖ Bailing on failed test: fail\u001b[0m\n",
"exitCode": 7
}
15 changes: 7 additions & 8 deletions packages/bail/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

const { test } = require('node:test');
const { spawnSync } = require('child_process');
const assert = require('assert');
const { Snap } = require('../../../tests/utils');

test('pass should not interfere with passing test', () => {
const snapshot = Snap(__filename);
test('pass should not interfere with passing test', async () => {
const child = spawnSync(process.execPath, [
'--test-reporter', 'dot', '--test-reporter-destination', 'stdout',
'--test-reporter', './index.js', '--test-reporter-destination', 'stdout', 'tests/fixtures/pass.js',
], { env: {} });
assert.strictEqual(child.stderr?.toString(), '');
assert.strictEqual(child.stdout?.toString(), '.\n');
assert.strictEqual(child.status, 0);

await snapshot(child);
});

test('fail should stop after failed test', () => {
test('fail should stop after failed test', async () => {
const child = spawnSync(process.execPath, [
'--test-reporter', 'dot', '--test-reporter-destination', 'stdout',
'--test-reporter', './index.js', '--test-reporter-destination', 'stdout',
'tests/fixtures/fail.js', 'tests/fixtures/pass.js',
], { env: {} });
assert.strictEqual(child.stdout?.toString(), 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n');
assert.strictEqual(child.status, 7);
await snapshot(child);

Check failure on line 23 in packages/bail/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v18)

fail should stop after failed test

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 7, + stderr: 'node:internal/test_runner/harness:48\n' + - stderr: 'node:internal/test_runner/harness:50\n' + ' throw err;\n' + ... 'Node.js *\n', stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n' }] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 7, + stderr: 'node:internal/test_runner/harness:48\n' + - stderr: 'node:internal/test_runner/harness:50\n' + ' throw err;\n' + ... 'Node.js *\n', stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n' } at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/bail/tests/index.test.js:23:3) at async Test.run (node:internal/test_runner/test:632:9) at async Test.processPendingSubtests (node:internal/test_runner/test:374:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: { stderr: "node:internal/test_runner/harness:48\n throw err;\n ^\n\nError: Bail\n *\n at bail.next (<anonymous>)\n *\n *\n *\n *\n *\n *\n *\n *\nEmitted 'error' event on Duplex instance at:\n *\n *\n *\n\nNode.js *\n", stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n', exitCode: 7 }, expected: { stderr: "node:internal/test_runner/harness:50\n throw err;\n ^\n\nError: Bail\n *\n at bail.next (<anonymous>)\n *\n *\n *\n *\n *\n *\n *\n *\nEmitted 'error' event on Duplex instance at:\n *\n *\n *\n\nNode.js *\n", stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n', exitCode: 7 }, operator: 'deepStrictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 23 in packages/bail/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v21)

fail should stop after failed test

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 7, + stderr: 'node:internal/test_runner/harness:51\n' + - stderr: 'node:internal/test_runner/harness:50\n' + ' throw err;\n' + ... 'Node.js *\n', stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n' }] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 7, + stderr: 'node:internal/test_runner/harness:51\n' + - stderr: 'node:internal/test_runner/harness:50\n' + ' throw err;\n' + ... 'Node.js *\n', stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n' } at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/bail/tests/index.test.js:23:3) at async Test.run (node:internal/test_runner/test:640:9) at async Test.processPendingSubtests (node:internal/test_runner/test:382:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: { stderr: "node:internal/test_runner/harness:51\n throw err;\n ^\n\nError: Bail\n *\n at bail.next (<anonymous>)\n *\n *\n *\n *\n *\n *\n *\n *\nEmitted 'error' event on Duplex instance at:\n *\n *\n *\n\nNode.js *\n", stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n', exitCode: 7 }, expected: { stderr: "node:internal/test_runner/harness:50\n throw err;\n ^\n\nError: Bail\n *\n at bail.next (<anonymous>)\n *\n *\n *\n *\n *\n *\n *\n *\nEmitted 'error' event on Duplex instance at:\n *\n *\n *\n\nNode.js *\n", stdout: 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n', exitCode: 7 }, operator: 'deepStrictEqual' } }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "::debug::starting to run tests\n::debug::starting to run is ok\n::debug::completed running is ok\n::debug::starting to run fails\n::error title=fails,file=tests/example.js,line=9,col=11::[Error [ERR_TEST_FAILURE]: this is an error] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext.<anonymous> (CWD/tests/example.js:9:11)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Promise.all (index 0)%0A at async Suite.run (node:internal/test_runner/test:948:7)%0A at async startSubtest (node:internal/test_runner/harness:216:3)%0A}\n::debug::starting to run is a diagnostic\n::debug::completed running is a diagnostic\n::notice file=tests/example.js,line=11,col=3::this is a diagnostic\n::debug::starting to run should fail\n::error title=should fail,file=tests/example.js,line=12,col=31::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (CWD/tests/example.js:12:31)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n::debug::starting to run more tests\n::debug::starting to run is ok\n::debug::completed running is ok\n::debug::completed running more tests\n::debug::starting to run is skipped\n::debug::completed running is skipped\n::debug::starting to run is a todo\n::debug::completed running is a todo\n::debug::starting to run top level diagnostic\n::debug::completed running top level diagnostic\n::notice file=tests/example.js,line=21,col=1::top level diagnostic\n::group::Test results (4 passed, 2 failed)\n::notice::Total Tests: 8%0ASuites 📂: 2%0APassed ✅: 4%0AFailed ❌: 2%0ACanceled 🚫: 0%0ASkipped ⏭️: 1%0ATodo 📝: 1%0ADuration 🕐: *ms\n::endgroup::\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"<h1>Test Results</h1>\n<table><tr><td>Total Tests</td><td>8</td></tr><tr><td>Suites 📂</td><td>2</td></tr><tr><td>Passed ✅</td><td>4</td></tr><tr><td>Failed ❌</td><td>2</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>1</td></tr><tr><td>Todo 📝</td><td>1</td></tr><tr><td>Duration 🕐</td><td>*ms</td></tr></table>\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "::debug::starting to run should fail\n::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:216:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n::debug::starting to run should pass\n::debug::completed running should pass\n::group::Test results (1 passed, 1 failed)\n::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n::endgroup::\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"<h1>Test Results</h1>\n<table><tr><td>Total Tests</td><td>2</td></tr><tr><td>Suites 📂</td><td>0</td></tr><tr><td>Passed ✅</td><td>1</td></tr><tr><td>Failed ❌</td><td>1</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>0</td></tr><tr><td>Todo 📝</td><td>0</td></tr><tr><td>Duration 🕐</td><td>*ms</td></tr></table>\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "",
"exitCode": 1
}
27 changes: 8 additions & 19 deletions packages/github/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,36 @@ const { test, describe, beforeEach } = require('node:test');
const { spawnSync } = require('child_process');
const { tmpdir } = require('os');
const { join } = require('path');
const assert = require('assert');
const path = require('path');
const { readFileSync, writeFileSync } = require('fs');
const { compareLines } = require('../../../tests/utils');
const output = require('./output');
const outputESM = require('./output-esm');
const { Snap } = require('../../../tests/utils');

const snapshot = Snap(__filename);
const GITHUB_STEP_SUMMARY = join(tmpdir(), 'github-actions-test-reporter');
const nodeMajor = process.versions.node.split('.')[0];

describe('github reporter', () => {
beforeEach(() => {
writeFileSync(GITHUB_STEP_SUMMARY, '');
});

test('spawn with reporter', () => {
test('spawn with reporter', async () => {
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], {
env: { GITHUB_ACTIONS: true, GITHUB_STEP_SUMMARY, GITHUB_WORKSPACE: path.resolve(__dirname, '../../../') },
});

assert.strictEqual(child.stderr?.toString(), '');
compareLines(child.stdout?.toString(), output.overrides[nodeMajor]?.stdout ?? output.stdout);
compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), output.summary);
await snapshot(child, readFileSync(GITHUB_STEP_SUMMARY).toString('utf-8'));

Check failure on line 24 in packages/github/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v18)

spawn with reporter

Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, ... '::debug::completed running is ok\n' + '::debug::starting to run fails\n' + + "::error title=fails,file=tests/example.js,line=9,col=11::[Error [ERR_TEST_FAILURE]: this is an error] {%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext.<anonymous> (CWD/tests/example.js:9:11)%0A at Test.runInAsyncScope (node:async_hooks:203:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Promise.all (index 0)%0A at async Suite.run (node:internal/test_runner/test:948:7)%0A at async startSubtest (node:internal/test_runner/harness:214:3),%0A code: 'ERR_TEST_FAILURE'%0A}\n" + - "::error title=fails,file=tests/example.js,line=9,col=11::[Error [ERR_TEST_FAILURE]: this is an error] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext.<anonymous> (CWD/tests/example.js:9:11)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Promise.all (index 0)%0A at async Suite.run (node:internal/test_runner/test:948:7)%0A at async startSubtest (node:internal/test_runner/harness:216:3)%0A}\n" + '::debug::starting to run is a diagnostic\n' + '::debug::completed running is a diagnostic\n' + '::notice file=tests/example.js,line=11,col=3::this is a diagnostic\n' + '::debug::starting to run should fail\n' + + "::error title=should fail,file=tests/example.js,line=12,col=31::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (CWD/tests/example.js:12:31)%0A at Test.runInAsyncScope (node:async_hooks:203:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A },%0A code: 'ERR_TEST_FAILURE'%0A}\n" + - "::error title=should fail,file=tests/example.js,line=12,col=31::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (CWD/tests/example.js:12:31)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + '::debug::starting to run more tests\n' + ... '::notice::Total Tests: 8%0ASuites 📂: 2%0APassed ✅: 4%0AFailed ❌: 2%0ACanceled 🚫: 0%0ASkipped ⏭

Check failure on line 24 in packages/github/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v21)

spawn with reporter

Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, ... '::debug::completed running is ok\n' + '::debug::starting to run fails\n' + + "::error title=fails,file=tests/example.js,line=9,col=11::Error [ERR_TEST_FAILURE]: this is an error%0A at async Promise.all (index 0) {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext.<anonymous> (CWD/tests/example.js:9:11)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:639:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:382:18)%0A at Test.postRun (node:internal/test_runner/test:730:19)%0A at Test.run (node:internal/test_runner/test:688:12)%0A at async Promise.all (index 0)%0A at async Suite.run (node:internal/test_runner/test:964:7)%0A at async startSubtest (node:internal/test_runner/harness:218:3)%0A}\n" + - "::error title=fails,file=tests/example.js,line=9,col=11::[Error [ERR_TEST_FAILURE]: this is an error] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext.<anonymous> (CWD/tests/example.js:9:11)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Promise.all (index 0)%0A at async Suite.run (node:internal/test_runner/test:948:7)%0A at async startSubtest (node:internal/test_runner/harness:216:3)%0A}\n" + '::debug::starting to run is a diagnostic\n' + '::debug::completed running is a diagnostic\n' + '::notice file=tests/example.js,line=11,col=3::this is a diagnostic\n' + '::debug::starting to run should fail\n' + + "::error title=should fail,file=tests/example.js,line=12,col=31::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (CWD/tests/example.js:12:31)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:639:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:382:18)%0A at Test.postRun (node:internal/test_runner/test:730:19)%0A at Test.run (node:internal/test_runner/test:688:12)%0A at async Suite.processPendingSubtests (node:internal/test_runner/test:382:7) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + - "::error title=should fail,file=tests/example.js,line=12,col=31::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (CWD/tests/example.js:12:31)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Suite.processPendingSubtests (node:internal/test_runner/test:374:18)%0A at Test.postRun (node:internal/test_runner/test:715:19)%0A at Test.run (node:internal/test_runner/test:673:12)%0A at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + '::debug::starting to run more tests\n' + ... '::notice::Total Tests: 8%0ASuites 📂: 2%0APassed ✅: 4%0AFaile
});

test('spawn with reporter - esm', () => {
test('spawn with reporter - esm', async () => {
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example.mjs'], {
env: { GITHUB_ACTIONS: true, GITHUB_STEP_SUMMARY, GITHUB_WORKSPACE: path.resolve(__dirname, '../../../') },
});

assert.strictEqual(child.stderr?.toString(), '');
compareLines(
child.stdout?.toString(),
outputESM.overrides[nodeMajor]?.stdout ?? outputESM.stdout,
);
compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), outputESM.summary);
await snapshot(child, readFileSync(GITHUB_STEP_SUMMARY).toString('utf-8'));

Check failure on line 32 in packages/github/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v18)

spawn with reporter - esm

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected + { + exitCode: 1, + stderr: '', + stdout: '::debug::starting to run should fail\n' + + "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: false == true] {%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: false == true%0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:203:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:214:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A },%0A code: 'ERR_TEST_FAILURE'%0A}\n" + + '::debug::starting to run should pass\n' + + '::debug::completed running should pass\n' + + '::group::Test results (1 passed, 1 failed)\n' + + '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + + '::endgroup::\n' + } - '<h1>Test Results</h1>\n' + - '<table><tr><td>Total Tests</td><td>8</td></tr><tr><td>Suites 📂</td><td>2</td></tr><tr><td>Passed ✅</td><td>4</td></tr><tr><td>Failed ❌</td><td>2</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>1</td></tr><tr><td>Todo 📝</td><td>1</td></tr><tr><td>Duration 🕐</td><td>*ms</td></tr></table>\n'] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + { + exitCode: 1, + stderr: '', + stdout: '::debug::starting to run should fail\n' + + "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: false == true] {%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: false == true%0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:203:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:214:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A },%0A code: 'ERR_TEST_FAILURE'%0A}\n" + + '::debug::starting to run should pass\n' + + '::debug::completed running should pass\n' + + '::group::Test results (1 passed, 1 failed)\n' + + '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + + '::endgroup::\n' + } - '<h1>Test Results</h1>\n' + - '<table><tr><td>Total Tests</td><td>8</td></tr><tr><td>Suites 📂</td><td>2</td></tr><tr><td>Passed ✅</td><td>4</td></tr><tr><td>Failed ❌</td><td>2</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>1</td></tr><tr><td>Todo 📝</td><td>1</td></tr><tr><td>Duration 🕐</td><td>*ms</td></tr></table>\n' at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/github/tests/index.test.js:32:5) at async Test.run (node:internal/test_runner/test:632:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: { stderr: '', stdout: "::debug::starting to run should fail\n::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: false == true] {%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: false == true%0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:203:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test

Check failure on line 32 in packages/github/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v21)

spawn with reporter - esm

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected + { + exitCode: 1, + stderr: '', + stdout: '::debug::starting to run should fail\n' + + "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:639:25)%0A at Test.start (node:internal/test_runner/test:550:17)%0A at startSubtest (node:internal/test_runner/harness:218:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + + '::debug::starting to run should pass\n' + + '::debug::completed running should pass\n' + + '::group::Test results (1 passed, 1 failed)\n' + + '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + + '::endgroup::\n' + } - '<h1>Test Results</h1>\n' + - '<table><tr><td>Total Tests</td><td>8</td></tr><tr><td>Suites 📂</td><td>2</td></tr><tr><td>Passed ✅</td><td>4</td></tr><tr><td>Failed ❌</td><td>2</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>1</td></tr><tr><td>Todo 📝</td><td>1</td></tr><tr><td>Duration 🕐</td><td>*ms</td></tr></table>\n'] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + { + exitCode: 1, + stderr: '', + stdout: '::debug::starting to run should fail\n' + + "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:639:25)%0A at Test.start (node:internal/test_runner/test:550:17)%0A at startSubtest (node:internal/test_runner/harness:218:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + + '::debug::starting to run should pass\n' + + '::debug::completed running should pass\n' + + '::group::Test results (1 passed, 1 failed)\n' + + '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + + '::endgroup::\n' + } - '<h1>Test Results</h1>\n' + - '<table><tr><td>Total Tests</td><td>8</td></tr><tr><td>Suites 📂</td><td>2</td></tr><tr><td>Passed ✅</td><td>4</td></tr><tr><td>Failed ❌</td><td>2</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>1</td></tr><tr><td>Todo 📝</td><td>1</td></tr><tr><td>Duration 🕐</td><td>*ms</td></tr></table>\n' at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/github/tests/index.test.js:32:5) at async Test.run (node:internal/test_runner/test:640:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:382:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: { stderr: '', stdout: "::debug::starting to run should fail\n::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_T
});

test('should noop if not in github actions', () => {
test('should noop if not in github actions', async () => {
const silentChild = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], { env: { } });
assert.strictEqual(silentChild.stderr?.toString(), '');
assert.strictEqual(silentChild.stdout?.toString(), '');
await snapshot(silentChild);

Check failure on line 37 in packages/github/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v18)

should noop if not in github actions

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected { exitCode: 1, stderr: '', + stdout: '' - stdout: '::debug::starting to run should fail\n' + - "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:216:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + - '::debug::starting to run should pass\n' + - '::debug::completed running should pass\n' + - '::group::Test results (1 passed, 1 failed)\n' + - '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + - '::endgroup::\n' }] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected { exitCode: 1, stderr: '', + stdout: '' - stdout: '::debug::starting to run should fail\n' + - "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:216:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + - '::debug::starting to run should pass\n' + - '::debug::completed running should pass\n' + - '::group::Test results (1 passed, 1 failed)\n' + - '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + - '::endgroup::\n' } at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/github/tests/index.test.js:37:5) at async Test.run (node:internal/test_runner/test:632:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: { stderr: '', stdout: '', exitCode: 1 }, expected: { stderr: '', stdout: "::debug::starting to run should fail\n::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:216:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n::debug::starting to run should pass\

Check failure on line 37 in packages/github/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v21)

should noop if not in github actions

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected { exitCode: 1, stderr: '', + stdout: '' - stdout: '::debug::starting to run should fail\n' + - "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:216:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + - '::debug::starting to run should pass\n' + - '::debug::completed running should pass\n' + - '::group::Test results (1 passed, 1 failed)\n' + - '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + - '::endgroup::\n' }] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected { exitCode: 1, stderr: '', + stdout: '' - stdout: '::debug::starting to run should fail\n' + - "::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:216:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n" + - '::debug::starting to run should pass\n' + - '::debug::completed running should pass\n' + - '::group::Test results (1 passed, 1 failed)\n' + - '::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: *ms\n' + - '::endgroup::\n' } at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/github/tests/index.test.js:37:5) at async Test.run (node:internal/test_runner/test:640:9) at async Suite.processPendingSubtests (node:internal/test_runner/test:382:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: { stderr: '', stdout: '', exitCode: 1 }, expected: { stderr: '', stdout: "::debug::starting to run should fail\n::error title=should fail,file=tests/example.mjs,line=5,col=3::[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:%0A%0A assert(false)%0A] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:%0A %0A assert(false)%0A %0A at TestContext.<anonymous> (file://CWD/tests/example.mjs:5:3)%0A at Test.runInAsyncScope (node:async_hooks:206:9)%0A at Test.run (node:internal/test_runner/test:631:25)%0A at Test.start (node:internal/test_runner/test:542:17)%0A at startSubtest (node:internal/test_runner/harness:216:17) {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}\n::debug::
});
});
27 changes: 0 additions & 27 deletions packages/github/tests/output-esm.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<testsuites>\n\t<testsuite name=\"tests\" time=\"*\" disabled=\"0\" errors=\"0\" tests=\"4\" failures=\"2\" skipped=\"0\" hostname=\"HOSTNAME\">\n\t\t<testcase name=\"is ok\" time=\"*\" classname=\"test\"/>\n\t\t<testcase name=\"fails\" time=\"*\" classname=\"test\" failure=\"this is an error\">\n\t\t\t<failure type=\"testCodeFailure\" message=\"this is an error\">\n[Error [ERR_TEST_FAILURE]: this is an error] {\n code: 'ERR_TEST_FAILURE',\n failureType: 'testCodeFailure',\n cause: Error: this is an error\n *\n *\n *\n *\n *\n *\n at async Promise.all (index 0)\n *\n *\n}\n\t\t\t</failure>\n\t\t</testcase>\n\t\t<testcase name=\"is a diagnostic\" time=\"*\" classname=\"test\"/>\n\t\t<testcase name=\"should fail\" time=\"*\" classname=\"test\" failure=\"The expression evaluated to a falsy value: assert(false)\">\n\t\t\t<failure type=\"testCodeFailure\" message=\"The expression evaluated to a falsy value: assert(false)\">\n[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n] {\n code: 'ERR_TEST_FAILURE',\n failureType: 'testCodeFailure',\n cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n \n assert(false)\n \n *\n *\n *\n *\n *\n *\n * {\n generatedMessage: true,\n code: 'ERR_ASSERTION',\n actual: false,\n expected: true,\n operator: '=='\n }\n}\n\t\t\t</failure>\n\t\t</testcase>\n\t</testsuite>\n\t<testsuite name=\"more tests\" time=\"*\" disabled=\"0\" errors=\"0\" tests=\"1\" failures=\"0\" skipped=\"0\" hostname=\"HOSTNAME\">\n\t\t<testcase name=\"is ok\" time=\"*\" classname=\"test\"/>\n\t</testsuite>\n\t<testcase name=\"is skipped\" time=\"*\" classname=\"test\">\n\t\t<skipped type=\"skipped\" message=\"true\"/>\n\t</testcase>\n\t<testcase name=\"is a todo\" time=\"*\" classname=\"test\">\n\t\t<skipped type=\"todo\" message=\"true\"/>\n\t</testcase>\n\t<testcase name=\"top level diagnostic\" time=\"*\" classname=\"test\"/>\n</testsuites>\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<testsuites>\n\t<testcase name=\"should fail\" time=\"*\" classname=\"test\" failure=\"The expression evaluated to a falsy value: assert(false)\">\n\t\t<failure type=\"testCodeFailure\" message=\"The expression evaluated to a falsy value: assert(false)\">\n[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n] {\n code: 'ERR_TEST_FAILURE',\n failureType: 'testCodeFailure',\n cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n \n assert(false)\n \n *\n *\n *\n *\n * {\n generatedMessage: true,\n code: 'ERR_ASSERTION',\n actual: false,\n expected: true,\n operator: '=='\n }\n}\n\t\t</failure>\n\t</testcase>\n\t<testcase name=\"should pass\" time=\"*\" classname=\"test\"/>\n</testsuites>\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<testsuites>\n",
"</testsuites>\n"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<testsuites>\n",
"\t<undefined name=\"root\">\n\t<testcase name=\"test\" time=\"0.100000\" classname=\"test\"/>\n\t</undefined>\n",
"</testsuites>\n"
]
33 changes: 9 additions & 24 deletions packages/junit/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,34 @@
const { test } = require('node:test');
const { spawnSync } = require('child_process');
const assert = require('assert');
const { compareLines } = require('../../../tests/utils');
const reporter = require('../index');
const output = require('./output');
const outputESM = require('./output-esm');
const { Snap } = require('../../../tests/utils');

const nodeMajor = process.versions.node.split('.')[0];
const snapshot = Snap(__filename);

test('spwan with reporter', () => {
test('spwan with reporter', async () => {
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], { env: {} });
assert.strictEqual(child.stderr?.toString(), '');
compareLines(child.stdout?.toString(), output.overrides[nodeMajor]?.stdout ?? output.stdout);
await snapshot(child);

Check failure on line 13 in packages/junit/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v18)

spwan with reporter

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, ... '\t\t\t<failure type="testCodeFailure" message="this is an error">\n' + '[Error [ERR_TEST_FAILURE]: this is an error] {\n' + + " failureType: 'testCodeFailure',\n" + + ' cause: Error: this is an error\n' + + ' *\n' + - " code: 'ERR_TEST_FAILURE',\n" + - " failureType: 'testCodeFailure',\n" + - ' cause: Error: this is an error\n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + + ' at async Promise.all (index 0)\n' + + ' *\n' + + ' at async startSubtest (node:internal/test_runner/harness:214:3),\n' + + " code: 'ERR_TEST_FAILURE'\n" + - ' *\n' + - ' at async Promise.all (index 0)\n' + - ' *\n' + - ' *\n' + '}\n' + '\t\t\t</failure>\n' + ... ' assert(false)\n' + '] {\n' + + " failureType: 'testCodeFailure',\n" + + ' cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n' + + ' \n' + + ' assert(false)\n' + + ' \n' + + ' *\n' + - " code: 'ERR_TEST_FAILURE',\n" + - " failureType: 'testCodeFailure',\n" + - ' cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n' + - ' \n' + - ' assert(false)\n' + - ' \n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + + ' * {\n' + + ' generatedMessage: true,\n' + + " code: 'ERR_ASSERTION',\n" + + ' actual: false,\n' + ... - ' *\n' + - ' * {\n' + - ' generatedMessage: true,\n' + - " code: 'ERR_ASSERTION',\n" + ...] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, ... '\t\t\t<failure type="testCodeFailure" message="this is an error">\n' + '[Error [ERR_TEST_FAILURE]: this is an error] {\n' + + " failureType: 'testCodeFailure',\n" + + ' cause: Error: this is an error\n' + + ' *\n' + - " code: 'ERR_TEST_FAILURE',\n" + - " failureType: 'testCodeFailure',\n" + - ' cause: Error: this is an error\n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + + ' at async Promise.all (index 0)\n' + + ' *\n' + + ' at async startSubtest (node:internal/test_runner/harness:214:3),\n' + + " code: 'ERR_TEST_FAILURE'\n" + - ' *\n' + - ' at async Promise.all (index 0)\n' + - ' *\n' + - ' *\n' + '}\n' + '\t\t\t</failure>\n' + ... ' assert(false)\n' + '] {\n' + + " failureType: 'testCodeFailure',\n" + + ' cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n' + + ' \n' + + ' assert(false)\n' + + ' \n' + + ' *\n' + - " code: 'ERR_TEST_FAILURE',\n" + - " failureType: 'testCodeFailure',\n" + - ' cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n' + - ' \n' + - ' assert(false)\n' + - ' \n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + ' *\n' + + ' * {\n' + + ' generatedMessage: true,\n' + + " code: 'ERR_ASSERTION',\n" + + ' actual: false,\n' + ... - ' *\n' + - ' * {\n' + - ' generatedMessage: true,\n' + - " code: 'ERR_ASSERTION',\n" + ... at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/junit/tests/index.test.js:13:3) at async Test.run (node:internal/test_runner/test:632:9) at async

Check failure on line 13 in packages/junit/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v21)

spwan with reporter

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, ... '\t\t<testcase name="fails" time="*" classname="test" failure="this is an error">\n' + '\t\t\t<failure type="testCodeFailure" message="this is an error">\n' + + 'Error [ERR_TEST_FAILURE]: this is an error\n' + + ' at async Promise.all (index 0) {\n' + - '[Error [ERR_TEST_FAILURE]: this is an error] {\n' + " code: 'ERR_TEST_FAILURE',\n" + ... '\t<testcase name="top level diagnostic" time="*" classname="test"/>\n' + '</testsuites>\n' }] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, ... '\t\t<testcase name="fails" time="*" classname="test" failure="this is an error">\n' + '\t\t\t<failure type="testCodeFailure" message="this is an error">\n' + + 'Error [ERR_TEST_FAILURE]: this is an error\n' + + ' at async Promise.all (index 0) {\n' + - '[Error [ERR_TEST_FAILURE]: this is an error] {\n' + " code: 'ERR_TEST_FAILURE',\n" + ... '\t<testcase name="top level diagnostic" time="*" classname="test"/>\n' + '</testsuites>\n' } at test (/home/runner/work/reporters/reporters/tests/utils.js:27:12) at async TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/junit/tests/index.test.js:13:3) at async Test.run (node:internal/test_runner/test:640:9) at async startSubtest (node:internal/test_runner/harness:218:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: { stderr: '', stdout: `<?xml version="1.0" encoding="utf-8"?>\n<testsuites>\n\t<testsuite name="tests" time="*" disabled="0" errors="0" tests="4" failures="2" skipped="0" hostname="HOSTNAME">\n\t\t<testcase name="is ok" time="*" classname="test"/>\n\t\t<testcase name="fails" time="*" classname="test" failure="this is an error">\n\t\t\t<failure type="testCodeFailure" message="this is an error">\nError [ERR_TEST_FAILURE]: this is an error\n at async Promise.all (index 0) {\n code: 'ERR_TEST_FAILURE',\n failureType: 'testCodeFailure',\n cause: Error: this is an error\n *\n *\n *\n *\n *\n *\n at async Promise.all (index 0)\n *\n *\n}\n\t\t\t</failure>\n\t\t</testcase>\n\t\t<testcase name="is a diagnostic" time="*" classname="test"/>\n\t\t<testcase name="should fail" time="*" classname="test" failure="The expression evaluated to a falsy value: assert(false)">\n\t\t\t<failure type="testCodeFailure" message="The expression evaluated to a falsy value: assert(false)">\n[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n] {\n code: 'ERR_TEST_FAILURE',\n failureType: 'testCodeFailure',\n cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n \n assert(false)\n \n *\n *\n *\n *\n *\n *\n * {\n generatedMessage: true,\n code: 'ERR_ASSERTION',\n actual: false,\n expected: true,\n operator: '=='\n }\n}\n\t\t\t</failure>\n\t\t</testcase>\n\t</testsuite>\n\t<testsuite name="more tests" time="*" disabled="0" errors="0" tests="1" failures="0" skipped="0" hostname="HOSTNAME">\n\t\t<testcase name="is ok" time="*" classname="test"/>\n\t</testsuite>\n\t<testcase name="is skipped" time="*" classname="test">\n\t\t<skipped type="skipped" message="true"/>\n\t</testcase>\n\t<testcase name="is a todo" time="*" classname="test">\n\t\t<skipped type="todo" message="true"/>\n\t</testcase>\n\t<testcase name="top level diagnostic" time="*" classname="test"/>\n</testsuites>\n`, exitCode: 1 }, expected: { stderr: '', stdout: `<?xml version="1.0" encoding="utf-8"?>\n<testsuites>\n\t<testsuite name="tests" time="*" disabled="0" errors="0" tests="4" failures="2" skipped="0" hostname="HOSTNAME">\n\t\t<testcase name="is ok" time="*" classname="test"/>\n\t\t<testcase nam
});

test('spwan with reporter -esm', () => {
test('spwan with reporter - esm', async () => {
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example.mjs'], { env: {} });
assert.strictEqual(child.stderr?.toString(), '');
compareLines(
child.stdout?.toString(),
outputESM.overrides[nodeMajor]?.stdout ?? outputESM.stdout,
);
await snapshot(child);

Check failure on line 18 in packages/junit/tests/index.test.js

View workflow job for this annotation

GitHub Actions / tests (v18)

spwan with reporter - esm

[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, stderr: '', stdout: '<?xml version="1.0" encoding="utf-8"?>\n' + '<testsuites>\n' + + '\t<testcase name="should fail" time="*" classname="test" failure="false == true">\n' + + '\t\t<failure type="testCodeFailure" message="false == true">\n' + + '[Error [ERR_TEST_FAILURE]: false == true] {\n' + + " failureType: 'testCodeFailure',\n" + + ' cause: AssertionError [ERR_ASSERTION]: false == true\n' + + ' *\n' + + ' *\n' + + ' *\n' + + ' *\n' + + ' * {\n' + + ' generatedMessage: true,\n' + + " code: 'ERR_ASSERTION',\n" + + ' actual: false,\n' + + ' expected: true,\n' + + " operator: '=='\n" + + ' },\n' + + " code: 'ERR_TEST_FAILURE'\n" + - '\t<testcase name="should fail" time="*" classname="test" failure="The expression evaluated to a falsy value: assert(false)">\n' + - '\t\t<failure type="testCodeFailure" message="The expression evaluated to a falsy value: assert(false)">\n' + - '[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n' + - '\n' + - ' assert(false)\n' + - '] {\n' + - " code: 'ERR_TEST_FAILURE',\n" + - " failureType: 'testCodeFailure',\n" + - ' cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n' + - ' \n' + - ' assert(false)\n' + - ' \n' + - ' *\n' + - ' *\n' + - ' *\n' + - ' *\n' + - ' * {\n' + - ' generatedMessage: true,\n' + - " code: 'ERR_ASSERTION',\n" + - ' actual: false,\n' + - ' expected: true,\n' + - " operator: '=='\n" + - ' }\n' + '}\n' + ... '\t<testcase name="should pass" time="*" classname="test"/>\n' + '</testsuites>\n' }] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected ... Lines skipped { exitCode: 1, stderr: '', stdout: '<?xml version="1.0" encoding="utf-8"?>\n' + '<testsuites>\n' + + '\t<testcase name="should fail" time="*" classname="test" failure="false == true">\n' + + '\t\t<failure type="testCodeFailure" message="false == true">\n' + + '[Error [ERR_TEST_FAILURE]: false == true] {\n' + + " failureType: 'testCodeFailure',\n" + + ' cause: AssertionError [ERR_ASSERTION]: false == true\n' + + ' *\n' + + ' *\n' + + ' *\n' + + ' *\n' + + ' * {\n' + + ' generatedMessage: true,\n' + + " code: 'ERR_ASSERTION',\n" + + ' actual: false,\n' + + ' expected: true,\n' + + " operator: '=='\n" + + ' },\n' + + " code: 'ERR_TEST_FAILURE'\n" + - '\t<testcase name="should fail" time="*" classname="test" failure="The expression evaluated to a falsy value: assert(false)">\n' + - '\t\t<failure type="testCodeFailure" message="The expression evaluated to a falsy value: assert(false)">\n' + - '[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n' + - '\n' + - ' assert(false)\n' + - '] {\n' + - " code: 'ERR_TEST_FAILURE',\n" + - " failureType: 'testCodeFailure',\n" + - ' cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:\n' + - ' \n' + - ' assert(false)\n' + - ' \n' + - ' *\n' + - ' *\n' + - ' *\n' + - ' *\n' + - ' * {\n' + - ' generatedMessage: true,\n' + - " code: 'ERR_ASSERTION',\n" + - ' actual: false,\n' + - ' expected: true,\n' + - " operator: '=='\n" + - ' }\n' + '}\n' + ... '\t<testcase name="should pass" time="*" classname="test"/>\n' + '</testsuites>\n' } at test (/home/runner/work/reporters/reporters/tests/util
});

test('empty', async () => {
const lines = [];
for await (const line of reporter([])) {
lines.push(line);
}
assert.deepStrictEqual(lines, [
'<?xml version="1.0" encoding="utf-8"?>\n',
'<testsuites>\n',
'</testsuites>\n',
]);

assert.deepStrictEqual(lines, await snapshot.snap(lines));
});

test('single test', async () => {
const lines = [];
for await (const line of reporter([{ type: 'test:pass', data: { name: 'test', nesting: 0, details: { duration_ms: 100 } } }])) {
lines.push(line);
}
assert.deepStrictEqual(lines, [
'<?xml version="1.0" encoding="utf-8"?>\n',
'<testsuites>\n',
'\t<undefined name="root">\n\t<testcase name="test" time="0.100000" classname="test"/>\n\t</undefined>\n',
'</testsuites>\n',
]);
assert.deepStrictEqual(lines, await snapshot.snap(lines));
});
64 changes: 0 additions & 64 deletions packages/junit/tests/output-esm.js

This file was deleted.

Loading

0 comments on commit 24fafdd

Please sign in to comment.