Welcome to mirror list, hosted at ThFree Co, Russian Federation.

hook-err.spec.js « integration « test « mocha-3.1.2 « lib « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fbdd7e8e383ec14abcc4ffcdd9f34a1da60da22a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
'use strict';

var assert = require('assert');
var runMocha = require('./helpers').runMocha;
var splitRegExp = require('./helpers').splitRegExp;
var bang = require('../../lib/reporters/base').symbols.bang;

describe('hook error handling', function () {
  var lines;

  describe('before hook error', function () {
    before(run('hooks/before-hook-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['before', bang + 'test 3']
      );
    });
  });

  describe('before hook error tip', function () {
    before(run('hooks/before-hook-error-tip.fixture.js', onlyErrorTitle));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['1) spec 2 "before all" hook:']
      );
    });
  });

  describe('before each hook error', function () {
    before(run('hooks/beforeEach-hook-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['before', bang + 'test 3']
      );
    });
  });

  describe('after hook error', function () {
    before(run('hooks/after-hook-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['test 1', 'test 2', 'after', bang + 'test 3']
      );
    });
  });

  describe('after each hook error', function () {
    before(run('hooks/afterEach-hook-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['test 1', 'after', bang + 'test 3']
      );
    });
  });

  describe('multiple hook errors', function () {
    before(run('hooks/multiple-hook-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        [
          'root before',
          '1-1 before',
          'root before each',
          '1 before each',
          '1-1 before each',
          bang + '1-1 after each',
          '1 after each',
          'root after each',
          '1-1 after',
          bang + '1-2 before',
          'root before each',
          '1 before each',
          '1-2 before each',
          '1-2 test 1',
          '1-2 after each',
          bang + '1 after each',
          'root after each',
          '1-2 after',
          '1 after',
          '2-1 before',
          'root before each',
          '2 before each',
          bang + '2 after each',
          bang + 'root after each',
          '2-1 after',
          '2 after',
          'root after'
        ]
      );
    });
  });

  describe('async - before hook error', function () {
    before(run('hooks/before-hook-async-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['before', bang + 'test 3']
      );
    });
  });

  describe('async - before hook error tip', function () {
    before(run('hooks/before-hook-async-error-tip.fixture.js', onlyErrorTitle));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['1) spec 2 "before all" hook:']
      );
    });
  });

  describe('async - before each hook error', function () {
    before(run('hooks/beforeEach-hook-async-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['before', bang + 'test 3']
      );
    });
  });

  describe('async - after hook error', function () {
    before(run('hooks/after-hook-async-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['test 1', 'test 2', 'after', bang + 'test 3']
      );
    });
  });

  describe('async - after each hook error', function () {
    before(run('hooks/afterEach-hook-async-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        ['test 1', 'after', bang + 'test 3']
      );
    });
  });

  describe('async - multiple hook errors', function () {
    before(run('hooks/multiple-hook-async-error.fixture.js'));
    it('should verify results', function () {
      assert.deepEqual(
        lines,
        [
          'root before',
          '1-1 before',
          'root before each',
          '1 before each',
          '1-1 before each',
          bang + '1-1 after each',
          '1 after each',
          'root after each',
          '1-1 after',
          bang + '1-2 before',
          'root before each',
          '1 before each',
          '1-2 before each',
          '1-2 test 1',
          '1-2 after each',
          bang + '1 after each',
          'root after each',
          '1-2 after',
          '1 after',
          '2-1 before',
          'root before each',
          '2 before each',
          bang + '2 after each',
          bang + 'root after each',
          '2-1 after',
          '2 after',
          'root after'
        ]
      );
    });
  });

  function run (fnPath, outputFilter) {
    return function (done) {
      runMocha(fnPath, [], function (err, res) {
        assert.ifError(err);

        lines = res.output
          .split(splitRegExp)
          .map(function (line) {
            return line.trim();
          })
          .filter(outputFilter || onlyConsoleOutput());

        done();
      });
    };
  }
});

function onlyConsoleOutput () {
  var foundSummary = false;
  return function (line) {
    if (!foundSummary) {
      foundSummary = !!(/\(\d+ms\)/).exec(line);
    }
    return !foundSummary && line.length > 0;
  };
}

function onlyErrorTitle (line) {
  return !!(/^1\)/).exec(line);
}