This repository was archived by the owner on May 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
165 lines (131 loc) · 4.03 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import path from 'path';
import {serial as test} from 'ava';
import AvaFiles from './';
test.afterEach(() => {
// We changed the CWD in some of the tests.
process.chdir(__dirname);
});
function fixture(...args) {
args.unshift(__dirname, 'fixtr');
return path.join(...args);
}
test('requires new', t => {
const avaFiles = AvaFiles;
t.throws(function () {
avaFiles(['**/foo*']);
}, 'Class constructor AvaFiles cannot be invoked without \'new\'');
});
test('ignores relativeness in patterns', t => {
const avaFiles = new AvaFiles({files: ['./foo']});
const file = avaFiles.files[0];
t.is(file, 'foo');
});
test('testMatcher', t => {
const avaFiles = new AvaFiles({files: ['**/foo*']});
function isTest(file) {
t.true(avaFiles.isTest(file), file + ' should be a test');
}
function notTest(file) {
t.false(avaFiles.isTest(file), file + ' should not be a test');
}
isTest('foo-bar.js');
isTest('foo.js');
isTest('foo/blah.js');
isTest('bar/foo.js');
isTest('bar/foo-bar/baz/buz.js');
notTest('bar/baz/buz.js');
notTest('bar.js');
notTest('bar/bar.js');
notTest('_foo-bar.js');
notTest('foo/_foo-bar.js');
notTest('foo-bar.txt');
notTest('node_modules/foo.js');
notTest('fixtures/foo.js');
notTest('helpers/foo.js');
});
test('sourceMatcher - defaults', t => {
const avaFiles = new AvaFiles({files: ['**/foo*']});
function isSource(file) {
t.true(avaFiles.isSource(file), file + ' should be a source');
}
function notSource(file) {
t.false(avaFiles.isSource(file), file + ' should not be a source');
}
isSource('foo-bar.js');
isSource('foo.js');
isSource('foo/blah.js');
isSource('bar/foo.js');
isSource('_foo-bar.js');
isSource('foo/_foo-bar.js');
isSource('fixtures/foo.js');
isSource('helpers/foo.js');
// TODO: Watcher should probably track any required file that matches the source pattern and has a require extension installed for the given extension.
notSource('foo-bar.json');
notSource('foo-bar.coffee');
// These seem OK
isSource('bar.js');
isSource('bar/bar.js');
notSource('node_modules/foo.js');
});
test('sourceMatcher - allow matching specific node_modules directories', t => {
const avaFiles = new AvaFiles({
files: ['**/foo*'],
sources: ['node_modules/foo/**']
});
t.true(avaFiles.isSource('node_modules/foo/foo.js'));
t.false(avaFiles.isSource('node_modules/bar/foo.js'));
});
test('sourceMatcher - providing negation patterns', t => {
const avaFiles = new AvaFiles({
files: ['**/foo*'],
sources: ['!**/bar*']
});
t.false(avaFiles.isSource('node_modules/foo/foo.js'));
t.false(avaFiles.isSource('bar.js'));
t.false(avaFiles.isSource('foo/bar.js'));
});
test('findFiles - does not return duplicates of the same file', async t => {
const avaFiles = new AvaFiles({files: ['**/no-duplicates/**']});
const files = await avaFiles.findTestFiles();
t.is(files.length, 2);
});
test('findFiles - honors cwd option', async t => {
const avaFiles = new AvaFiles({
files: ['**/test/*.js'],
cwd: fixture('cwd', 'dir-b')
});
const files = await avaFiles.findTestFiles();
t.is(files.length, 1);
t.is(path.basename(files[0]), 'baz.js');
});
test('findFiles - finds the correct files by default', async t => {
const fixtureDir = fixture('default-patterns');
process.chdir(fixtureDir);
const expected = [
'sub/directory/__tests__/foo.js',
'sub/directory/bar.test.js',
'test-foo.js',
'test.js',
'test/baz.js',
'test/deep/deep.js'
].map(function (file) {
return path.join(fixtureDir, file);
}).sort();
const avaFiles = new AvaFiles();
const files = await avaFiles.findTestFiles();
files.sort();
t.deepEqual(files, expected);
});
test('findTestHelpers - finds the test helpers', async t => {
const fixtureDir = fixture('default-patterns');
process.chdir(fixtureDir);
const expected = [
'sub/directory/__tests__/helpers/foo.js',
'sub/directory/__tests__/_foo.js',
'test/helpers/test.js',
'test/_foo-help.js'
].sort().map(file => path.join(fixtureDir, file));
const avaFiles = new AvaFiles();
const files = await avaFiles.findTestHelpers();
t.deepEqual(files.sort(), expected);
});