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('JSMockLoader', function() {
20
var JSMockLoader = require('../lib/loader/JSMockLoader');
21
var path = require('path');
22
var loadResouce = require('../lib/test_helpers/loadResource');
23
24
it('should match package.json paths', function() {
25
var loader = new JSMockLoader();
26
expect(loader.matchPath('x.js')).toBe(false);
27
expect(loader.matchPath('a/__mocks__/x.js')).toBe(true);
28
expect(loader.matchPath('__mocks__/x.js')).toBe(true);
29
expect(loader.matchPath('a/__mocks__/support/x.js')).toBe(false);
30
expect(loader.matchPath('a/1.css')).toBe(false);
31
});
32
33
it('should match package.json paths with matchSubDirs', function() {
34
var loader = new JSMockLoader({ matchSubDirs: true });
35
expect(loader.matchPath('x.js')).toBe(false);
36
expect(loader.matchPath('a/__mocks__/x.js')).toBe(true);
37
expect(loader.matchPath('__mocks__/x.js')).toBe(true);
38
expect(loader.matchPath('a/__mocks__/support/x.js')).toBe(true);
39
expect(loader.matchPath('a/1.css')).toBe(false);
40
});
41
42
var testData = path.join(__dirname, '..', '__test_data__', 'JSMock');
43
44
it('should extract dependencies', function() {
45
loadResouce(
46
new JSMockLoader(),
47
path.join(testData, '__mocks__', 'mock.js'),
48
null,
49
function(errors, resource) {
50
expect(resource.id).toBe('mock');
51
expect(resource.requiredModules).toEqual(['foo', 'bar']);
52
});
53
});
54
55
});
56
57