~ps-jenkins/ubuntu-push/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to docs/example-server/node_modules/mocha/lib/interfaces/qunit.js

  • Committer: Roberto Alsina
  • Date: 2014-09-05 14:57:17 UTC
  • mto: (91.179.25 automatic)
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: roberto.alsina@canonical.com-20140905145717-0ufcsv27w25i1nnu
added example app server

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/**
 
3
 * Module dependencies.
 
4
 */
 
5
 
 
6
var Suite = require('../suite')
 
7
  , Test = require('../test')
 
8
  , utils = require('../utils');
 
9
 
 
10
/**
 
11
 * QUnit-style interface:
 
12
 *
 
13
 *     suite('Array');
 
14
 *
 
15
 *     test('#length', function(){
 
16
 *       var arr = [1,2,3];
 
17
 *       ok(arr.length == 3);
 
18
 *     });
 
19
 *
 
20
 *     test('#indexOf()', function(){
 
21
 *       var arr = [1,2,3];
 
22
 *       ok(arr.indexOf(1) == 0);
 
23
 *       ok(arr.indexOf(2) == 1);
 
24
 *       ok(arr.indexOf(3) == 2);
 
25
 *     });
 
26
 *
 
27
 *     suite('String');
 
28
 *
 
29
 *     test('#length', function(){
 
30
 *       ok('foo'.length == 3);
 
31
 *     });
 
32
 *
 
33
 */
 
34
 
 
35
module.exports = function(suite){
 
36
  var suites = [suite];
 
37
 
 
38
  suite.on('pre-require', function(context, file, mocha){
 
39
 
 
40
    /**
 
41
     * Execute before running tests.
 
42
     */
 
43
 
 
44
    context.before = function(name, fn){
 
45
      suites[0].beforeAll(name, fn);
 
46
    };
 
47
 
 
48
    /**
 
49
     * Execute after running tests.
 
50
     */
 
51
 
 
52
    context.after = function(name, fn){
 
53
      suites[0].afterAll(name, fn);
 
54
    };
 
55
 
 
56
    /**
 
57
     * Execute before each test case.
 
58
     */
 
59
 
 
60
    context.beforeEach = function(name, fn){
 
61
      suites[0].beforeEach(name, fn);
 
62
    };
 
63
 
 
64
    /**
 
65
     * Execute after each test case.
 
66
     */
 
67
 
 
68
    context.afterEach = function(name, fn){
 
69
      suites[0].afterEach(name, fn);
 
70
    };
 
71
 
 
72
    /**
 
73
     * Describe a "suite" with the given `title`.
 
74
     */
 
75
 
 
76
    context.suite = function(title){
 
77
      if (suites.length > 1) suites.shift();
 
78
      var suite = Suite.create(suites[0], title);
 
79
      suite.file = file;
 
80
      suites.unshift(suite);
 
81
      return suite;
 
82
    };
 
83
 
 
84
    /**
 
85
     * Exclusive test-case.
 
86
     */
 
87
 
 
88
    context.suite.only = function(title, fn){
 
89
      var suite = context.suite(title, fn);
 
90
      mocha.grep(suite.fullTitle());
 
91
    };
 
92
 
 
93
    /**
 
94
     * Describe a specification or test-case
 
95
     * with the given `title` and callback `fn`
 
96
     * acting as a thunk.
 
97
     */
 
98
 
 
99
    context.test = function(title, fn){
 
100
      var test = new Test(title, fn);
 
101
      test.file = file;
 
102
      suites[0].addTest(test);
 
103
      return test;
 
104
    };
 
105
 
 
106
    /**
 
107
     * Exclusive test-case.
 
108
     */
 
109
 
 
110
    context.test.only = function(title, fn){
 
111
      var test = context.test(title, fn);
 
112
      var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$';
 
113
      mocha.grep(new RegExp(reString));
 
114
    };
 
115
 
 
116
    /**
 
117
     * Pending test case.
 
118
     */
 
119
 
 
120
    context.test.skip = function(title){
 
121
      context.test(title);
 
122
    };
 
123
  });
 
124
};