UNPKG

2.51 kBJavaScriptView Raw
1/// Module index
2//
3// Just add sugar!
4//
5//
6// Copyright (c) 2013 Quildreen Motta
7//
8// Permission is hereby granted, free of charge, to any person
9// obtaining a copy of this software and associated documentation files
10// (the "Software"), to deal in the Software without restriction,
11// including without limitation the rights to use, copy, modify, merge,
12// publish, distribute, sublicense, and/or sell copies of the Software,
13// and to permit persons to whom the Software is furnished to do so,
14// subject to the following conditions:
15//
16// The above copyright notice and this permission notice shall be
17// included in all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26//
27
28//// -- Dependencies ---------------------------------------------------
29var extend = require('boo').extend
30var run = require('./runner').run
31var Test = require('./test').Test
32var Suite = require('./suite').Suite
33
34//// -- Core implementation --------------------------------------------
35
36// It :: String, (() -> Promise a) -> Test a
37// Spec :: String, (It, Spec) -> Suite
38
39// :: Suite -> It
40function it(suite) { return function(title, fun) {
41 return Test.make(suite, title, fun)
42}}
43
44// :: Suite -> Spec
45function describe(parent) { return function(title, fun) {
46 var suite = Suite.make(parent, title)
47 var ctx = { it: it(suite)
48 , describe: describe(suite)
49 , beforeEach: suite.beforeEach
50 , beforeAll: suite.beforeAll
51 , afterEach: suite.afterEach
52 , afterAll: suite.afterAll }
53
54
55 if (fun) fun.call(ctx, ctx.it, ctx.describe)
56
57 return suite
58}}
59
60// :: String -> Spec
61function catchAll(title) {
62 var suite = Suite.make(null, title)
63
64 var f = describe(suite)
65 f.run = function(reporter){ return run(suite.tests, reporter) }
66
67 return f
68}
69
70//// -- Exports --------------------------------------------------------
71module.exports = extend( catchAll
72 , { Test: Test
73 , Suite: Suite
74 , run: run })
\No newline at end of file