Skip to content

Commit

Permalink
Fixes: #20
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRaindrop committed Aug 3, 2020
1 parent a438568 commit cf4518d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
Empty file.
42 changes: 38 additions & 4 deletions __test__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ function typof (val) {
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
}

describe('use with require', function () {
describe('use with require #1', function () {

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

beforeEach(function (done) {
if (!result) {
tree({
ignore: ['package.json', /node_modules\/bfolder\/node_modules/],
o: path.resolve(__dirname, 'o.data'),
o: outputPath,
l: 3,
f: true,
base: testBase,
Expand Down Expand Up @@ -47,7 +48,40 @@ describe('use with require', function () {
});

it('should generate report', function () {
const generatedReport = fs.readFileSync(path.resolve(__dirname, 'o.data'));
const generatedReport = fs.readFileSync(outputPath);
expect(generatedReport.toString()).to.equal(result.report);
})
});
});

describe('use with require #2', function () {

let result;
const outputPath = path.resolve(__dirname, 'report/o#2.data');

beforeEach(function (done) {
if (!result) {
tree({
ignore: ['package.json', /node_modules\/bfolder\/node_modules/, 'b.data', 't.txt'],
o: outputPath,
l: 3,
f: true,
base: testBase,
noreport: true,
directoryFirst: true,
}).then((res) => {
result = res;
done();
});
}
else {
done();
}
});

it('should output corret report with ignores', function () {
const generatedReport = fs.readFileSync(outputPath);
const report = result.report;
expect(generatedReport.toString()).to.equal(report);
expect(report).to.match(/└── a\.ts/)
});
});
10 changes: 0 additions & 10 deletions __test__/o.data

This file was deleted.

11 changes: 11 additions & 0 deletions __test__/report/o#1.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/Users/rdp/Dev/github/MrRaindrop/tree-cli/__test__/__data__
├── node_modules/
| ├── bfolder/
| ├── a.txt
| └── t.txt
├── a.ts
└── b.data

directory: 2 file: 4

ignored: directory (1), file (1)
9 changes: 9 additions & 0 deletions __test__/report/o#2.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/Users/rdp/Dev/github/MrRaindrop/tree-cli/__test__/__data__
├── node_modules/
| ├── bfolder/
| └── a.txt
└── a.ts

directory: 4 file: 6

ignored: directory (2), file (4)
4 changes: 3 additions & 1 deletion tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ var Promise = require('bluebird'),

for (var i = 0, l = children.length; i < l; i++) {
(i === l - 1) && (last = true);
str += _stringifyTreeNode(children[i], last);
var child = children[i];
var isLast = child.lasts[child.level - 1] === true;
str += _stringifyTreeNode(child, isLast);
}
return str;

Expand Down

0 comments on commit cf4518d

Please sign in to comment.