Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): update tests #106

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
8 changes: 6 additions & 2 deletions 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 @@ -24,7 +25,7 @@ describe('github reporter', () => {
});

assert.strictEqual(child.stderr?.toString(), '');
compareLines(child.stdout?.toString(), output.stdout);
compareLines(child.stdout?.toString(), output.overrides[nodeMajor]?.stdout ?? output.stdout);
compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), output.summary);
});

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

assert.strictEqual(child.stderr?.toString(), '');
compareLines(child.stdout?.toString(), outputESM.stdout);
compareLines(
child.stdout?.toString(),
outputESM.overrides[nodeMajor]?.stdout ?? outputESM.stdout,
);
compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), outputESM.summary);
});

Expand Down
24 changes: 23 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,26 @@ 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: {
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::
`,
},
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::
`,
},
},
};
30 changes: 28 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 All @@ -26,4 +26,30 @@ module.exports = {
summary: `<h1>Test Results</h1>
<table><tr><td>Total Tests</td><td>7</td></tr><tr><td>Suites 📂</td><td>2</td></tr><tr><td>Passed ✅</td><td>3</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>
`,
overrides: {
18: {
stdout: `::debug::starting to run tests
::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}
::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).*
::debug::starting to run more tests
::debug::starting to run is ok
::debug::completed running is ok
::debug::completed running more tests
::debug::starting to run is skipped
::debug::completed running is skipped
::debug::starting to run is a todo
::debug::completed running is a todo
::group::Test results \\(3 passed, 2 failed\\)
::notice::Total Tests: 7%0ASuites 📂: 2%0APassed ✅: 3%0AFailed ❌: 2%0ACanceled 🚫: 0%0ASkipped ⏭️: 1%0ATodo 📝: 1%0ADuration 🕐: .*ms
::endgroup::
`,
},
},
};
9 changes: 7 additions & 2 deletions packages/junit/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ 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(), '');
compareLines(child.stdout?.toString(), output.stdout);
compareLines(child.stdout?.toString(), output.overrides[nodeMajor]?.stdout ?? output.stdout);
});

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(
child.stdout?.toString(),
outputESM.overrides[nodeMajor]?.stdout ?? outputESM.stdout,
);
});

test('empty', async () => {
Expand Down
62 changes: 62 additions & 0 deletions packages/junit/tests/output-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,66 @@ module.exports = {
<testsuites>
\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\\)
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>
`,
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>
`,
},
18: {
stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
<testsuites>
\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\\] {
failureType: 'testCodeFailure',
cause: AssertionError \\[ERR_ASSERTION\\]: false == true
Expand All @@ -26,4 +86,6 @@ module.exports = {
\t<testcase name="should pass" time=".*" classname="test"/>
</testsuites>
`,
},
},
};
67 changes: 67 additions & 0 deletions packages/junit/tests/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,71 @@ module.exports = {
\t\t<testcase name="is ok" time=".*" classname="test"/>
\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
.*
.*
.*
.*
.*
.*
.*
.*
.*
}
\t\t\t</failure>
\t\t</testcase>
\t\t<testcase name="is a diagnostic" time=".*" classname="test"/>
\t\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 TestContext.* \\(.*/example.js:12:31\\)
at .*
at .*
at .*
at .*
at .*
at .* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
}
\t\t\t</failure>
\t\t</testcase>
\t</testsuite>
\t<testsuite name="more tests" time=".*" disabled="0" errors="0" tests="1" failures="0" skipped="0" hostname=".*">
\t\t<testcase name="is ok" time=".*" classname="test"/>
\t</testsuite>
\t<testcase name="is skipped" time=".* classname="test">
\t\t<skipped type="skipped" message="true"/>
\t</testcase>
\t<testcase name="is a todo" time=".*" classname="test">
\t\t<skipped type="todo" message="true"/>
\t</testcase>
</testsuites>
`,
overrides: {
18: {
stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
<testsuites>
\t<testsuite name="tests" time=".*" disabled="0" errors="0" tests="4" failures="2" skipped="0" hostname=".*">
\t\t<testcase name="is ok" time=".*" classname="test"/>
\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\\] {
failureType: 'testCodeFailure',
cause: Error: this is an error
Expand Down Expand Up @@ -64,4 +129,6 @@ code: 'ERR_TEST_FAILURE'
\t</testcase>
</testsuites>
`,
},
},
};
10 changes: 4 additions & 6 deletions packages/testwatch/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { once } = require('node:events');
const assert = require('node:assert');
const path = require('node:path');
const chalk = require('chalk');
const { isSupported, major, minor } = require('../nodeVersion');
const { isSupported } = require('../nodeVersion');

const clear = '\x1Bc';
const esc = '\x1b';
Expand Down Expand Up @@ -38,8 +38,6 @@ Filter Test
const filterFilesPrompt = filterTestsPrompt.replace('test', 'file').replace('Test', 'File');
const debugOutput = process.env.DEBUG || process.argv.includes('--debug');

const skipText = major >= 20 && minor >= 7 ? '# test name does not match pattern' : '# SKIP';

function debug(str) {
if (debugOutput) {
const delimiter = chalk.bgWhite('--CLEAR--');
Expand Down Expand Up @@ -176,8 +174,8 @@ describe('testwatch', { concurrency: true, skip: !isSupported ? 'unsupported nod
'',
'',
`${tests
.replace('✔ j - sum (*ms)', `﹣ j - sum (*ms) ${skipText}`)
.replace('✔ index - sum (*ms)', `﹣ index - sum (*ms) ${skipText}`)
.replace('✔ j - sum (*ms)', '﹣ j - sum (*ms) # test name does not match pattern')
.replace('✔ index - sum (*ms)', '﹣ index - sum (*ms) # test name does not match pattern')
}\n${compactMenu}\n${clearLines}${activeFilters}${mainMenuWithFilters}\n`,
]);
});
Expand Down Expand Up @@ -240,7 +238,7 @@ describe('testwatch', { concurrency: true, skip: !isSupported ? 'unsupported nod
const activeFilters = '\nActive Filters: file name **/index*.*, test name /sum/\n';
assert.strictEqual(stderr, '');
assert.strictEqual(outputs.length, 11);
assert.strictEqual(outputs[10], `${testsRun[1].replace('✔ index - subtraction (*ms)', `﹣ index - subtraction (*ms) ${skipText}`)}\n${compactMenu}\n${clearLines}${activeFilters}${mainMenuWithFilters}\n`);
assert.strictEqual(outputs[10], `${testsRun[1].replace('✔ index - subtraction (*ms)', '﹣ index - subtraction (*ms) # test name does not match pattern')}\n${compactMenu}\n${clearLines}${activeFilters}${mainMenuWithFilters}\n`);
});

it('should mention when no files found', async () => {
Expand Down
Loading