From 1d3ca6ad12b4abb5c47adc775b47c205a4214e0a Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Thu, 14 Mar 2024 00:53:17 +0200 Subject: [PATCH] test: migrate snapshots to snap (#114) --- package.json | 1 + .../bc72bb2843f04838a97cba748b6c200f/0.json | 5 + .../bc72bb2843f04838a97cba748b6c200f/1.json | 5 + packages/bail/index.js | 2 + packages/bail/tests/index.test.js | 15 +- .../1f0f93c51b9f571a9d899160525b1bcb/0.json | 5 + .../1f0f93c51b9f571a9d899160525b1bcb/1.json | 1 + .../1f0f93c51b9f571a9d899160525b1bcb/2.json | 5 + .../1f0f93c51b9f571a9d899160525b1bcb/3.json | 1 + .../1f0f93c51b9f571a9d899160525b1bcb/4.json | 5 + .../4353502ed400317a687af8c8312f2662/0.json | 5 + .../4353502ed400317a687af8c8312f2662/1.json | 1 + .../4353502ed400317a687af8c8312f2662/2.json | 5 + .../4353502ed400317a687af8c8312f2662/3.json | 1 + .../4353502ed400317a687af8c8312f2662/4.json | 5 + .../dc3fc117f81a81ae79e191693864201a/0.json | 5 + .../dc3fc117f81a81ae79e191693864201a/1.json | 1 + .../dc3fc117f81a81ae79e191693864201a/2.json | 5 + .../dc3fc117f81a81ae79e191693864201a/3.json | 1 + .../dc3fc117f81a81ae79e191693864201a/4.json | 5 + packages/github/tests/index.test.js | 27 ++-- packages/github/tests/output-esm.js | 27 ---- .../1f0f93c51b9f571a9d899160525b1bcb/0.json | 5 + .../1f0f93c51b9f571a9d899160525b1bcb/1.json | 5 + .../1f0f93c51b9f571a9d899160525b1bcb/2.json | 5 + .../1f0f93c51b9f571a9d899160525b1bcb/3.json | 6 + .../4353502ed400317a687af8c8312f2662/0.json | 5 + .../4353502ed400317a687af8c8312f2662/1.json | 5 + .../4353502ed400317a687af8c8312f2662/2.json | 5 + .../4353502ed400317a687af8c8312f2662/3.json | 6 + .../dc3fc117f81a81ae79e191693864201a/0.json | 5 + .../dc3fc117f81a81ae79e191693864201a/1.json | 5 + .../dc3fc117f81a81ae79e191693864201a/2.json | 5 + .../dc3fc117f81a81ae79e191693864201a/3.json | 6 + packages/junit/tests/index.test.js | 33 ++--- packages/junit/tests/output-esm.js | 64 --------- packages/junit/tests/output.js | 136 ------------------ .../bc72bb2843f04838a97cba748b6c200f/0.json | 5 + .../bc72bb2843f04838a97cba748b6c200f/1.json | 5 + packages/silent/tests/index.test.js | 14 +- .../bc72bb2843f04838a97cba748b6c200f/0.json | 5 + packages/slow/tests/index.test.js | 15 +- tests/utils.js | 51 +++++-- yarn.lock | 58 ++++++++ 44 files changed, 272 insertions(+), 310 deletions(-) create mode 100644 packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json create mode 100644 packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json create mode 100644 packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json create mode 100644 packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json create mode 100644 packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json create mode 100644 packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json create mode 100644 packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/4.json create mode 100644 packages/github/.snapshots/4353502ed400317a687af8c8312f2662/0.json create mode 100644 packages/github/.snapshots/4353502ed400317a687af8c8312f2662/1.json create mode 100644 packages/github/.snapshots/4353502ed400317a687af8c8312f2662/2.json create mode 100644 packages/github/.snapshots/4353502ed400317a687af8c8312f2662/3.json create mode 100644 packages/github/.snapshots/4353502ed400317a687af8c8312f2662/4.json create mode 100644 packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json create mode 100644 packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json create mode 100644 packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json create mode 100644 packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json create mode 100644 packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/4.json delete mode 100644 packages/github/tests/output-esm.js create mode 100644 packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json create mode 100644 packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json create mode 100644 packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json create mode 100644 packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json create mode 100644 packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/0.json create mode 100644 packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/1.json create mode 100644 packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/2.json create mode 100644 packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/3.json create mode 100644 packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json create mode 100644 packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json create mode 100644 packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json create mode 100644 packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json delete mode 100644 packages/junit/tests/output-esm.js delete mode 100644 packages/junit/tests/output.js create mode 100644 packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json create mode 100644 packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json create mode 100644 packages/slow/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json diff --git a/package.json b/package.json index f5b1562..314d6f9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json b/packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json new file mode 100644 index 0000000..06976e1 --- /dev/null +++ b/packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": ".\n", + "exitCode": 0 +} \ No newline at end of file diff --git a/packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json b/packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json new file mode 100644 index 0000000..57164ff --- /dev/null +++ b/packages/bail/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json @@ -0,0 +1,5 @@ +{ + "stderr": "node:internal/test_runner/harness:*\n throw err;\n ^\n\nError: Bail\n *\n at bail.next ()\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 +} \ No newline at end of file diff --git a/packages/bail/index.js b/packages/bail/index.js index 2155668..202ca30 100644 --- a/packages/bail/index.js +++ b/packages/bail/index.js @@ -3,8 +3,10 @@ module.exports = async function* bail(source) { for await (const event of source) { if (event.type === 'test:fail') { + /* c8 ignore start */ yield `\n\u001b[31m✖ Bailing on failed test: ${event.data.name}\u001b[0m\n`; throw new Error('Bail'); + /* c8 ignore stop */ } } }; diff --git a/packages/bail/tests/index.test.js b/packages/bail/tests/index.test.js index 3537c57..85f0a89 100644 --- a/packages/bail/tests/index.test.js +++ b/packages/bail/tests/index.test.js @@ -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); }); diff --git a/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json new file mode 100644 index 0000000..45fae9b --- /dev/null +++ b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json @@ -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 at async Promise.all (index 0) {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext. (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::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. (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::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 +} \ No newline at end of file diff --git a/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json new file mode 100644 index 0000000..d99140f --- /dev/null +++ b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json @@ -0,0 +1 @@ +"

Test Results

\n
Total Tests8
Suites 📂2
Passed ✅4
Failed ❌2
Canceled 🚫0
Skipped ⏭️1
Todo 📝1
Duration 🕐*ms
\n" \ No newline at end of file diff --git a/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json new file mode 100644 index 0000000..23d6841 --- /dev/null +++ b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json @@ -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. (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", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json new file mode 100644 index 0000000..d046fe4 --- /dev/null +++ b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json @@ -0,0 +1 @@ +"

Test Results

\n
Total Tests2
Suites 📂0
Passed ✅1
Failed ❌1
Canceled 🚫0
Skipped ⏭️0
Todo 📝0
Duration 🕐*ms
\n" \ No newline at end of file diff --git a/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/4.json b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/4.json new file mode 100644 index 0000000..6b29232 --- /dev/null +++ b/packages/github/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/4.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/0.json b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/0.json new file mode 100644 index 0000000..3c2b389 --- /dev/null +++ b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/0.json @@ -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 failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext. (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::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. (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::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 +} \ No newline at end of file diff --git a/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/1.json b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/1.json new file mode 100644 index 0000000..d99140f --- /dev/null +++ b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/1.json @@ -0,0 +1 @@ +"

Test Results

\n
Total Tests8
Suites 📂2
Passed ✅4
Failed ❌2
Canceled 🚫0
Skipped ⏭️1
Todo 📝1
Duration 🕐*ms
\n" \ No newline at end of file diff --git a/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/2.json b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/2.json new file mode 100644 index 0000000..3df42bd --- /dev/null +++ b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/2.json @@ -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]: false == true] {%0A failureType: 'testCodeFailure',%0A cause: AssertionError [ERR_ASSERTION]: false == true%0A at TestContext. (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", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/3.json b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/3.json new file mode 100644 index 0000000..d046fe4 --- /dev/null +++ b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/3.json @@ -0,0 +1 @@ +"

Test Results

\n
Total Tests2
Suites 📂0
Passed ✅1
Failed ❌1
Canceled 🚫0
Skipped ⏭️0
Todo 📝0
Duration 🕐*ms
\n" \ No newline at end of file diff --git a/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/4.json b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/4.json new file mode 100644 index 0000000..6b29232 --- /dev/null +++ b/packages/github/.snapshots/4353502ed400317a687af8c8312f2662/4.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json new file mode 100644 index 0000000..af52572 --- /dev/null +++ b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json @@ -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. (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. (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 +} \ No newline at end of file diff --git a/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json new file mode 100644 index 0000000..d99140f --- /dev/null +++ b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json @@ -0,0 +1 @@ +"

Test Results

\n
Total Tests8
Suites 📂2
Passed ✅4
Failed ❌2
Canceled 🚫0
Skipped ⏭️1
Todo 📝1
Duration 🕐*ms
\n" \ No newline at end of file diff --git a/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json new file mode 100644 index 0000000..83b5627 --- /dev/null +++ b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json @@ -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. (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 +} \ No newline at end of file diff --git a/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json new file mode 100644 index 0000000..d046fe4 --- /dev/null +++ b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json @@ -0,0 +1 @@ +"

Test Results

\n
Total Tests2
Suites 📂0
Passed ✅1
Failed ❌1
Canceled 🚫0
Skipped ⏭️0
Todo 📝0
Duration 🕐*ms
\n" \ No newline at end of file diff --git a/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/4.json b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/4.json new file mode 100644 index 0000000..6b29232 --- /dev/null +++ b/packages/github/.snapshots/dc3fc117f81a81ae79e191693864201a/4.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/github/tests/index.test.js b/packages/github/tests/index.test.js index 05a7b72..02d253b 100644 --- a/packages/github/tests/index.test.js +++ b/packages/github/tests/index.test.js @@ -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, nodeMajor } = require('../../../tests/utils'); +const snapshot = Snap(`${__filename}.${nodeMajor}`); 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')); }); - 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')); }); - 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); }); }); diff --git a/packages/github/tests/output-esm.js b/packages/github/tests/output-esm.js deleted file mode 100644 index 945accc..0000000 --- a/packages/github/tests/output-esm.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -module.exports = { - stdout: `::debug::starting to run should fail -::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. \\(file:///.*/example.mjs:5:3\\)%0A.* {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A} -::debug::starting to run should pass -::debug::completed running should pass -::group::Test results \\(1 passed, 1 failed\\) -::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: .*ms -::endgroup:: -`, - summary: `

Test Results

-
Total Tests2
Suites 📂0
Passed ✅1
Failed ❌1
Canceled 🚫0
Skipped ⏭️0
Todo 📝0
Duration 🕐.*ms
-`, - overrides: { - 18: { - stdout: `::debug::starting to run should fail -::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.* {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A },%0A code: 'ERR_TEST_FAILURE'%0A} -::debug::starting to run should pass -::debug::completed running should pass -::group::Test results \\(1 passed, 1 failed\\) -::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: .*ms -::endgroup:: -`, - }, - }, -}; diff --git a/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json new file mode 100644 index 0000000..4d44ab7 --- /dev/null +++ b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/0.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "\n\n\t\n\t\t\n\t\t\n\t\t\t\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\n\t\t\n\t\t\n\t\t\n\t\t\t\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\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\n", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json new file mode 100644 index 0000000..8412e9d --- /dev/null +++ b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/1.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "\n\n\t\n\t\t\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\n\t\n\t\n\n", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json new file mode 100644 index 0000000..3f20a94 --- /dev/null +++ b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/2.json @@ -0,0 +1,5 @@ +[ + "\n", + "\n", + "\n" +] \ No newline at end of file diff --git a/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json new file mode 100644 index 0000000..9493fc6 --- /dev/null +++ b/packages/junit/.snapshots/1f0f93c51b9f571a9d899160525b1bcb/3.json @@ -0,0 +1,6 @@ +[ + "\n", + "\n", + "\t\n\t\n\t\n", + "\n" +] \ No newline at end of file diff --git a/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/0.json b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/0.json new file mode 100644 index 0000000..411bf85 --- /dev/null +++ b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/0.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "\n\n\t\n\t\t\n\t\t\n\t\t\t\n[Error [ERR_TEST_FAILURE]: this is an error] {\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 at async startSubtest (node:internal/test_runner/harness:214:3),\n code: 'ERR_TEST_FAILURE'\n}\n\t\t\t\n\t\t\n\t\t\n\t\t\n\t\t\t\n[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\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 *\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}\n\t\t\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\n", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/1.json b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/1.json new file mode 100644 index 0000000..9692f7c --- /dev/null +++ b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/1.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "\n\n\t\n\t\t\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}\n\t\t\n\t\n\t\n\n", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/2.json b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/2.json new file mode 100644 index 0000000..3f20a94 --- /dev/null +++ b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/2.json @@ -0,0 +1,5 @@ +[ + "\n", + "\n", + "\n" +] \ No newline at end of file diff --git a/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/3.json b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/3.json new file mode 100644 index 0000000..9493fc6 --- /dev/null +++ b/packages/junit/.snapshots/4353502ed400317a687af8c8312f2662/3.json @@ -0,0 +1,6 @@ +[ + "\n", + "\n", + "\t\n\t\n\t\n", + "\n" +] \ No newline at end of file diff --git a/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json new file mode 100644 index 0000000..303b4db --- /dev/null +++ b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/0.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "\n\n\t\n\t\t\n\t\t\n\t\t\t\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\n\t\t\n\t\t\n\t\t\n\t\t\t\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\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n\n", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json new file mode 100644 index 0000000..8412e9d --- /dev/null +++ b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/1.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "\n\n\t\n\t\t\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\n\t\n\t\n\n", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json new file mode 100644 index 0000000..3f20a94 --- /dev/null +++ b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/2.json @@ -0,0 +1,5 @@ +[ + "\n", + "\n", + "\n" +] \ No newline at end of file diff --git a/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json new file mode 100644 index 0000000..9493fc6 --- /dev/null +++ b/packages/junit/.snapshots/dc3fc117f81a81ae79e191693864201a/3.json @@ -0,0 +1,6 @@ +[ + "\n", + "\n", + "\t\n\t\n\t\n", + "\n" +] \ No newline at end of file diff --git a/packages/junit/tests/index.test.js b/packages/junit/tests/index.test.js index 17e6fe6..5234615 100644 --- a/packages/junit/tests/index.test.js +++ b/packages/junit/tests/index.test.js @@ -3,26 +3,19 @@ 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, nodeMajor } = require('../../../tests/utils'); -const nodeMajor = process.versions.node.split('.')[0]; +const snapshot = Snap(`${__filename}.${nodeMajor}`); -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); }); -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); }); test('empty', async () => { @@ -30,11 +23,8 @@ test('empty', async () => { for await (const line of reporter([])) { lines.push(line); } - assert.deepStrictEqual(lines, [ - '\n', - '\n', - '\n', - ]); + + assert.deepStrictEqual(lines, await snapshot.snap(lines)); }); test('single test', async () => { @@ -42,10 +32,5 @@ test('single test', async () => { for await (const line of reporter([{ type: 'test:pass', data: { name: 'test', nesting: 0, details: { duration_ms: 100 } } }])) { lines.push(line); } - assert.deepStrictEqual(lines, [ - '\n', - '\n', - '\t\n\t\n\t\n', - '\n', - ]); + assert.deepStrictEqual(lines, await snapshot.snap(lines)); }); diff --git a/packages/junit/tests/output-esm.js b/packages/junit/tests/output-esm.js deleted file mode 100644 index 8e9753f..0000000 --- a/packages/junit/tests/output-esm.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -module.exports = { - stdout: `<\\?xml version="1.0" encoding="utf-8"\\?> - -\t -\t\t -\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value: - - assert\\(false\\) -] { - code: 'ERR_TEST_FAILURE', - failureType: 'testCodeFailure', - cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value: - - assert\\(false\\) - - at .* - at .* - at .* - at .* - at .* { - generatedMessage: true, - code: 'ERR_ASSERTION', - actual: false, - expected: true, - operator: '==' - } -} -\t\t -\t -\t - -`, - overrides: { - 18: { - stdout: `<\\?xml version="1.0" encoding="utf-8"\\?> - -\t -\t\t -\\[Error \\[ERR_TEST_FAILURE\\]: false == true\\] { - failureType: 'testCodeFailure', - cause: AssertionError \\[ERR_ASSERTION\\]: false == true - at TestContext.*/example.mjs:5:3\\) - at .* - at .* - at .* - at .* { - generatedMessage: true, - code: 'ERR_ASSERTION', - actual: false, - expected: true, - operator: '==' - }, - code: 'ERR_TEST_FAILURE' -} -\t\t -\t -\t - -`, - }, - }, -}; diff --git a/packages/junit/tests/output.js b/packages/junit/tests/output.js deleted file mode 100644 index b18389d..0000000 --- a/packages/junit/tests/output.js +++ /dev/null @@ -1,136 +0,0 @@ -'use strict'; - -module.exports = { - stdout: `<\\?xml version="1.0" encoding="utf-8"\\?> - -\t -\t\t -\t\t -\t\t\t -\\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] { - code: 'ERR_TEST_FAILURE', - failureType: 'testCodeFailure', - cause: Error: this is an error - .* - .* - .* - .* - .* - .* - .* - .* - .* -} -\t\t\t -\t\t -\t\t -\t\t -\t\t -\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value: - -assert\\(false\\) -\\] { -code: 'ERR_TEST_FAILURE', -failureType: 'testCodeFailure', -cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value: - - assert\\(false\\) - - at TestContext.* \\(.*/example.js:12:31\\) - at .* - at .* - at .* - at .* - at .* - at .* { - generatedMessage: true, - code: 'ERR_ASSERTION', - actual: false, - expected: true, - operator: '==' -} -} -\t\t\t -\t\t -\t -\t -\t\t -\t -\t -\t\t -\t -\t -\t\t -\t -\t - -`, - overrides: { - 18: { - stdout: `<\\?xml version="1.0" encoding="utf-8"\\?> - -\t -\t\t -\t\t -\t\t\t -\\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] { - failureType: 'testCodeFailure', - cause: Error: this is an error - .* - .* - .* - .* - .* - .* - .* - .* - .* - code: 'ERR_TEST_FAILURE' -} -\t\t\t -\t\t -\t\t -\t\t -\t\t -\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value: - -assert\\(false\\) -\\] { -failureType: 'testCodeFailure', -cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value: - - assert\\(false\\) - - at TestContext.* \\(.*/example.js:12:31\\) - at .* - at .* - at .* - at .* - at .* - at .* { - generatedMessage: true, - code: 'ERR_ASSERTION', - actual: false, - expected: true, - operator: '==' -}, -code: 'ERR_TEST_FAILURE' -} -\t\t\t -\t\t -\t -\t -\t\t -\t -\t -\t\t -\t -\t -\t\t -\t -\t - -`, - }, - }, -}; diff --git a/packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json b/packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json new file mode 100644 index 0000000..6b29232 --- /dev/null +++ b/packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json b/packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json new file mode 100644 index 0000000..6b29232 --- /dev/null +++ b/packages/silent/.snapshots/bc72bb2843f04838a97cba748b6c200f/1.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/silent/tests/index.test.js b/packages/silent/tests/index.test.js index ef8707b..698ceeb 100644 --- a/packages/silent/tests/index.test.js +++ b/packages/silent/tests/index.test.js @@ -2,16 +2,16 @@ const { test } = require('node:test'); const { spawnSync } = require('child_process'); -const assert = require('assert'); +const { Snap } = require('../../../tests/utils'); -test('spwan with reporter', () => { +const snapshot = Snap(__filename); + +test('spwan with reporter', async () => { const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], { env: {} }); - assert.strictEqual(child.stderr?.toString(), ''); - assert.strictEqual(child.stdout?.toString(), ''); + await snapshot(child); }); -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(), ''); - assert.strictEqual(child.stdout?.toString(), ''); + await snapshot(child); }); diff --git a/packages/slow/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json b/packages/slow/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json new file mode 100644 index 0000000..b28a11c --- /dev/null +++ b/packages/slow/.snapshots/bc72bb2843f04838a97cba748b6c200f/0.json @@ -0,0 +1,5 @@ +{ + "stderr": "", + "stdout": "file: CWD/tests/slow_tests.js has slow tests:\n *\n *\n *\n", + "exitCode": 1 +} \ No newline at end of file diff --git a/packages/slow/tests/index.test.js b/packages/slow/tests/index.test.js index a9be7fd..6a4d6b7 100644 --- a/packages/slow/tests/index.test.js +++ b/packages/slow/tests/index.test.js @@ -1,17 +1,12 @@ 'use strict'; -const assert = require('assert'); const { test } = require('node:test'); const { spawnSync } = require('child_process'); -const { compareLines } = require('../../../tests/utils'); +const { Snap } = require('../../../tests/utils'); -test('spwan with reporter', () => { +const snapshot = Snap(__filename); + +test('spwan with reporter', async () => { const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/slow_tests.js'], { env: { FORCE_COLOR: 1 } }); - assert.strictEqual(child.stderr?.toString(), ''); - compareLines(child.stdout?.toString(), `\ -file: .*tests/slow_tests\\.js has slow tests: - \\\x1B\\[31m-\\\x1B\\[0m is too slow \\[\x1B\\[31m1s\\\x1B\\[0m\\] \\(\\\x1B\\[0m.*tests/slow_tests\\.js:9:3\\) - \\\x1B\\[38;5;215m-\\\x1B\\[0m is pretty slow \\[\\\x1B\\[38;5;215m.*ms\\\x1B\\[0m\\] \\(\\\x1B\\[0m.*tests/slow_tests\\.js:8:3\\) - \\\x1B\\[33m-\\\x1B\\[0m is a little slow \\[\x1B\\[33m.*ms\\\x1B\\[0m\\] \\(\\\x1B\\[0m.*tests/slow_tests\\.js:7:3\\) -`); + await snapshot(child); }); diff --git a/tests/utils.js b/tests/utils.js index f711434..546380d 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -1,23 +1,44 @@ 'use strict'; -/* eslint-disable no-console */ -const assert = require('assert'); +const assert = require('node:assert'); +const { hostname } = require('node:os'); +const { resolve } = require('node:path'); +// eslint-disable-next-line import/no-unresolved +const Snap = require('@matteo.collina/snap'); -function compareLines(output = '', expected = '') { - const outputLines = output.split(/\r?\n/); - const expectedLines = expected.split(/\r?\n/); - if (outputLines.length !== expectedLines.length) { - console.log(output); - console.log(expected); - assert.strictEqual(outputLines.length, expectedLines.length, 'Output and expected have different number of lines'); - } - for (let i = 0; i < expectedLines.length; i += 1) { - const expectedRegex = new RegExp(expectedLines[i]); - assert.match(outputLines[i], expectedRegex, `Line ${i} did not match`); +const nodeMajor = process.versions.node.split('.')[0]; + +function sanitize(str) { + return str + .replaceAll(resolve(process.cwd(), '../../'), 'CWD') + .replaceAll(process.version, '*') + .replaceAll(/[0-9.]+ms/g, '*ms') + .replaceAll(hostname(), 'HOSTNAME') + .replaceAll(/time="[0-9.]+"/g, 'time="*"') + .replaceAll(/test_runner\/harness:[0-9.]+\n/g, 'test_runner/harness:*\n') + .replace(/(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g, '$1*$7$8\n'); +} + +function snapshot(filename) { + const snap = Snap(filename); + async function test(child, ...args) { + const actual = { + stderr: sanitize(child.stderr?.toString() ?? ''), + stdout: sanitize(child.stdout?.toString()), + exitCode: child.status, + }; + assert.deepStrictEqual(actual, await snap(actual)); + for (const arg of args) { + const a = typeof arg === 'string' ? sanitize(arg) : arg; + // eslint-disable-next-line no-await-in-loop + assert.deepStrictEqual(a, await snap(a)); + } } - return true; + test.snap = snap; + return test; } module.exports = { - compareLines, + Snap: snapshot, + nodeMajor, }; diff --git a/yarn.lock b/yarn.lock index d63f22c..e6f680e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -91,6 +91,14 @@ "@jridgewell/resolve-uri" "3.1.0" "@jridgewell/sourcemap-codec" "1.4.14" +"@matteo.collina/snap@^0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@matteo.collina/snap/-/snap-0.2.1.tgz#597b2aaa27098930d7e54b9f8fa4fb0bab2e0783" + integrity sha512-rXCDKwOhAHzjmHUxEjKcmhvuhzF6gY0JWhpol9lTA+n5V1yTrbKNHNCe5ovxZjPw25PusmIEbYBIswC3ZUjhNQ== + dependencies: + find-up "^7.0.0" + slash "^5.1.0" + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -608,6 +616,15 @@ find-up@^5.0.0: locate-path "^6.0.0" path-exists "^4.0.0" +find-up@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-7.0.0.tgz#e8dec1455f74f78d888ad65bf7ca13dd2b4e66fb" + integrity sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g== + dependencies: + locate-path "^7.2.0" + path-exists "^5.0.0" + unicorn-magic "^0.1.0" + flat-cache@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11" @@ -998,6 +1015,13 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" +locate-path@^7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-7.2.0.tgz#69cb1779bd90b35ab1e771e1f2f89a202c2a8a8a" + integrity sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA== + dependencies: + p-locate "^6.0.0" + lodash.merge@^4.6.2: version "4.6.2" resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" @@ -1123,6 +1147,13 @@ p-limit@^3.0.2: dependencies: yocto-queue "^0.1.0" +p-limit@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-4.0.0.tgz#914af6544ed32bfa54670b061cafcbd04984b644" + integrity sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ== + dependencies: + yocto-queue "^1.0.0" + p-locate@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834" @@ -1130,6 +1161,13 @@ p-locate@^5.0.0: dependencies: p-limit "^3.0.2" +p-locate@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-6.0.0.tgz#3da9a49d4934b901089dca3302fa65dc5a05c04f" + integrity sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw== + dependencies: + p-limit "^4.0.0" + parent-module@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2" @@ -1142,6 +1180,11 @@ path-exists@^4.0.0: resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== +path-exists@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-5.0.0.tgz#a6aad9489200b21fab31e49cf09277e5116fb9e7" + integrity sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ== + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -1277,6 +1320,11 @@ signal-exit@^4.0.1: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.0.2.tgz#ff55bb1d9ff2114c13b400688fa544ac63c36967" integrity sha512-MY2/qGx4enyjprQnFaZsHib3Yadh3IXyV2C321GY0pjGfVBu4un0uDJkwgdxqO+Rdx8JMT8IfJIRwbYVz3Ob3Q== +slash@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-5.1.0.tgz#be3adddcdf09ac38eebe8dcdc7b1a57a75b095ce" + integrity sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg== + stack-utils@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.6.tgz#aaf0748169c02fc33c8232abccf933f54a1cc34f" @@ -1407,6 +1455,11 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" +unicorn-magic@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/unicorn-magic/-/unicorn-magic-0.1.0.tgz#1bb9a51c823aaf9d73a8bfcd3d1a23dde94b0ce4" + integrity sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ== + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" @@ -1501,3 +1554,8 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + +yocto-queue@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251" + integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==