Debian Codegraph @

test/other/test-matcher.js

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /*jslint nomen: true */
2 var path = require('path'),
3 glob = require('glob'),
4 root = path.resolve(__dirname, 'data', 'matcher'),
5 src = '../../lib/util/file-matcher.js',
6 fileMatcher = require(src),
7 allFiles;
8
9 module.exports = {
10 setUp: function (cb) {
11 if (!allFiles) {
12 glob('**/*.js', { cwd: root}, function (err, files) {
13 allFiles = files.map(function (file) { return path.resolve(root, file); });
14 cb();
15 });
16 } else {
17 cb();
18 }
19 },
20 "should return all files except those under node_modules by default": function (test) {
21 fileMatcher.filesFor(function (err, files) {
22 test.ok(!err);
23 allFiles.forEach(function (file) {
24 var matcher = function (f) { return f === file; },
25 shouldMatch = file.indexOf('file.js') < 0;
26 if (shouldMatch) {
27 test.ok(files.filter(matcher).length, 'Should match [' + file + '] but did not');
28 } else {
29 test.ok(!files.filter(matcher).length, 'Should NOT match [' + file + '] but did');
30 }
31 });
32 test.done();
33 });
34 },
35 "should return relative filenames when requested": function (test) {
36 fileMatcher.filesFor({ root: root, relative: true }, function (err, files) {
37 test.ok(!err);
38 allFiles.forEach(function (file) {
39 var matcher = function (f) { return path.resolve(root, f) === file; },
40 shouldMatch = file.indexOf('file.js') < 0;
41 if (shouldMatch) {
42 test.ok(files.filter(matcher).length, 'Should match [' + file + '] but did not');
43 } else {
44 test.ok(!files.filter(matcher).length, 'Should NOT match [' + file + '] but did');
45 }
46 });
47 test.done();
48 });
49 },
50 "should match stuff under cwd": function (test) {
51 fileMatcher.matcherFor(function (err, matchFn) {
52 test.ok(!err);
53 test.ok(matchFn(path.resolve(__dirname, src)), 'should match itself');
54 test.done();
55 });
56 },
57 "should match stuff under cwd overriding relative opts passed in": function (test) {
58 fileMatcher.matcherFor({ relative: true }, function (err, matchFn) {
59 test.ok(!err);
60 test.ok(matchFn(path.resolve(__dirname, src)), 'should match itself');
61 test.done();
62 });
63 },
64 "should ignore node_modules": function (test) {
65 fileMatcher.matcherFor({ root: root }, function (err, matchFn) {
66 test.ok(!err);
67 test.ok(matchFn.files);
68 test.deepEqual(allFiles.filter(function (f) { return !f.match(/node_modules/); }).sort(),
69 matchFn.files.sort());
70 allFiles.forEach(function (file) {
71 var shouldMatch = file.indexOf('file.js') < 0;
72 if (shouldMatch) {
73 test.ok(matchFn(file), 'Should match [' + file + '] but did not');
74 } else {
75 test.ok(!matchFn(file), 'Should NOT match [' + file + '] but did');
76 }
77 });
78 test.done();
79 });
80 },
81 "should match stuff with explicit includes and excludes": function (test) {
82 fileMatcher.matcherFor({ root: root, includes: [ '**/general/**/*.js' ], excludes: [ '**/general.js' ] }, function (err, matchFn) {
83 test.ok(!err);
84 allFiles.forEach(function (file) {
85 if (file.indexOf('/general/') < 0) { return; }
86 var shouldMatch = file.indexOf('file.js') >= 0;
87 if (shouldMatch) {
88 test.ok(matchFn(file), 'Should match [' + file + '] but did not');
89 } else {
90 test.ok(!matchFn(file), 'Should NOT match [' + file + '] but did');
91 }
92 });
93 test.done();
94 });
95 }
96 };