-
-
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
10 changed files
with
57 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,26 +1,45 @@ | ||
|
||
import equals from '../../fn/modules/equals.js'; | ||
|
||
let promise = Promise.resolve(0); | ||
let n = 0; | ||
|
||
function runTest(name, fn, value, values, resolve, reject) { | ||
function runTest(name, fn, expected, value, values, pass, fail) { | ||
try { | ||
fn(resolve, value, ...values); | ||
fn((value) => ( | ||
// If value is an Error object | ||
value instanceof Error ? | ||
fail(value) : | ||
// If value is expected | ||
expected === undefined || equals(value, expected) ? | ||
pass(value) : | ||
// Otherwise | ||
fail(new Error('done() value does not equal expected value')) | ||
), value, ...values); | ||
} | ||
catch(e) { | ||
reject(e); | ||
fail(e); | ||
} | ||
} | ||
|
||
export default function scheduleTest(time, name, fn, ...values) { | ||
export default function scheduleTest(time, name, fn, expected, ...values) { | ||
return promise = promise | ||
.then((value) => new Promise((resolve, reject) => | ||
setTimeout(runTest, time * 1000, name, fn, value, values, (value) => { | ||
// Log pass | ||
.then((value) => new Promise((resolve, reject) => { | ||
const pass = (value) => { | ||
console.log('%c✓ Test ' + (++n) + ' %c' + name, 'color: #B6BD00; font-weight: 400;', 'color: #779AAB; font-weight: 400;'); | ||
resolve(value); | ||
}, (e) => { | ||
// Log fail | ||
console.log('%c✗ Test ' + (++n) + ' %c' + name, 'color: #ba4029; font-weight: 400;', 'color: #779AAB; font-weight: 400;', e.message); | ||
}; | ||
|
||
const fail = (e) => { | ||
console.log('%c✗ Test ' + (++n) + ' %c' + name, 'color: #f02f2f; font-weight: 600;', 'color: #779AAB; font-weight: 400;', e.message); | ||
reject(); | ||
}) | ||
)); | ||
}; | ||
|
||
return time === 'frame' ? | ||
requestAnimationFrame(() => runTest(name, fn, expected, value, values, pass, fail)) : | ||
time === 'tick' ? | ||
Promise.resolve().then(() => runTest(name, fn, expected, value, values, pass, fail)) : | ||
// Assume time is a number in seconds | ||
setTimeout(runTest, time * 1000, name, fn, expected, value, values, pass, fail) ; | ||
})); | ||
} |
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