react / wstein / node_modules / jest-cli / node_modules / node-haste / __tests__ / ConfigurationTrie-test.js
80668 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*15* @emails [email protected] [email protected]16*/1718describe('ConfigurationTrie', function() {19var ConfigurationTrie = require('../lib/ConfigurationTrie');20var ProjectConfiguration = require('../lib/resource/ProjectConfiguration');21var path = require('path');2223it('should match subpath', function() {24var config = new ProjectConfiguration(path.join('a','b','package.json'), {});25var trie = new ConfigurationTrie([config]);2627expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(config);28expect(trie.findConfiguration(path.join('a','a.js'))).toBe(undefined);29expect(trie.findConfiguration(path.join('a','b','c','d.js'))).toBe(config);30expect(trie.findConfiguration(path.join('a','b.js'))).toBe(undefined);31});323334it('should support haste paths', function() {35var config = new ProjectConfiguration(36'a/b/package.json',37{38haste: { roots: ['c', 'd'] }39});40var trie = new ConfigurationTrie([config]);4142expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(undefined);43expect(trie.findConfiguration(path.join('a','b','c','a.js'))).toBe(config);44expect(trie.findConfiguration(path.join('a','b','d','d.js'))).toBe(config);45});464748it('should match subpath with 2 configurations', function() {49var config1 = new ProjectConfiguration(path.join('a','b','package.json'), {});50var config2 = new ProjectConfiguration(path.join('a','c','package.json'), {});51var trie = new ConfigurationTrie([config1, config2]);5253expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(config1);54expect(trie.findConfiguration(path.join('a','c','c','d.js'))).toBe(config2);55});565758it('should match nested configurations', function() {59var config1 = new ProjectConfiguration(path.join('a','b','package.json'), {});60var config2 =61new ProjectConfiguration(path.join('a','b','c','package.json'), {});62var trie = new ConfigurationTrie([config1, config2]);6364expect(trie.findConfiguration(path.join('a','b','a.js'))).toBe(config1, path.join('a','b','a.js'));65expect(trie.findConfiguration(path.join('a','b','c.js'))).toBe(config1, path.join('a','b','c.js'));66expect(trie.findConfiguration(path.join('a','b','c','d.js'))).toBe(config2, path.join('a','b','c','d.js'));67});6869});707172