Skip to content

Commit ecf4094

Browse files
authored
Merge pull request #108 from docsbydoxdox/hotfix/tests
[hotfix] Added more utility tests
2 parents 7274cba + 75a86f0 commit ecf4094

File tree

13 files changed

+90
-36
lines changed

13 files changed

+90
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"./packages/doxdox"
1616
],
1717
"scripts": {
18-
"test": "npm run test --workspaces --if-present",
18+
"test": "DEBUG=true npm run test --workspaces --if-present",
1919
"build": "npm run build --workspaces --if-present",
2020
"prettier-check": "npx prettier@2 --check \"packages/**/*.ts\"",
2121
"prettier-fix": "npx prettier@2 --write \"packages/**/*.ts\"",

packages/doxdox-cli/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"resolveJsonModule": true,

packages/doxdox-core/src/utils.test.ts

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import { join } from 'path';
66

77
import {
88
findFileInPath,
9-
getRootDirPath,
9+
findParentNodeModules,
1010
getIgnoreConfigInPath,
11+
getProjectPackage,
12+
getRootDirPath,
13+
isDirectory,
14+
isFile,
1115
parseIgnoreConfig,
12-
slugify,
13-
getProjectPackage
16+
sanitizePath,
17+
slugify
1418
} from './utils';
1519

1620
describe('utils', () => {
@@ -38,6 +42,21 @@ describe('utils', () => {
3842
});
3943
});
4044

45+
describe('findParentNodeModules', () => {
46+
it('find node_modules with input directory', async () => {
47+
assert.equal(
48+
await findParentNodeModules('./'),
49+
join(process.cwd(), '../../node_modules')
50+
);
51+
});
52+
it('fail to find node_modules with input directory with depth of 1', async () => {
53+
assert.notEqual(
54+
await findParentNodeModules('./', 1),
55+
join(process.cwd(), '../../node_modules')
56+
);
57+
});
58+
});
59+
4160
describe('getIgnoreConfigInPath', () => {
4261
it('find ignore config with input directory', async () => {
4362
assert.deepEqual(await getIgnoreConfigInPath('./'), [
@@ -67,6 +86,54 @@ describe('utils', () => {
6786
});
6887
});
6988

89+
describe('getProjectPackage', () => {
90+
it('gets contents from project package', async () => {
91+
const { name, description, version, exports } = JSON.parse(
92+
await fs.readFile('./package.json', 'utf8')
93+
);
94+
95+
assert.deepEqual(await getProjectPackage('./'), {
96+
name,
97+
description,
98+
version,
99+
exports
100+
});
101+
});
102+
it('file to get contents from folder without package file', async () => {
103+
assert.deepEqual(await getProjectPackage('./src/'), {});
104+
});
105+
});
106+
107+
describe('getRootDirPath', () => {
108+
it('get dir path', () => {
109+
assert.equal(getRootDirPath(), join(process.cwd(), './src'));
110+
});
111+
});
112+
113+
describe('isDirectory', () => {
114+
it('return true with directory input', async () => {
115+
assert.equal(await isDirectory('./'), true);
116+
});
117+
it('return false with file input', async () => {
118+
assert.equal(await isDirectory('./package.json'), false);
119+
});
120+
it('return false with invalid input', async () => {
121+
assert.equal(await isDirectory('./invalid.txt'), false);
122+
});
123+
});
124+
125+
describe('isFile', () => {
126+
it('return true with file input', async () => {
127+
assert.equal(await isFile('./package.json'), true);
128+
});
129+
it('return false with directory input', async () => {
130+
assert.equal(await isFile('./'), false);
131+
});
132+
it('return false with invalid input', async () => {
133+
assert.equal(await isFile('./invalid.txt'), false);
134+
});
135+
});
136+
70137
describe('parseIgnoreConfig', () => {
71138
it('parse ignore config', () => {
72139
assert.deepEqual(
@@ -101,9 +168,14 @@ describe('utils', () => {
101168
});
102169
});
103170

104-
describe('getRootDirPath', () => {
105-
it('get dir path', () => {
106-
assert.equal(getRootDirPath(), join(process.cwd(), './src'));
171+
describe('sanitizePath', () => {
172+
it('sanitize path', () => {
173+
assert.equal(
174+
sanitizePath(
175+
'file:///Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
176+
),
177+
'/Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
178+
);
107179
});
108180
});
109181

@@ -112,22 +184,4 @@ describe('utils', () => {
112184
assert.equal(slugify('./src/utils.ts'), 'src-utils-ts');
113185
});
114186
});
115-
116-
describe('getProjectPackage', () => {
117-
it('gets contents from project package', async () => {
118-
const { name, description, version, exports } = JSON.parse(
119-
await fs.readFile('./package.json', 'utf8')
120-
);
121-
122-
assert.deepEqual(await getProjectPackage('./'), {
123-
name,
124-
description,
125-
version,
126-
exports
127-
});
128-
});
129-
it('file to get contents from folder without package file', async () => {
130-
assert.deepEqual(await getProjectPackage('./src/'), {});
131-
});
132-
});
133187
});

packages/doxdox-core/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-parser-jsdoc/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-parser-template/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-renderer-bootstrap/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-renderer-dash/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-renderer-github-wiki/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-renderer-json/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-renderer-markdown/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox-renderer-template/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

packages/doxdox/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"module": "ES2020",
4+
"module": "es2020",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
77
"declaration": true,

0 commit comments

Comments
 (0)