Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80668 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
* @emails [email protected] [email protected]
17
*/
18
19
describe('ConfigurationTrie', function() {
20
var ConfigurationTrie = require('../lib/ConfigurationTrie');
21
var ProjectConfiguration = require('../lib/resource/ProjectConfiguration');
22
var path = require('path');
23
24
it('should match subpath', function() {
25
var config = new ProjectConfiguration(path.join('a','b','package.json'), {});
26
var trie = new ConfigurationTrie([config]);
27
28
expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(config);
29
expect(trie.findConfiguration(path.join('a','a.js'))).toBe(undefined);
30
expect(trie.findConfiguration(path.join('a','b','c','d.js'))).toBe(config);
31
expect(trie.findConfiguration(path.join('a','b.js'))).toBe(undefined);
32
});
33
34
35
it('should support haste paths', function() {
36
var config = new ProjectConfiguration(
37
'a/b/package.json',
38
{
39
haste: { roots: ['c', 'd'] }
40
});
41
var trie = new ConfigurationTrie([config]);
42
43
expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(undefined);
44
expect(trie.findConfiguration(path.join('a','b','c','a.js'))).toBe(config);
45
expect(trie.findConfiguration(path.join('a','b','d','d.js'))).toBe(config);
46
});
47
48
49
it('should match subpath with 2 configurations', function() {
50
var config1 = new ProjectConfiguration(path.join('a','b','package.json'), {});
51
var config2 = new ProjectConfiguration(path.join('a','c','package.json'), {});
52
var trie = new ConfigurationTrie([config1, config2]);
53
54
expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(config1);
55
expect(trie.findConfiguration(path.join('a','c','c','d.js'))).toBe(config2);
56
});
57
58
59
it('should match nested configurations', function() {
60
var config1 = new ProjectConfiguration(path.join('a','b','package.json'), {});
61
var config2 =
62
new ProjectConfiguration(path.join('a','b','c','package.json'), {});
63
var trie = new ConfigurationTrie([config1, config2]);
64
65
expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(config1, path.join('a','b','a.js'));
66
expect(trie.findConfiguration(path.join('a','b','c.js'))).toBe(config1, path.join('a','b','c.js'));
67
expect(trie.findConfiguration(path.join('a','b','c','d.js'))).toBe(config2, path.join('a','b','c','d.js'));
68
});
69
70
});
71
72