Skip to content

Commit 58d41c7

Browse files
committed
Fixes: #20
1 parent dc3e143 commit 58d41c7

6 files changed

Lines changed: 61 additions & 15 deletions

File tree

__test__/__data__/node_modules/t.txt

Whitespace-only changes.

__test__/index.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ function typof (val) {
99
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
1010
}
1111

12-
describe('use with require', function () {
12+
describe('use with require #1', function () {
1313

1414
let result;
15+
const outputPath = path.resolve(__dirname, 'report/o#1.data');
1516

1617
beforeEach(function (done) {
1718
if (!result) {
1819
tree({
1920
ignore: ['package.json', /node_modules\/bfolder\/node_modules/],
20-
o: path.resolve(__dirname, 'o.data'),
21+
o: outputPath,
2122
l: 3,
2223
f: true,
2324
base: testBase,
@@ -47,7 +48,40 @@ describe('use with require', function () {
4748
});
4849

4950
it('should generate report', function () {
50-
const generatedReport = fs.readFileSync(path.resolve(__dirname, 'o.data'));
51+
const generatedReport = fs.readFileSync(outputPath);
5152
expect(generatedReport.toString()).to.equal(result.report);
52-
})
53+
});
54+
});
55+
56+
describe('use with require #2', function () {
57+
58+
let result;
59+
const outputPath = path.resolve(__dirname, 'report/o#2.data');
60+
61+
beforeEach(function (done) {
62+
if (!result) {
63+
tree({
64+
ignore: ['package.json', /node_modules\/bfolder\/node_modules/, 'b.data', 't.txt'],
65+
o: outputPath,
66+
l: 3,
67+
f: true,
68+
base: testBase,
69+
noreport: true,
70+
directoryFirst: true,
71+
}).then((res) => {
72+
result = res;
73+
done();
74+
});
75+
}
76+
else {
77+
done();
78+
}
79+
});
80+
81+
it('should output corret report with ignores', function () {
82+
const generatedReport = fs.readFileSync(outputPath);
83+
const report = result.report;
84+
expect(generatedReport.toString()).to.equal(report);
85+
expect(report).to.match(/ a\.ts/)
86+
});
5387
});

__test__/o.data

Lines changed: 0 additions & 10 deletions
This file was deleted.

__test__/report/o#1.data

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/Users/rdp/Dev/github/MrRaindrop/tree-cli/__test__/__data__
2+
├── node_modules/
3+
| ├── bfolder/
4+
| ├── a.txt
5+
| └── t.txt
6+
├── a.ts
7+
└── b.data
8+
9+
directory: 2 file: 4
10+
11+
ignored: directory (1), file (1)

__test__/report/o#2.data

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/Users/rdp/Dev/github/MrRaindrop/tree-cli/__test__/__data__
2+
├── node_modules/
3+
| ├── bfolder/
4+
| └── a.txt
5+
└── a.ts
6+
7+
directory: 4 file: 6
8+
9+
ignored: directory (2), file (4)

tree.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,9 @@ var Promise = require('bluebird'),
496496

497497
for (var i = 0, l = children.length; i < l; i++) {
498498
(i === l - 1) && (last = true);
499-
str += _stringifyTreeNode(children[i], last);
499+
var child = children[i];
500+
var isLast = child.lasts[child.level - 1] === true;
501+
str += _stringifyTreeNode(child, isLast);
500502
}
501503
return str;
502504

0 commit comments

Comments
 (0)