[ospec] Improve the done() call checker
This commit is contained in:
parent
33180370ea
commit
8ebf036b8c
3 changed files with 86 additions and 2 deletions
|
|
@ -6,6 +6,8 @@ _2018-xx-yy_
|
|||
<!-- Add new lines here. Version number will be decided later -->
|
||||
### Breaking
|
||||
- Better input checking to prevent misuses of the library. This may uncover bugs in your test suites. Since it is potentially a disruptive update this change triggers a semver major bump. ([#2167(https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
- Change the reserved character for hooks and test suite meta-information from `"__"` to `"\x01"`. Tests whose name start with `"\0x01"` will be rejected ([#2167(https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
- Misues of the library will now throw errors, rather than report failures. ([#2167(https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
|
||||
### Features
|
||||
- Give async timeout a stack trace that points to the problematic test ([#2154](https://github.com/MithrilJS/mithril.js/pull/2154) [@gilbert](github.com/gilbert), [#2167](https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
|
|
@ -16,6 +18,8 @@ _2018-xx-yy_
|
|||
- Detect duplicate calls to `done()` properly [#2162](https://github.com/MithrilJS/mithril.js/issues/2162) ([#2167](https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
- Don't count `done()` calls as passing tests in the final tally [#2166](https://github.com/MithrilJS/mithril.js/issues/2166) ([#2167](https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
- Don't try to report internal errors as assertion failures, throw them instead ([#2167](https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
- Don't ignore, silently, tests whose name start with the test suite meta-information sequence (was `"__"` up to this version) ([#2167(https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
- Fix the `done()` call detection logic [#2158](https://github.com/MithrilJS/mithril.js/issues/2158) and assorted fixes (accept non-English names, tolerate comments; [#2167](https://github.com/MithrilJS/mithril.js/pull/2167))
|
||||
|
||||
## 2.1.0
|
||||
_2018-05-25_
|
||||
|
|
|
|||
|
|
@ -166,8 +166,12 @@ else window.o = m()
|
|||
}
|
||||
if (fn.length > 0) {
|
||||
var body = fn.toString()
|
||||
arg = (body.match(/\(([\w$]+)/) || body.match(/([\w$]+)\s*=>/) || []).pop()
|
||||
if (body.indexOf(arg) === body.lastIndexOf(arg)) throw new Error("`" + arg + "()` should be called at least once")
|
||||
arg = (body.match(/^(.+?)(?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*=>/) || body.match(/\((?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*(.+?)(?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*[,\)]/) || []).pop()
|
||||
if (body.indexOf(arg) === body.lastIndexOf(arg)) {
|
||||
var e = new Error
|
||||
e.stack = "`" + arg + "()` should be called at least once\n" + o.cleanStackTrace(task.err)
|
||||
throw e
|
||||
}
|
||||
try {
|
||||
fn(done, setDelay)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -612,3 +612,79 @@ o.spec("ospec", function() {
|
|||
})
|
||||
})
|
||||
})
|
||||
o.spec("the done parser", function() {
|
||||
o("accepts non-English names", function() {
|
||||
var oo = o.new()
|
||||
var threw = false
|
||||
oo("test", function(完了) {
|
||||
oo(true).equals(true)
|
||||
完了()
|
||||
})
|
||||
try {oo.run(function(){})} catch(e) {threw = true}
|
||||
o(threw).equals(false)
|
||||
})
|
||||
o("tolerates comments", function() {
|
||||
var oo = o.new()
|
||||
var threw = false
|
||||
oo("test", function(/*hey
|
||||
*/ /**/ //ho
|
||||
done /*hey
|
||||
*/ /**/ //huuu
|
||||
, timeout
|
||||
) {
|
||||
timeout(5)
|
||||
oo(true).equals(true)
|
||||
done()
|
||||
})
|
||||
try {oo.run(function(){})} catch(e) {threw = true}
|
||||
o(threw).equals(false)
|
||||
})
|
||||
/*eslint-disable no-eval*/
|
||||
try {eval("(()=>{})()"); o.spec("with ES6 arrow functions", function() {
|
||||
function getCommentContent(f) {
|
||||
f = f.toString()
|
||||
return f.slice(f.indexOf("/*") + 2, f.lastIndexOf("*/"))
|
||||
}
|
||||
o("has no false positives 1", function(){
|
||||
var oo = o.new()
|
||||
var threw = false
|
||||
eval(getCommentContent(function(){/*
|
||||
oo(
|
||||
'Async test parser mistakenly identified 1st token after a parens to be `done` reference',
|
||||
done => {
|
||||
oo(threw).equals(false)
|
||||
done()
|
||||
}
|
||||
)
|
||||
*/}))
|
||||
try {oo.run(function(){})} catch(e) {threw = true}
|
||||
o(threw).equals(false)
|
||||
})
|
||||
o("has no false negatives", function(){
|
||||
var oo = o.new()
|
||||
var threw = false
|
||||
eval(getCommentContent(function(){/*
|
||||
oo(
|
||||
"Multiple references to the wrong thing doesn't fool the checker",
|
||||
done => {
|
||||
oo(threw).equals(false)
|
||||
oo(threw).equals(false)
|
||||
}
|
||||
)
|
||||
*/}))
|
||||
try {oo.run(function(){})} catch(e) {threw = true}
|
||||
o(threw).equals(true)
|
||||
})
|
||||
o("isn't fooled by comments", function(){
|
||||
var oo = o.new()
|
||||
var threw = false
|
||||
oo(
|
||||
"comments won't throw the parser off",
|
||||
eval("done /*hey*/ /**/ => {oo(threw).equals(false);done()}")
|
||||
)
|
||||
try {oo.run(function(){})} catch(e) {threw = true}
|
||||
o(threw).equals(false)
|
||||
})
|
||||
})} catch (e) {/*ES5 env, or no eval, ignore*/}
|
||||
/*eslint-enable no-eval*/
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue