Skip to content

Commit a6b7561

Browse files
committed
Added new tests.
1 parent 35e833a commit a6b7561

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

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

Lines changed: 57 additions & 3 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('./'), [
@@ -91,6 +110,30 @@ describe('utils', () => {
91110
});
92111
});
93112

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+
94137
describe('parseIgnoreConfig', () => {
95138
it('parse ignore config', () => {
96139
assert.deepEqual(
@@ -125,6 +168,17 @@ describe('utils', () => {
125168
});
126169
});
127170

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+
);
179+
});
180+
});
181+
128182
describe('slugify', () => {
129183
it('slugify path', () => {
130184
assert.equal(slugify('./src/utils.ts'), 'src-utils-ts');

0 commit comments

Comments
 (0)