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('JSBenchLoader', function() {
20
var JSBenchLoader = require('../lib/loader/JSBenchLoader');
21
var path = require('path');
22
var ProjectConfiguration = require('../lib/resource/ProjectConfiguration');
23
var loadResouce = require('../lib/test_helpers/loadResource');
24
25
it('should match package.json paths', function() {
26
var loader = new JSBenchLoader();
27
expect(loader.matchPath('x.js')).toBe(false);
28
expect(loader.matchPath('a/__benchmarks__/x.js')).toBe(true);
29
expect(loader.matchPath('__benchmarks__/x.js')).toBe(true);
30
expect(loader.matchPath('a/__benchmarks__/support/x.js')).toBe(false);
31
expect(loader.matchPath('a/1.css')).toBe(false);
32
});
33
34
it('should match package.json paths with matchSubDirs', function() {
35
var loader = new JSBenchLoader({ matchSubDirs: true });
36
expect(loader.matchPath('x.js')).toBe(false);
37
expect(loader.matchPath('a/__benchmarks__/x.js')).toBe(true);
38
expect(loader.matchPath('__benchmarks__/x.js')).toBe(true);
39
expect(loader.matchPath('a/__benchmarks__/support/x.js')).toBe(true);
40
expect(loader.matchPath('a/1.css')).toBe(false);
41
});
42
43
var testData = path.join(__dirname, '..', '__test_data__', 'JSBench');
44
45
it('should extract dependencies', function() {
46
loadResouce(
47
new JSBenchLoader(),
48
path.join(testData, '__benchmarks__/html-bench.js'),
49
null,
50
function(errors, resource) {
51
expect(resource.id).toBe('html-bench');
52
expect(resource.requiredModules)
53
.toEqual(['htmlSpecialChars']);
54
expect(resource.contacts).toEqual(['[email protected]']);
55
});
56
});
57
58
it('should resolve paths using configuration', function() {
59
loadResouce(
60
new JSBenchLoader(),
61
path.join(testData, 'configured', '__benchmarks__', 'test-bench.js'),
62
new ProjectConfiguration(
63
path.join(testData, 'configured', 'package.json'),
64
{}),
65
function(errors, resource) {
66
expect(resource.id).toBe(path.join('configured','__benchmarks__','test-bench.js'));
67
});
68
});
69
70
});
71
72