Skip to content

Commit d2359cf

Browse files
committed
Enhance testing and tree formatting
1 parent 221c885 commit d2359cf

13 files changed

Lines changed: 223 additions & 34 deletions

File tree

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@structure-codes/utils",
33
"version": "0.0.2",
4-
"description": "A library to test if a filename is considered a to be a standard non-dotted dotfile",
4+
"description": "A library containing utilities to convert tree structures between JSON and string formats",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
77
"exports": {
@@ -11,7 +11,8 @@
1111
"scripts": {
1212
"build": "rollup -c rollup.config.js",
1313
"dev": "rollup -w -c rollup.config.js",
14-
"test": "jest --verbose"
14+
"test": "jest --verbose",
15+
"coverage": "jest --coverage"
1516
},
1617
"repository": {
1718
"type": "git",
@@ -38,5 +39,8 @@
3839
"ts-jest": "^27.0.7",
3940
"ts-node": "^10.4.0",
4041
"typescript": "^4.4.4"
42+
},
43+
"dependencies": {
44+
"@structure-codes/is-nondot": "^1.1.2"
4145
}
4246
}

src/__tests__/tree.test.ts

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { treeStringToJson } from "../treeStringToJson";
22
import * as fs from "fs";
33
import * as path from "path";
4-
import { TreeType } from "../types";
4+
import { defaultSettings, ISettings, TreeType } from "../types";
55
import { treeJsonToString } from "../treeJsonToString";
66

77
const dirPath = path.join(__dirname, "trees");
8-
const trees = fs.readdirSync(dirPath);
9-
trees.forEach((file) => {
10-
const treeString = fs.readFileSync(path.join(dirPath, file)).toString();
8+
const tabTrees = fs.readdirSync(dirPath + "/tab-tests");
9+
const settingsTree = fs.readFileSync(dirPath + "/settings-tests/base.tree").toString();
10+
const noDotsTree = fs.readFileSync(dirPath + "/settings-tests/no-dots.tree").toString();
11+
const noFilesTree = fs.readFileSync(dirPath + "/settings-tests/no-files.tree").toString();
12+
const depth2Tree = fs.readFileSync(dirPath + "/settings-tests/depth-2.tree").toString();
13+
14+
tabTrees.forEach((file) => {
15+
const treeString = fs.readFileSync(path.join(dirPath + "/tab-tests", file)).toString();
1116
let tree: TreeType[];
12-
test(`can convert file to TreeType format: ${file}`, () => {
17+
test(`treeStringToJson can convert file to TreeType format: ${file}`, () => {
1318
tree = treeStringToJson(treeString);
1419

1520
// Number of parents
@@ -18,8 +23,49 @@ trees.forEach((file) => {
1823
expect(tree[2].name).toBe("static");
1924
});
2025

21-
test("can convert TreeType format back to original string", () => {
22-
const newTreeString = treeJsonToString(tree);
26+
test("treeJsonToString can convert TreeType format back to original string", () => {
27+
const newTreeString = treeJsonToString({ tree });
2328
expect(treeString === newTreeString);
2429
});
30+
31+
});
32+
33+
34+
test("treeJsonToString base options works", () => {
35+
const baseTree = treeStringToJson(settingsTree);
36+
const newTreeString = treeJsonToString({ tree: baseTree, options: defaultSettings });
37+
expect(settingsTree === newTreeString);
38+
});
39+
40+
test("treeJsonToString depth option works", () => {
41+
const options: ISettings = {
42+
...defaultSettings,
43+
depth: 2,
44+
};
45+
const baseTree = treeStringToJson(settingsTree);
46+
const newTreeString = treeJsonToString({ tree: baseTree, options });
47+
expect(settingsTree !== newTreeString);
48+
expect(depth2Tree === newTreeString);
49+
});
50+
51+
test("treeJsonToString hideDots option works", () => {
52+
const options: ISettings = {
53+
...defaultSettings,
54+
hideDots: true,
55+
};
56+
const baseTree = treeStringToJson(settingsTree);
57+
const newTreeString = treeJsonToString({ tree: baseTree, options });
58+
expect(settingsTree !== newTreeString);
59+
expect(noDotsTree === newTreeString);
60+
});
61+
62+
test("treeJsonToString hideFiles option works", () => {
63+
const options: ISettings = {
64+
...defaultSettings,
65+
hideFiles: true,
66+
};
67+
const baseTree = treeStringToJson(settingsTree);
68+
const newTreeString = treeJsonToString({ tree: baseTree, options });
69+
expect(settingsTree !== newTreeString);
70+
expect(noFilesTree === newTreeString);
2571
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
//
3+
├── Jenkinsfile
4+
├── LICENSE
5+
├── config.js
6+
├── .git
7+
│ ├── articles
8+
│ └── utils
9+
├── functions
10+
├── src
11+
│ ├── articles
12+
│ ├── components
13+
│ │ ├── builder
14+
│ │ │ ├── center
15+
│ │ │ ├── left
16+
│ │ │ │ └── sections-asdf //sdfa
17+
│ │ │ ├── lists.sdf
18+
│ │ │ └── right
19+
│ │ │ └── sections.txt
20+
│ │ ├── dashboard.js
21+
│ │ ├── landing.ts
22+
│ │ ├── router.jsx
23+
│ │ └── shared
24+
│ └── utils
25+
└── static.xzxxx
26+
└── images
27+
├── screenshots
28+
└── templates.txt
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
//
3+
├── Jenkinsfile
4+
├── LICENSE
5+
├── config.js
6+
├── .git
7+
│ ├── articles
8+
│ └── utils
9+
├── functions
10+
├── src
11+
│ └── articles
12+
│ └── components
13+
│ └── utils
14+
└── static.xzxxx
15+
└── images
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
//
3+
├── functions
4+
├── src
5+
│ ├── articles
6+
│ ├── components
7+
│ │ ├── builder
8+
│ │ │ ├── center
9+
│ │ │ ├── left
10+
│ │ │ │ └── sections-asdf //sdfa
11+
│ │ │ └── right
12+
│ │ └── shared
13+
│ └── utils
14+
└── static.xzxxx
15+
└── images
16+
└── screenshots
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
//
3+
├── .git
4+
│ ├── articles
5+
│ └── utils
6+
├── functions
7+
├── src
8+
│ ├── articles
9+
│ ├── components
10+
│ │ ├── builder
11+
│ │ │ ├── center
12+
│ │ │ ├── left
13+
│ │ │ │ └── sections-asdf //sdfa
14+
│ │ │ └── right
15+
│ │ └── shared
16+
│ └── utils
17+
└── static.xzxxx
18+
└── images
19+
└── screenshots
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)