Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80657 views
1
/**
2
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
3
*
4
* This source code is licensed under the BSD-style license found in the
5
* LICENSE file in the root directory of this source tree. An additional grant
6
* of patent rights can be found in the PATENTS file in the same directory.
7
*/
8
'use strict';
9
10
jest.autoMockOff();
11
12
describe('utils-normalizeConfig', function() {
13
var path;
14
var root;
15
var utils;
16
var expectedPathFooBar;
17
var expectedPathFooQux;
18
var expectedPathAbs;
19
var expectedPathAbsAnother;
20
21
beforeEach(function() {
22
path = require('path');
23
root = path.resolve('/').replace(/[\\\/]/g, '');
24
expectedPathFooBar = root + '/root/path/foo/bar/baz';
25
expectedPathFooQux = root + '/root/path/foo/qux/quux';
26
expectedPathAbs = root + '/an/abs/path';
27
expectedPathAbsAnother = root + '/another/abs/path';
28
utils = require('../utils');
29
});
30
31
it('throws when an invalid config option is passed in', function() {
32
expect(function() {
33
utils.normalizeConfig({
34
rootDir: '/root/path/foo',
35
thisIsAnInvalidConfigKey: 'with a value even!'
36
});
37
}).toThrow('Unknown config option: thisIsAnInvalidConfigKey');
38
});
39
40
describe('rootDir', function() {
41
it('throws if the config is missing a rootDir property', function() {
42
expect(function() {
43
utils.normalizeConfig({});
44
}).toThrow('No rootDir config value found!');
45
});
46
});
47
48
describe('collectCoverageOnlyFrom', function() {
49
it('normalizes all paths relative to rootDir', function() {
50
var config = utils.normalizeConfig({
51
rootDir: '/root/path/foo/',
52
collectCoverageOnlyFrom: {
53
'bar/baz': true,
54
'qux/quux/': true
55
}
56
}, '/root/path');
57
58
var expected = {};
59
expected[expectedPathFooBar] = true;
60
expected[expectedPathFooQux] = true;
61
62
expect(config.collectCoverageOnlyFrom).toEqual(expected);
63
});
64
65
it('does not change absolute paths', function() {
66
var config = utils.normalizeConfig({
67
rootDir: '/root/path/foo',
68
collectCoverageOnlyFrom: {
69
'/an/abs/path': true,
70
'/another/abs/path': true
71
}
72
});
73
74
var expected = {};
75
expected[expectedPathAbs] = true;
76
expected[expectedPathAbsAnother] = true;
77
78
expect(config.collectCoverageOnlyFrom).toEqual(expected);
79
});
80
81
it('substitutes <rootDir> tokens', function() {
82
var config = utils.normalizeConfig({
83
rootDir: '/root/path/foo',
84
collectCoverageOnlyFrom: {
85
'<rootDir>/bar/baz': true
86
}
87
});
88
89
var expected = {};
90
expected[expectedPathFooBar] = true;
91
92
expect(config.collectCoverageOnlyFrom).toEqual(expected);
93
});
94
});
95
96
describe('testPathDirs', function() {
97
it('normalizes all paths relative to rootDir', function() {
98
var config = utils.normalizeConfig({
99
rootDir: '/root/path/foo',
100
testPathDirs: [
101
'bar/baz',
102
'qux/quux/'
103
]
104
}, '/root/path');
105
106
expect(config.testPathDirs).toEqual([
107
expectedPathFooBar, expectedPathFooQux
108
]);
109
});
110
111
it('does not change absolute paths', function() {
112
var config = utils.normalizeConfig({
113
rootDir: '/root/path/foo',
114
testPathDirs: [
115
'/an/abs/path',
116
'/another/abs/path'
117
]
118
});
119
120
expect(config.testPathDirs).toEqual([
121
expectedPathAbs, expectedPathAbsAnother
122
]);
123
});
124
125
it('substitutes <rootDir> tokens', function() {
126
var config = utils.normalizeConfig({
127
rootDir: '/root/path/foo',
128
testPathDirs: [
129
'<rootDir>/bar/baz'
130
]
131
});
132
133
expect(config.testPathDirs).toEqual([expectedPathFooBar]);
134
});
135
});
136
137
describe('scriptPreprocessor', function() {
138
it('normalizes the path according to rootDir', function() {
139
var config = utils.normalizeConfig({
140
rootDir: '/root/path/foo',
141
scriptPreprocessor: 'bar/baz'
142
}, '/root/path');
143
144
expect(config.scriptPreprocessor).toEqual(expectedPathFooBar);
145
});
146
147
it('does not change absolute paths', function() {
148
var config = utils.normalizeConfig({
149
rootDir: '/root/path/foo',
150
scriptPreprocessor: '/an/abs/path'
151
});
152
153
expect(config.scriptPreprocessor).toEqual(expectedPathAbs);
154
});
155
156
it('substitutes <rootDir> tokens', function() {
157
var config = utils.normalizeConfig({
158
rootDir: '/root/path/foo',
159
scriptPreprocessor: '<rootDir>/bar/baz'
160
});
161
162
expect(config.scriptPreprocessor).toEqual(expectedPathFooBar);
163
});
164
});
165
166
describe('setupEnvScriptFile', function() {
167
it('normalizes the path according to rootDir', function() {
168
var config = utils.normalizeConfig({
169
rootDir: '/root/path/foo',
170
setupEnvScriptFile: 'bar/baz'
171
}, '/root/path');
172
173
expect(config.setupEnvScriptFile).toEqual(expectedPathFooBar);
174
});
175
176
it('does not change absolute paths', function() {
177
var config = utils.normalizeConfig({
178
rootDir: '/root/path/foo',
179
setupEnvScriptFile: '/an/abs/path'
180
});
181
182
expect(config.setupEnvScriptFile).toEqual(expectedPathAbs);
183
});
184
185
it('substitutes <rootDir> tokens', function() {
186
var config = utils.normalizeConfig({
187
rootDir: '/root/path/foo',
188
setupEnvScriptFile: '<rootDir>/bar/baz'
189
});
190
191
expect(config.setupEnvScriptFile).toEqual(expectedPathFooBar);
192
});
193
});
194
195
describe('setupTestFrameworkScriptFile', function() {
196
it('normalizes the path according to rootDir', function() {
197
var config = utils.normalizeConfig({
198
rootDir: '/root/path/foo',
199
setupTestFrameworkScriptFile: 'bar/baz'
200
}, '/root/path');
201
202
expect(config.setupTestFrameworkScriptFile).toEqual(expectedPathFooBar);
203
});
204
205
it('does not change absolute paths', function() {
206
var config = utils.normalizeConfig({
207
rootDir: '/root/path/foo',
208
setupTestFrameworkScriptFile: '/an/abs/path'
209
});
210
211
expect(config.setupTestFrameworkScriptFile).toEqual(expectedPathAbs);
212
});
213
214
it('substitutes <rootDir> tokens', function() {
215
var config = utils.normalizeConfig({
216
rootDir: '/root/path/foo',
217
setupTestFrameworkScriptFile: '<rootDir>/bar/baz'
218
});
219
220
expect(config.setupTestFrameworkScriptFile).toEqual(expectedPathFooBar);
221
});
222
});
223
224
describe('testPathIgnorePatterns', function() {
225
it('does not normalize paths relative to rootDir', function() {
226
// This is a list of patterns, so we can't assume any of them are
227
// directories
228
var config = utils.normalizeConfig({
229
rootDir: '/root/path/foo',
230
testPathIgnorePatterns: [
231
'bar/baz',
232
'qux/quux'
233
]
234
}, '/root/path');
235
236
expect(config.testPathIgnorePatterns).toEqual([
237
'bar/baz',
238
'qux/quux'
239
]);
240
});
241
242
it('does not normalize trailing slashes', function() {
243
// This is a list of patterns, so we can't assume any of them are
244
// directories
245
var config = utils.normalizeConfig({
246
rootDir: '/root/path/foo',
247
testPathIgnorePatterns: [
248
'bar/baz',
249
'qux/quux/'
250
]
251
});
252
253
expect(config.testPathIgnorePatterns).toEqual([
254
'bar/baz',
255
'qux/quux/'
256
]);
257
});
258
259
it('substitutes <rootDir> tokens', function() {
260
var config = utils.normalizeConfig({
261
rootDir: '/root/path/foo',
262
testPathIgnorePatterns: [
263
'hasNoToken',
264
'<rootDir>/hasAToken'
265
]
266
});
267
268
expect(config.testPathIgnorePatterns).toEqual([
269
'hasNoToken',
270
'/root/path/foo/hasAToken'
271
]);
272
});
273
});
274
275
describe('modulePathIgnorePatterns', function() {
276
it('does not normalize paths relative to rootDir', function() {
277
// This is a list of patterns, so we can't assume any of them are
278
// directories
279
var config = utils.normalizeConfig({
280
rootDir: '/root/path/foo',
281
modulePathIgnorePatterns: [
282
'bar/baz',
283
'qux/quux'
284
]
285
}, '/root/path');
286
287
expect(config.modulePathIgnorePatterns).toEqual([
288
'bar/baz',
289
'qux/quux'
290
]);
291
});
292
293
it('does not normalize trailing slashes', function() {
294
// This is a list of patterns, so we can't assume any of them are
295
// directories
296
var config = utils.normalizeConfig({
297
rootDir: '/root/path/foo',
298
modulePathIgnorePatterns: [
299
'bar/baz',
300
'qux/quux/'
301
]
302
});
303
304
expect(config.modulePathIgnorePatterns).toEqual([
305
'bar/baz',
306
'qux/quux/'
307
]);
308
});
309
310
it('substitutes <rootDir> tokens', function() {
311
var config = utils.normalizeConfig({
312
rootDir: '/root/path/foo',
313
modulePathIgnorePatterns: [
314
'hasNoToken',
315
'<rootDir>/hasAToken'
316
]
317
});
318
319
expect(config.modulePathIgnorePatterns).toEqual([
320
'hasNoToken',
321
'/root/path/foo/hasAToken'
322
]);
323
});
324
});
325
});
326
327