1 | var IgnoreFile = require("../")
|
2 | , fs = require('fs')
|
3 |
|
4 |
|
5 | var c = require("./common.js")
|
6 | c.ignores({ ".gitignore": ["a/b/c/abc"] })
|
7 | c.ignores({ ".ignore": ["*", "!a/b/c/abc"] })
|
8 |
|
9 |
|
10 | var expected =
|
11 | [ "/a"
|
12 | , "/a/b"
|
13 | , "/a/b/c"
|
14 | , "/a/b/c/abc" ]
|
15 |
|
16 | var originalReadFile = fs.readFile
|
17 | , parallelCount = 0
|
18 | , firstCall
|
19 |
|
20 |
|
21 |
|
22 | fs.readFile = function (filename, options, callback) {
|
23 | if (typeof options === 'function') {
|
24 | callback = options
|
25 | options = false
|
26 | }
|
27 |
|
28 | parallelCount++
|
29 |
|
30 | process.nextTick(function () {
|
31 | if (parallelCount > 1) {
|
32 | if (!firstCall) {
|
33 | return firstCall = function (cb) {
|
34 | originalReadFile(filename, options, function (err, data) {
|
35 | callback(err, data)
|
36 | if (cb) cb()
|
37 | })
|
38 | }
|
39 | }
|
40 |
|
41 | if (filename.indexOf('.gitignore') !== -1) {
|
42 | firstCall(function () {
|
43 | originalReadFile(filename, options, callback)
|
44 | })
|
45 | } else {
|
46 | originalReadFile(filename, options, function (err, data) {
|
47 | callback(err, data)
|
48 | firstCall()
|
49 | })
|
50 | }
|
51 | } else {
|
52 | originalReadFile(filename, options, callback)
|
53 | parallelCount = 0
|
54 | }
|
55 | })
|
56 | }
|
57 |
|
58 | require("tap").test("read file order", function (t) {
|
59 | t.pass("start")
|
60 |
|
61 | IgnoreFile({ path: __dirname + "/fixtures"
|
62 | , ignoreFiles: [".gitignore", ".ignore"] })
|
63 | .on("ignoreFile", function (e) {
|
64 | console.error("ignore file!", e)
|
65 | })
|
66 | .on("child", function (e) {
|
67 | var p = e.path.substr(e.root.path.length)
|
68 | var i = expected.indexOf(p)
|
69 | if (i === -1) {
|
70 | t.fail("unexpected file found", {f: p})
|
71 | } else {
|
72 | t.pass(p)
|
73 | expected.splice(i, 1)
|
74 | }
|
75 | })
|
76 | .on("close", function () {
|
77 | fs.readFile = originalReadFile
|
78 | t.notOk(expected.length, "all expected files should be seen")
|
79 | t.end()
|
80 | })
|
81 | })
|