-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import chalk from 'chalk'; | ||
import QUnit from '../../index.js'; | ||
import yaml from 'js-yaml' | ||
import indentString from 'indent-string'; | ||
import TAPDisplayFinalResult from '../tap/display-final-result.js'; | ||
import TAPDisplayTestResult from '../tap/display-test-result.js'; | ||
|
||
let COUNTER = { testCount: 0, failCount: 0, skipCount: 0, passCount: 0 }; | ||
|
||
global.window = global; | ||
window.QUnit = QUnit; | ||
window.QUNIX_TEST_TIME_COUNTER = (function() { // NOTE: might be needed for failFast option timeTaken calculation | ||
const startTime = new Date(); | ||
|
||
return { | ||
start: startTime, | ||
stop: () => +(new Date()) - (+startTime) | ||
}; | ||
})(); | ||
|
||
|
||
window.QUnit.on('testEnd', (details) => TAPDisplayTestResult(COUNTER, details)); | ||
window.QUnit.done((details) => { | ||
window.QUNIT_RESULT = Object.assign(details, { | ||
timeTaken: window.QUNIX_TEST_TIME_COUNTER.stop() | ||
}); | ||
TAPDisplayFinalResult(COUNTER, details.timeTaken); | ||
}); | ||
|
||
export default window.QUnit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default function({ testCount, passCount, skipCount, failCount }, timeTaken) { | ||
console.log(''); | ||
console.log(`1..${testCount}`); | ||
console.log(`# tests ${testCount}`); | ||
console.log(`# pass ${passCount}`); | ||
console.log(`# skip ${skipCount}`); | ||
console.log(`# fail ${failCount}`); | ||
|
||
// let seconds = timeTaken > 1000 ? Math.floor(timeTaken / 1000) : 0; | ||
// let milliseconds = timeTaken % 100; | ||
|
||
console.log(`# duration ${timeTaken}`); | ||
console.log(''); | ||
} | ||
// console.log(details.timeTaken); // runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import yaml from 'js-yaml' | ||
import indentString from 'indent-string'; | ||
|
||
// tape TAP output: ['operator', 'stack', 'at', 'expected', 'actual'] | ||
// ava TAP output: ['message', 'name', 'at', 'assertion', 'values'] // Assertion #5, message | ||
export default function(COUNTER, details) { // NOTE: https://github.com/qunitjs/qunit/blob/master/src/html-reporter/diff.js | ||
COUNTER.testCount++; | ||
|
||
if (details.status === 'skipped') { | ||
COUNTER.skipCount++; | ||
console.log(`ok ${COUNTER.testCount}`, details.fullName.join(' | '), '# skip'); | ||
} else if (details.status === 'todo') { | ||
console.log(`not ok ${COUNTER.testCount}`, details.fullName.join(' | '), '# skip'); | ||
} else if (details.status === 'failed') { | ||
COUNTER.failCount++; | ||
console.log(`not ok ${COUNTER.testCount}`, details.fullName.join(' | '), `# (${details.runtime} ms)`); | ||
details.assertions.reduce((errorCount, assertion, index) => { | ||
if (!assertion.passed && assertion.todo === false) { | ||
COUNTER.errorCount++; | ||
let stack = assertion.stack?.match(/\(.+\)/g); | ||
|
||
console.log(' ---'); | ||
console.log(indentString(yaml.safeDump({ | ||
name: `Assertion #${index + 1}`, // TODO: check what happens on runtime errors | ||
actual: assertion.actual || null, | ||
expected: assertion.expected || null, | ||
message: assertion.message || null, | ||
stack: assertion.stack || null, | ||
at: stack ? stack[0].replace('(file://', '').replace(')', '') : null | ||
}).trim(), 4)); | ||
console.log(' ...'); | ||
} | ||
|
||
return errorCount; | ||
}, 0); | ||
} else if (details.status === 'passed') { | ||
COUNTER.passCount++; | ||
console.log(`ok ${COUNTER.testCount}`, details.fullName.join(' | '), `# (${details.runtime} ms)`); | ||
} | ||
} | ||
|
||
// not ok 10 test exited without ending: deepEqual true works | ||
// --- | ||
// operator: fail | ||
// at: process.<anonymous> (/home/izelnakri/ava-test/node_modules/tape/index.js:85:19) | ||
// stack: |- | ||
// Error: test exited without ending: deepEqual true works | ||
// at Test.assert [as _assert] (/home/izelnakri/ava-test/node_modules/tape/lib/test.js:269:54) | ||
// at Test.bound [as _assert] (/home/izelnakri/ava-test/node_modules/tape/lib/test.js:90:32) | ||
// at Test.fail (/home/izelnakri/ava-test/node_modules/tape/lib/test.js:363:10) | ||
// at Test.bound [as fail] (/home/izelnakri/ava-test/node_modules/tape/lib/test.js:90:32) | ||
// at Test._exit (/home/izelnakri/ava-test/node_modules/tape/lib/test.js:226:14) | ||
// at Test.bound [as _exit] (/home/izelnakri/ava-test/node_modules/tape/lib/test.js:90:32) | ||
// at process.<anonymous> (/home/izelnakri/ava-test/node_modules/tape/index.js:85:19) | ||
// at process.emit (node:events:376:20) | ||
// ... | ||
|