Skip to content

Commit db944ff

Browse files
committed
chore: correct path to fixtures in unittests
1 parent f654d78 commit db944ff

File tree

13 files changed

+385
-129
lines changed

13 files changed

+385
-129
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,18 @@
116116
"compile": "tsc -p ./",
117117
"watch": "tsc -watch -p ./",
118118
"test": "yarn run compile && node ./out/test/runTest.js",
119+
"lint": "eslint src",
119120
"prettify": "prettier --ignore-path .eslintignore '**/*.{js,jsx,ts,tsx,json,html,css,yml}' --write"
120121
},
121122
"devDependencies": {
122123
"@types/glob": "^7.1.1",
123-
"@types/mocha": "^2.2.42",
124+
"@types/mocha": "8",
124125
"@types/node": "12",
125126
"@types/vscode": "^1.50.0",
126127
"@typescript-eslint/eslint-plugin": "^4.16.0",
127128
"@typescript-eslint/parser": "^4.16.0",
128129
"eslint": "^7.21.0",
129-
"mocha": "4",
130+
"mocha": "8",
130131
"prettier": "^2.3.1",
131132
"typescript": "4",
132133
"vscode-test": "^1.5.2"

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import { IVsCodeConfig } from './lib/interface';
33

44
export function getConfig(): IVsCodeConfig {
5-
let config: IVsCodeConfig = {
5+
const config: IVsCodeConfig = {
66
ignore: ['node_modules'],
77
rootCharCode: vscode.workspace
88
.getConfiguration()

src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,6 @@ export function activate(context: vscode.ExtensionContext) {
134134
}
135135

136136
// this method is called when your extension is deactivated
137-
export function deactivate() {}
137+
export function deactivate() {
138+
//
139+
}

src/lib/directory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export async function listDirectory(
7070
if (sort) {
7171
files = sortFilesLikeVSCode(files);
7272
}
73-
let remainingDepth = maxDepth - 1;
73+
const remainingDepth = maxDepth - 1;
7474
if (remainingDepth > 0) {
75-
for (let file of files) {
75+
for (const file of files) {
7676
if (file.isDirectory) {
7777
const subFiles = await listDirectory(file.absolutePath, {
7878
...config,

src/lib/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const defaultCharset: ICharset = {
1010
blank: String.fromCharCode(32), // ' ',
1111
};
1212

13-
function createTreeString(start: string, fill: string, size: number = 3) {
13+
function createTreeString(start: string, fill: string, size = 3) {
1414
let result = '';
1515
for (let i = 0; i < size; i++) {
1616
if (i === 0) {

src/lib/text.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IFileTreeItem } from './interface';
22

33
/** get line array. these lines are trimLeft with their common beginning substring. */
4-
function getLines(text: string = '') {
4+
function getLines(text = '') {
55
// split selected text into separate lines
66
// empty lines are ignored
77
const lines = text.split('\n').filter((line) => line.trim() !== '');
@@ -28,9 +28,7 @@ function getLines(text: string = '') {
2828
return lines;
2929
}
3030

31-
export function formatFileTreeItemsFromText(
32-
text: string = ''
33-
): IFileTreeItem[] {
31+
export function formatFileTreeItemsFromText(text = ''): IFileTreeItem[] {
3432
const lines = getLines(text);
3533

3634
// find common hash
@@ -49,16 +47,16 @@ export function formatFileTreeItemsFromText(
4947
let item: IFileTreeItem;
5048
// symbol
5149
let symbol = matched[0];
52-
let name = line.slice(symbol.length).trim();
53-
let hash = symbol.match(/#+/);
50+
const name = line.slice(symbol.length).trim();
51+
const hash = symbol.match(/#+/);
5452
let left = 0;
5553
// if contains hash, read hash as its depth symbol
5654
if (hash) {
5755
left = symbol.length - hash[0].length;
5856
symbol = hash[0];
5957
}
6058
let depth = symbol.length;
61-
let prev = list[index - 1];
59+
const prev = list[index - 1];
6260
if (depth === 0) {
6361
depth = 1;
6462
}
@@ -86,7 +84,7 @@ export function formatFileTreeItemsFromText(
8684
prev.isLast = true;
8785
let siblingIndex = index - 1;
8886
let sibling = list[siblingIndex];
89-
let lastMap: any = {};
87+
const lastMap: any = {};
9088
while (siblingIndex >= 0 && sibling.depth !== depth) {
9189
// make sure the previous lines are properly set 'isLast'
9290
if (sibling.depth > depth && !lastMap[sibling.depth]) {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import * as assert from 'assert';
4-
import { revertTreeString } from '../utils';
4+
import { revertTreeString } from '../../utils';
55

66
// Defines a Mocha test suite to group tests of similar kind together
77
suite('Extension Tests', function () {
@@ -14,11 +14,11 @@ suite('Extension Tests', function () {
1414
// });
1515
test('revert tree string to text', function () {
1616
const rootText = fs.readFileSync(
17-
path.join(__dirname, '../../fixtures/root.txt'),
17+
path.join(__dirname, '../../../fixtures/root.txt'),
1818
'utf8'
1919
);
2020
const rootReverted = fs.readFileSync(
21-
path.join(__dirname, '../../fixtures/root-reverted.txt'),
21+
path.join(__dirname, '../../../fixtures/root-reverted.txt'),
2222
'utf8'
2323
);
2424
const reverted = revertTreeString(rootText);
@@ -35,11 +35,11 @@ suite('Extension Tests', function () {
3535
// https://github.com/aprilandjan/ascii-tree-generator/pull/11
3636
test('revert more-depth tree string to text', function () {
3737
const origin = fs.readFileSync(
38-
path.join(__dirname, '../../fixtures/more-depth-reverted.txt'),
38+
path.join(__dirname, '../../../fixtures/more-depth-reverted.txt'),
3939
'utf8'
4040
);
4141
const treeString = fs.readFileSync(
42-
path.join(__dirname, '../../fixtures/more-depth.txt'),
42+
path.join(__dirname, '../../../fixtures/more-depth.txt'),
4343
'utf8'
4444
);
4545
const reverted = revertTreeString(treeString);

src/test/suite/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export function run(): Promise<void> {
66
// Create the mocha test
77
const mocha = new Mocha({
88
ui: 'tdd',
9+
color: true,
910
});
1011

1112
const testsRoot = path.resolve(__dirname, '..');
@@ -29,6 +30,7 @@ export function run(): Promise<void> {
2930
}
3031
});
3132
} catch (err) {
33+
console.error(err);
3234
e(err);
3335
}
3436
});

src/test/suite/lib/directory.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function findFileByName(files: IFileStat[] = [], name: string) {
2222
suite('lib/directory functions', function () {
2323
this.timeout(120000);
2424

25-
const rootDir: string = path.resolve(__dirname, '../../../fixtures/root');
25+
const rootDir: string = path.resolve(__dirname, '../../../../fixtures/root');
2626

2727
test('should correctly list directory', async () => {
2828
const files = await listDirectory(rootDir);

src/test/suite/lib/generator.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ suite('lib/generator functions', function () {
1111
this.timeout(120000);
1212
// Enable test mode to override user defined chars with defaults
1313
setTestMode();
14-
const rootDir: string = path.resolve(__dirname, '../../../fixtures/root');
14+
const rootDir: string = path.resolve(__dirname, '../../../../fixtures/root');
1515
const rootText = fs.readFileSync(
16-
path.join(__dirname, '../../../fixtures/root.txt'),
16+
path.join(__dirname, '../../../../fixtures/root.txt'),
1717
'utf8'
1818
);
1919
const rootSorted = fs.readFileSync(
20-
path.join(__dirname, '../../../fixtures/root-sorted.txt'),
20+
path.join(__dirname, '../../../../fixtures/root-sorted.txt'),
2121
'utf8'
2222
);
2323
const rootFillLeft = fs.readFileSync(
24-
path.join(__dirname, '../../../fixtures/root-fill-left.txt'),
24+
path.join(__dirname, '../../../../fixtures/root-fill-left.txt'),
2525
'utf8'
2626
);
2727

@@ -36,7 +36,7 @@ suite('lib/generator functions', function () {
3636

3737
test('should correctly generate tree from hash text', () => {
3838
const text = fs.readFileSync(
39-
path.join(__dirname, '../../../fixtures/hash.txt'),
39+
path.join(__dirname, '../../../../fixtures/hash.txt'),
4040
'utf8'
4141
);
4242
const items = formatFileTreeItemsFromText(text);
@@ -46,7 +46,7 @@ suite('lib/generator functions', function () {
4646

4747
test('should correctly generate tree from indent text', () => {
4848
const text = fs.readFileSync(
49-
path.join(__dirname, '../../../fixtures/indent.txt'),
49+
path.join(__dirname, '../../../../fixtures/indent.txt'),
5050
'utf8'
5151
);
5252
const items = formatFileTreeItemsFromText(text);
@@ -56,7 +56,7 @@ suite('lib/generator functions', function () {
5656

5757
test('should correctly generate tree from hash-indented text if fill-left', () => {
5858
const text = fs.readFileSync(
59-
path.join(__dirname, '../../../fixtures/hash-indented.txt'),
59+
path.join(__dirname, '../../../../fixtures/hash-indented.txt'),
6060
'utf8'
6161
);
6262
const items = formatFileTreeItemsFromText(text);
@@ -66,7 +66,7 @@ suite('lib/generator functions', function () {
6666

6767
test('should correctly generate tree from hash-indented text if not fill-left', () => {
6868
const text = fs.readFileSync(
69-
path.join(__dirname, '../../../fixtures/hash-indented.txt'),
69+
path.join(__dirname, '../../../../fixtures/hash-indented.txt'),
7070
'utf8'
7171
);
7272
const items = formatFileTreeItemsFromText(text);

0 commit comments

Comments
 (0)