This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
67 lines (58 loc) · 1.46 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
66
67
import fs from 'fs';
import test from 'ava';
import vinylFile from 'vinyl-file';
import pEvent from 'p-event';
import Vinyl from 'vinyl';
import xo from '.';
test('main', async t => {
const stream = xo();
stream.on('data', file => {
t.truthy(file.eslint);
t.truthy(file.eslint.messages.length);
t.pass();
});
const finish = pEvent(stream, 'finish');
stream.write(vinylFile.readSync('_fixture.js'));
stream.write(vinylFile.readSync('_fixture.js'));
stream.end();
await finish;
});
test('default formatter', async t => {
const stream = xo();
stream.pipe(xo.format(null, report => {
t.truthy(/[×✖]/.test(report));
t.pass();
}));
const finish = pEvent(stream, 'finish');
stream.end(vinylFile.readSync('_fixture.js'));
await finish;
});
test('fix option', async t => {
fs.writeFileSync('.eslintignore', '_ignored.js');
const stream = xo({
fix: true
});
stream.on('data', file => {
t.is(file.contents.toString(), 'alert();\n');
t.pass();
});
const finish = pEvent(stream, 'finish');
stream.end(new Vinyl({
path: __filename,
contents: Buffer.from('alert()')
}));
await finish;
fs.unlinkSync('.eslintignore');
});
test.serial.failing('ignored files', async t => {
fs.writeFileSync('.eslintignore', '_fixture.js');
const stream = xo();
stream.on('data', file => {
t.falsy(file.eslint);
t.pass();
});
const finish = pEvent(stream, 'finish');
stream.end(vinylFile.readSync('_fixture.js'));
await finish;
fs.unlinkSync('.eslintignore');
});