This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.js
74 lines (59 loc) · 1.73 KB
/
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
'use strict';
var Ajv = require('ajv');
var ajvIstanbul = require('.');
var assert = require('assert');
var istanbul = require('istanbul');
describe('ajv-istanbul', () => {
var ajv;
beforeEach(() => {
ajv = new Ajv;
delete global.__coverage__;
});
it('should allow chaining with other plugins', () => {
assert.equal(ajvIstanbul(ajv), ajv);
});
it('should extend ajv instance to add instrumentation of generation code', () => {
ajvIstanbul(ajv);
var validate = ajv.compile({
type: 'integer',
minimum: 1,
maximum: 9
});
validate(0);
assert.equal(typeof global.__coverage__, 'object');
});
it('should allow generating coverage reports', (done) => {
ajvIstanbul(ajv);
var validate = ajv.compile({
id: 'test_integer_schema.json',
type: 'integer',
minimum: 1,
maximum: 9
});
assert.strictEqual( validate(0), false );
assert.strictEqual( validate(5), true );
assert.strictEqual( validate(10), false );
assert.strictEqual( validate(1.1), false );
assert.strictEqual( validate('a'), false );
assert.strictEqual( validate(NaN), false );
var collector = new istanbul.Collector();
var reporter = new istanbul.Reporter();
var sync = true;
collector.add(global.__coverage__);
reporter.add('text');
reporter.addAll([ 'lcov', 'html' ]);
var oldLog = console.log;
console.log = log;
var logged;
reporter.write(collector, sync, function () {
console.log = oldLog;
console.log('reports generated');
console.log(logged);
assert.equal(logged.match(/[^0-9]100[^0-9]/g).length, 9, '100% in 9 places');
done();
});
function log(str) {
logged = str;
}
});
});