/
grep.spec.js
79 lines (72 loc) · 2.17 KB
/
grep.spec.js
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
'use strict';
var helpers = require('../helpers');
var runMocha = helpers.runMocha;
var runMochaJSON = helpers.runMochaJSON;
var FIXTURE = 'options/grep';
describe('--grep', function() {
it('should run specs matching a string', function(done) {
runMochaJSON(FIXTURE, ['--grep', 'match'], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have passed')
.and('to have passed test count', 2)
.and('not to have pending tests');
done();
});
});
describe('should run specs matching a RegExp', function() {
it('with RegExp-like strings (pattern followed by flag)', function(done) {
runMochaJSON(FIXTURE, ['--grep', '/match/i'], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have passed')
.and('to have passed test count', 4)
.and('not to have pending tests');
done();
});
});
it('with string as pattern', function(done) {
runMochaJSON(FIXTURE, ['--grep', '.*'], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed')
.and('to have passed test count', 4)
.and('to have failed test count', 1)
.and('not to have pending tests');
done();
});
});
});
describe('when used with --invert', function() {
it('should run specs that do not match the pattern', function(done) {
runMochaJSON(FIXTURE, ['--grep', 'fail', '--invert'], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have passed')
.and('to have passed test count', 4)
.and('not to have pending tests');
done();
});
});
});
describe('when both --fgrep and --grep used together', function() {
it('should report an error', function(done) {
runMocha(
FIXTURE,
['--fgrep', 'first', '--grep', 'second'],
function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with output', /mutually exclusive/i);
done();
},
'pipe'
);
});
});
});