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("FileFinder", function() {
20
var path = require('path');
21
var finder = require('../lib/FileFinder');
22
23
var workingDir = path.join(__dirname, '..', '__test_data__', 'FileFinder');
24
25
it("should find files in a directory using FileFinder object", function() {
26
var result,
27
28
find = new finder({
29
scanDirs: [workingDir],
30
extensions: ['.js'],
31
useNative: true,
32
ignore: null
33
});
34
35
runs(function() {
36
find.find(function(files) {
37
result = files;
38
});
39
});
40
41
waitsFor(function() {
42
return result;
43
}, 300);
44
45
runs(function() {
46
var files = result.map(function(r) {
47
return r[0];
48
});
49
expect(files.join('\n')).toContain(path.join('sub','1.js'));
50
expect(files.join('\n')).toContain(path.join('sub','2.js'));
51
expect(files.join('\n')).toContain('3.js');
52
});
53
});
54
55
it("should find files in a directory", function() {
56
var result;
57
runs(function() {
58
finder.find([workingDir], ['.js'], null, function(files) {
59
result = files;
60
});
61
});
62
63
waitsFor(function() {
64
return result;
65
}, 300);
66
67
runs(function() {
68
var files = result.map(function(r) {
69
return r[0];
70
});
71
expect(files.join('\n')).toContain(path.join('sub','1.js'));
72
expect(files.join('\n')).toContain(path.join('sub','2.js'));
73
expect(files.join('\n')).toContain('3.js');
74
});
75
});
76
77
it("should find files in a directory using native find", function() {
78
var result;
79
runs(function() {
80
finder.findNative([workingDir], ['.js'], null, function(files) {
81
result = files;
82
});
83
});
84
85
waitsFor(function() {
86
return result;
87
}, 300);
88
89
runs(function() {
90
var files = result.map(function(r) {
91
return r[0];
92
});
93
expect(files.join('\n')).toContain(path.join('sub','2.js'));
94
expect(files.join('\n')).toContain(path.join('sub','2.js'));
95
expect(files.join('\n')).toContain('3.js');
96
});
97
});
98
});
99
100