UNPKG

1.22 kBJavaScriptView Raw
1
2
3
4!function(exports) {
5 var undef
6 , assert = exports.assert || require("./assert")
7 , only = []
8 , chain = []
9 , pos = 0
10
11 exports.describe = describe
12 exports.test = test
13 exports.it = function(name, next, opts) {
14 return test("it " + name, next, opts)
15 }
16
17 function describe(name, fn) {
18 chain.splice(pos, 0, ["# " + name, fn])
19 return exports
20 }
21 function test(name, fn, opts) {
22 if (typeof name === "function") {
23 fn = name
24 name = "{unnamed test}"
25 }
26 chain.splice(pos, 0, [name, fn, opts])
27 return exports
28 }
29
30 function next() {
31 var run = chain[pos++]
32 if (run === undef) {
33 console.log("done")
34 } else {
35 console.log(run[0], "run " + pos)
36 if (typeof run[1] === "function") {
37 run[1].call(exports, new Case, new Mock)
38 }
39 next()
40
41 }
42 }
43
44 function Mock(name) {
45 }
46 function Case(name) {
47 }
48 Case.prototype = assert
49
50 assert.end = function() {
51 if (this.ended) {
52 throw Error("'" + this.name + "' ended multiple times")
53 }
54 this.ended = 1
55 }
56
57 setTimeout(next, 1)
58
59
60
61}(this)
62
63var describe = this.describe
64
65describe("Suite 1", function(test, it) {
66 this.it ("should pass 1-1")
67
68})
69
70describe("Suite 2")
71.it ("should run 2-1", function(assert) {
72 assert.ok(true)
73 assert.end()
74})
75
76
77