Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80635 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
var path = require('path');
13
var TestRunner = require('../TestRunner');
14
var utils = require('../lib/utils');
15
16
describe('TestRunner-fs', function() {
17
18
describe('testPathsMatching', function() {
19
20
pit('finds tests with default file extensions', function() {
21
var rootDir = path.resolve(__dirname, 'test_root');
22
var runner = new TestRunner(utils.normalizeConfig({
23
rootDir: rootDir,
24
testDirectoryName: '__testtests__',
25
}));
26
return runner.promiseTestPathsMatching(/.*/).then(function(paths) {
27
var relPaths = paths.map(function (absPath) {
28
return path.relative(rootDir, absPath);
29
});
30
expect(relPaths).toEqual([path.normalize('__testtests__/test.js')]);
31
});
32
});
33
34
pit('finds tests with similar but custom file extensions', function() {
35
var rootDir = path.resolve(__dirname, 'test_root');
36
var runner = new TestRunner(utils.normalizeConfig({
37
rootDir: rootDir,
38
testDirectoryName: '__testtests__',
39
testFileExtensions: ['jsx'],
40
}));
41
return runner.promiseTestPathsMatching(/.*/).then(function(paths) {
42
var relPaths = paths.map(function (absPath) {
43
return path.relative(rootDir, absPath);
44
});
45
expect(relPaths).toEqual([path.normalize('__testtests__/test.jsx')]);
46
});
47
});
48
49
pit('finds tests with totally custom foobar file extensions', function() {
50
var rootDir = path.resolve(__dirname, 'test_root');
51
var runner = new TestRunner(utils.normalizeConfig({
52
rootDir: rootDir,
53
testDirectoryName: '__testtests__',
54
testFileExtensions: ['foobar'],
55
}));
56
return runner.promiseTestPathsMatching(/.*/).then(function(paths) {
57
var relPaths = paths.map(function (absPath) {
58
return path.relative(rootDir, absPath);
59
});
60
expect(relPaths).toEqual([path.normalize('__testtests__/test.foobar')]);
61
});
62
});
63
64
pit('finds tests with many kinds of file extensions', function() {
65
var rootDir = path.resolve(__dirname, 'test_root');
66
var runner = new TestRunner(utils.normalizeConfig({
67
rootDir: rootDir,
68
testDirectoryName: '__testtests__',
69
testFileExtensions: ['js', 'jsx'],
70
}));
71
return runner.promiseTestPathsMatching(/.*/).then(function(paths) {
72
var relPaths = paths.map(function (absPath) {
73
return path.relative(rootDir, absPath);
74
});
75
expect(relPaths.sort()).toEqual([
76
path.normalize('__testtests__/test.js'),
77
path.normalize('__testtests__/test.jsx'),
78
]);
79
});
80
});
81
82
});
83
84
});
85
86