Skip to content

Commit

Permalink
[ospec] Allow more than one o.only() test
Browse files Browse the repository at this point in the history
  • Loading branch information
pygy committed Jun 1, 2018
1 parent a23216b commit 14695c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ospec/ospec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if (typeof module !== "undefined") module["exports"] = m()
else window.o = m()
})(function init(name) {
var spec = {}, subjects = [], results, only = null, ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty
var spec = {}, subjects = [], results, only = [], ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty
var ospecFileName = getStackName(ensureStackTrace(new Error), /[\/\\](.*?):\d+:\d+/), timeoutStackName
var globalTimeout = noTimeoutRightNow
var currentTestError = null
Expand Down Expand Up @@ -43,7 +43,8 @@ else window.o = m()
highlight("/!\\ WARNING /!\\ o.only() mode") + "\n" + o.cleanStackTrace(ensureStackTrace(new Error)) + "\n",
cStyle("red"), ""
)
o(subject, only = predicate)
only.push(predicate)
o(subject, predicate)
}
o.spy = function(fn) {
var spy = function() {
Expand Down Expand Up @@ -101,7 +102,7 @@ else window.o = m()
pre = [].concat(pre, spec["\x01beforeEach"] || [])
post = [].concat(spec["\x01afterEach"] || [], post)
series([].concat(spec["\x01before"] || [], Object.keys(spec).reduce(function(tasks, key) {
if (key.charCodeAt(0) !== 1 && (only === null || spec[key].fn === only || !(spec[key] instanceof Task))) {
if (key.charCodeAt(0) !== 1 && (only.length === 0 || only.indexOf(spec[key].fn) !== -1 || !(spec[key] instanceof Task))) {
tasks.push(new Task(function(done) {
o.timeout(Infinity)
subjects.push(key)
Expand Down
7 changes: 6 additions & 1 deletion ospec/tests/test-ospec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ o("o.only", function(done) {
oo.only(".only()", function() {
oo(2).equals(2)
}, true)
oo.only("another .only()", function(done) {
done("that fails")
}, true)
})

oo.run(function(results){
o(results.length).equals(1)
o(results.length).equals(2)
o(results[0].pass).equals(true)
o(results[1].pass).equals(false)

done()
})
})
Expand Down

0 comments on commit 14695c9

Please sign in to comment.