1 | var assert = require("assert");
|
2 | var file = require('../file-system');
|
3 | var path = require('path');
|
4 | var fs = require('fs');
|
5 |
|
6 | function getPath(filepath) {
|
7 | return path.join(__dirname, 'var', filepath);
|
8 | }
|
9 |
|
10 | describe('filter params', function() {
|
11 | var allFiles = [
|
12 | getPath('filter/index.css'),
|
13 | getPath('filter/index.js'),
|
14 | getPath('filter/index.html'),
|
15 | getPath('filter/1/ab.css'),
|
16 | getPath('filter/1/abc.js'),
|
17 | getPath('filter/1/a.html'),
|
18 | getPath('filter/1/1/ac.css'),
|
19 | getPath('filter/1/1/bc.js'),
|
20 | getPath('filter/1/1/a-b-c.html'),
|
21 | getPath('filter/2/a_b_c.css'),
|
22 | getPath('filter/2/2/a_b_c.css'),
|
23 | getPath('filter/2/a-c.js'),
|
24 | getPath('filter/2/b.html')
|
25 | ];
|
26 |
|
27 | before(function() {
|
28 | allFiles.forEach(function(item) {
|
29 | file.writeFileSync(item);
|
30 | });
|
31 | });
|
32 |
|
33 | it('match css files in current dir', function() {
|
34 | var result = [];
|
35 |
|
36 | file.recurseSync(getPath('filter'), [
|
37 | '*.css'
|
38 | ], function(filepath, filename) {
|
39 | if (!filename) return;
|
40 |
|
41 | result.push(filepath);
|
42 | });
|
43 |
|
44 | assert.equal(result.length, 1);
|
45 | });
|
46 |
|
47 | it('match all css files', function() {
|
48 | var result = [];
|
49 |
|
50 | file.recurseSync(getPath('filter'), [
|
51 | '**/*.css'
|
52 | ], function(filepath, filename) {
|
53 | if (!filename) return;
|
54 | result.push(filepath);
|
55 | });
|
56 |
|
57 | assert.equal(result.length, 5);
|
58 | });
|
59 |
|
60 | it('match all css files in specific folder', function() {
|
61 | var result = [];
|
62 |
|
63 | file.recurseSync(getPath('filter'), [
|
64 | '2/*.css'
|
65 | ], function(filepath, filename) {
|
66 | if (!filename) return;
|
67 | result.push(filepath);
|
68 | });
|
69 |
|
70 | assert.equal(result.length, 1);
|
71 | });
|
72 |
|
73 | it('specific file * name', function() {
|
74 | var result = [];
|
75 |
|
76 | file.recurseSync(getPath('filter'), [
|
77 | '2/**/*c.css'
|
78 | ], function(filepath, filename) {
|
79 | if (!filename) return;
|
80 | result.push(filepath);
|
81 | });
|
82 |
|
83 | assert.equal(result.length, 2);
|
84 | });
|
85 |
|
86 | it('exclude all css files in specific folder', function() {
|
87 | var result = [];
|
88 |
|
89 | file.recurseSync(getPath('filter'), [
|
90 | '**/*.css',
|
91 | '!2/**/*.css'
|
92 | ], function(filepath, filename) {
|
93 | if (!filename) return;
|
94 | result.push(filepath);
|
95 | });
|
96 |
|
97 | assert.equal(result.length, 3);
|
98 | });
|
99 |
|
100 | after(function() {
|
101 | file.rmdirSync(getPath('filter'));
|
102 | });
|
103 | }); |
\ | No newline at end of file |