-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.mjs
69 lines (57 loc) · 2.1 KB
/
test.mjs
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
import chai from 'chai';
import execa from 'execa';
import {
handleAbsolute,
normalizeOptionAliases
} from './index';
import path from 'path';
const { expect } = chai;
describe('handleAbsolute', function() {
let root = '@@ROOT_SENTINAL@@';
it('works', function() {
expect(handleAbsolute('/foo/bar/baz', root)).to.eql('/foo/bar/baz');
expect(handleAbsolute('foo/bar/baz', root)).to.eql('@@ROOT_SENTINAL@@/foo/bar/baz');
});
});
describe('normalizeOptionAliases', function() {
it('works', function() {
expect(normalizeOptionAliases({})).to.eql({});
expect(normalizeOptionAliases({})).to.not.equal({});
expect(normalizeOptionAliases({ g: 'foo'})).to.not.equal({ grep: 'foo'});
expect(normalizeOptionAliases({ i: 'foo'})).to.not.equal({ invert: 'foo'});
expect(normalizeOptionAliases({ i: 'foo', apple: [{ a:1 }]})).to.not.equal({ invert: 'foo', apple: [{ a: 1}]});
expect(normalizeOptionAliases({ _: ['a'] })).to.not.equal({ });
});
});
describe('runner', function() {
// TODO: if problems arise, lets add tests here
});
describe('acceptance', function() {
it('works', async function() {
let child = await execa('./bin/mocha-esm', ['fixtures/a', 'fixtures/b']);
expect(child.code).to.eql(0);
expect(child.stdout).to.contain('foo A');
expect(child.stdout).to.contain('works A');
expect(child.stdout).to.contain('foo B');
expect(child.stdout).to.contain('works B');
});
it('fails', async function() {
try {
await execa('./bin/mocha-esm', ['fixtures/fail']);
// should not get here
expect(true).to.eq(false);
} catch (e) {
expect(e.message).to.contain('I WILL FAIL')
}
});
it('greps', async function() {
let child = await execa('./bin/mocha-esm', ['--grep', 'works A', 'fixtures/a']);
expect(child.stdout).to.contain('works A');
expect(child.stdout).to.not.contain('works B');
});
it('greps invert', async function() {
let child = await execa('./bin/mocha-esm', ['-i', '--grep', 'works A', 'fixtures/a']);
expect(child.stdout).to.not.contain('works A');
expect(child.stdout).to.contain('works B');
});
});