/
glob-assets.test.js
138 lines (107 loc) · 4.16 KB
/
glob-assets.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
import path from 'path';
import test from 'ava';
import {copy, ensureDir} from 'fs-extra';
import tempy from 'tempy';
import globAssets from '../lib/glob-assets';
const fixtures = 'test/fixtures/files';
test('Retrieve file from single path', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, ['upload.txt']);
t.deepEqual(globbedAssets, ['upload.txt']);
});
test('Retrieve multiple files from path', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, ['upload.txt', 'upload_other.txt']);
t.deepEqual(globbedAssets.sort(), ['upload_other.txt', 'upload.txt'].sort());
});
test('Retrieve multiple files from Object', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [
{path: 'upload.txt', name: 'upload_name', label: 'Upload label'},
'upload_other.txt',
]);
t.deepEqual(globbedAssets.sort(), ['upload.txt', 'upload_other.txt'].sort());
});
test('Retrieve multiple files without duplicates', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [
'upload_other.txt',
'upload.txt',
'upload_other.txt',
'upload.txt',
'upload.txt',
'upload_other.txt',
]);
t.deepEqual(globbedAssets.sort(), ['upload_other.txt', 'upload.txt'].sort());
});
test('Retrieve file from single glob', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, ['upload.*']);
t.deepEqual(globbedAssets, ['upload.txt']);
});
test('Retrieve multiple files from single glob', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, ['*.txt']);
t.deepEqual(globbedAssets.sort(), ['upload_other.txt', 'upload.txt'].sort());
});
test('Accept glob array with one value', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [['*load.txt'], ['*_other.txt']]);
t.deepEqual(globbedAssets.sort(), ['upload_other.txt', 'upload.txt'].sort());
});
test('Exclude globs that resolve to no files', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [['upload.txt', '!upload.txt']]);
t.deepEqual(globbedAssets, []);
});
test('Accept glob array with one value for missing files', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [['*missing.txt'], ['*_other.txt']]);
t.deepEqual(globbedAssets.sort(), ['upload_other.txt'].sort());
});
test('Include dotfiles', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, ['.dot*']);
t.deepEqual(globbedAssets, ['.dotfile']);
});
test('Ingnore single negated glob', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, ['!*.txt']);
t.deepEqual(globbedAssets, []);
});
test('Ingnore single negated glob in Object', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [{path: '!*.txt'}]);
t.deepEqual(globbedAssets, []);
});
test('Accept negated globs', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [['*.txt', '!**/*_other.txt']]);
t.deepEqual(globbedAssets, ['upload.txt']);
});
test('Expand directories', async t => {
const cwd = tempy.directory();
await copy(fixtures, path.resolve(cwd, 'dir'));
const globbedAssets = await globAssets({cwd}, [['dir']]);
t.deepEqual(globbedAssets.sort(), ['dir', 'dir/upload_other.txt', 'dir/upload.txt', 'dir/.dotfile'].sort());
});
test('Include empty directory as defined', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
await ensureDir(path.resolve(cwd, 'empty'));
const globbedAssets = await globAssets({cwd}, [['empty']]);
t.deepEqual(globbedAssets, ['empty']);
});