Skip to content

Commit

Permalink
fix,test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Jan 4, 2024
1 parent 6cd3790 commit 2f9a9dd
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [v18, v19, v20]
node: [v18, v20, v21]
steps:
- uses: actions/checkout@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions packages/bail/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test('fail should stop after failed test', () => {
'--test-reporter', './index.js', '--test-reporter-destination', 'stdout',
'tests/fixtures/fail.js', 'tests/fixtures/pass.js',
], { env: {} });
assert.strictEqual(child.stderr?.toString(), '');
assert.strictEqual(child.stdout?.toString(), 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n');
assert.strictEqual(child.status, 1);
assert.strictEqual(child.status, 7);
});
6 changes: 5 additions & 1 deletion packages/github/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const output = require('./output');
const outputESM = require('./output-esm');

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

describe('github reporter', () => {
beforeEach(() => {
Expand All @@ -34,7 +35,10 @@ describe('github reporter', () => {
});

assert.strictEqual(child.stderr?.toString(), '');
compareLines(child.stdout?.toString(), outputESM.stdout);
compareLines(

Check failure on line 38 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]: Line 1 did not match] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Line 1 did not match at compareLines (/home/runner/work/reporters/reporters/tests/utils.js:18:12) at TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/github/tests/index.test.js:38:5) at Test.runInAsyncScope (node:async_hooks:203:9) at Test.run (node:internal/test_runner/test:631:25) at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) { generatedMessage: false, code: 'ERR_ASSERTION', actual: "::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:///home/runner/work/reporters/reporters/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}", expected: /:error title=should fail,file=tests\/example.mjs,line=5,col=3::\[Error \[ERR_TEST_FAILURE\]: false == true\] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError \[ERR_ASSERTION\]: false == true%0A at TestContext.<anonymous> \(file:\/\/\/.*\/example.mjs:5:3\)%0A.* {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A}/, operator: 'match' }, code: 'ERR_TEST_FAILURE' }
child.stdout?.toString(),
outputESM.overrides[nodeMajor]?.stdout ?? outputESM.stdout,
);
compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), outputESM.summary);
});

Expand Down
14 changes: 13 additions & 1 deletion packages/github/tests/output-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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\\]: false == true\\] {%0A failureType: 'testCodeFailure',%0A cause: AssertionError \\[ERR_ASSERTION\\]: false == true%0A at TestContext.<anonymous> \\(.*/example.mjs:5:3\\).* code: 'ERR_TEST_FAILURE'%0A}
:error title=should fail,file=tests/example.mjs,line=5,col=3::\\[Error \\[ERR_TEST_FAILURE\\]: false == true\\] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError \\[ERR_ASSERTION\\]: false == true%0A at TestContext.<anonymous> \\(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\\)
Expand All @@ -12,4 +12,16 @@ module.exports = {
summary: `<h1>Test Results</h1>
<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>
`,
overrides: {
21: {
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.<anonymous> \\(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::
`,
},
},
};
4 changes: 2 additions & 2 deletions packages/github/tests/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {
::debug::starting to run is ok
::debug::completed running is ok
::debug::starting to run fails
::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> (.*/example.js:9:11).* code: 'ERR_TEST_FAILURE'%0A}
::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> (.*/example.js:9:11).*%0A}
::debug::starting to run is a diagnostic
::debug::completed running is a diagnostic
::notice file=tests/example.js::this is a diagnostic
::debug::starting to run should fail
::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> (.*/example.js:12:31).*
::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> (.*/example.js:12:31).*
::debug::starting to run more tests
::debug::starting to run is ok
::debug::completed running is ok
Expand Down
7 changes: 6 additions & 1 deletion packages/junit/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const reporter = require('../index');
const output = require('./output');
const outputESM = require('./output-esm');

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

test('spwan with reporter', () => {
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], { env: {} });
assert.strictEqual(child.stderr?.toString(), '');
Expand All @@ -17,7 +19,10 @@ test('spwan with reporter', () => {
test('spwan with reporter -esm', () => {
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example.mjs'], { env: {} });
assert.strictEqual(child.stderr?.toString(), '');
compareLines(child.stdout?.toString(), outputESM.stdout);
compareLines(

Check failure on line 22 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]: Line 5 did not match] { failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Line 5 did not match at compareLines (/home/runner/work/reporters/reporters/tests/utils.js:18:12) at TestContext.<anonymous> (/home/runner/work/reporters/reporters/packages/junit/tests/index.test.js:22:3) at Test.runInAsyncScope (node:async_hooks:203:9) at Test.run (node:internal/test_runner/test:631:25) at Test.processPendingSubtests (node:internal/test_runner/test:374:18) at Test.postRun (node:internal/test_runner/test:715:19) at Test.run (node:internal/test_runner/test:673:12) at async startSubtest (node:internal/test_runner/harness:214:3) { generatedMessage: false, code: 'ERR_ASSERTION', actual: " failureType: 'testCodeFailure',", expected: / code: 'ERR_TEST_FAILURE',/, operator: 'match' }, code: 'ERR_TEST_FAILURE' }
child.stdout?.toString(),
outputESM.overrides[nodeMajor]?.stdout ?? outputESM.stdout,
);
});

test('empty', async () => {
Expand Down
39 changes: 37 additions & 2 deletions packages/junit/tests/output-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
\t<testcase name="should fail" time=".*" classname="test" failure="false == true">
\t\t<failure type="testCodeFailure" message="false == true">
\\[Error \\[ERR_TEST_FAILURE\\]: false == true\\] {
code: 'ERR_TEST_FAILURE',
failureType: 'testCodeFailure',
cause: AssertionError \\[ERR_ASSERTION\\]: false == true
at TestContext.*/example.mjs:5:3\\)
Expand All @@ -18,12 +19,46 @@ module.exports = {
actual: false,
expected: true,
operator: '=='
},
code: 'ERR_TEST_FAILURE'
}
}
\t\t</failure>
\t</testcase>
\t<testcase name="should pass" time=".*" classname="test"/>
</testsuites>
`,
overrides: {
21: {
stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
<testsuites>
\t<testcase name="should fail" time=".*" classname="test" failure="The expression evaluated to a falsy value: assert\\(false\\)">
\t\t<failure type="testCodeFailure" message="The expression evaluated to a falsy value: assert\\(false\\)">
\\[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</failure>
\t</testcase>
\t<testcase name="should pass" time=".*" classname="test"/>
</testsuites>
`,
},
},
};
6 changes: 3 additions & 3 deletions packages/junit/tests/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
\t\t<testcase name="fails" time=".*" classname="test" failure="this is an error">
\t\t\t<failure type="testCodeFailure" message="this is an error">
\\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {
code: 'ERR_TEST_FAILURE',
failureType: 'testCodeFailure',
cause: Error: this is an error
.*
Expand All @@ -19,7 +20,6 @@ module.exports = {
.*
.*
.*
code: 'ERR_TEST_FAILURE'
}
\t\t\t</failure>
\t\t</testcase>
Expand All @@ -30,6 +30,7 @@ module.exports = {
assert\\(false\\)
\\] {
code: 'ERR_TEST_FAILURE',
failureType: 'testCodeFailure',
cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value:
Expand All @@ -47,8 +48,7 @@ cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy v
actual: false,
expected: true,
operator: '=='
},
code: 'ERR_TEST_FAILURE'
}
}
\t\t\t</failure>
\t\t</testcase>
Expand Down

0 comments on commit 2f9a9dd

Please sign in to comment.