-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
65 lines (51 loc) · 1.37 KB
/
test.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
'use strict';
/* eslint-env mocha */
const assert = require('assert');
const {spawn} = require('child_process');
const path = require('path');
const {expect} = require('chai');
const stripColor = require('strip-ansi');
const bin = require.resolve('pug-lint/bin/pug-lint');
function run(args, cb) {
const command = [bin].concat(args);
let stdout = '';
let stderr = '';
const node = process.execPath;
const child = spawn(node, command);
child.stderr.on('data', data => {
stderr += data;
});
child.stdout.on('data', data => {
stdout += data;
});
child.on('error', () => {
cb();
});
child.on('close', code => {
cb(null, code, stdout, stderr);
});
return child;
}
describe('with linting errors', () => {
let output;
before(done => {
const args = ['-r', './', path.resolve('./fixture.pug')];
run(args, (err, code, stdout) => {
assert(!err, err);
output = stripColor(stdout);
done();
});
});
it('should contain errors', () => {
return expect(output).to.not.be.empty;
});
it('should display filename', () => {
return expect(output).to.contain('fixture.pug');
});
it('should not display current directory path', () => {
return expect(output).to.not.contain(process.cwd());
});
it('should display lint error', () => {
return expect(output).to.contain('Unexpected character \'#');
});
});