Skip to content

Commit

Permalink
Merge pull request #108 from docsbydoxdox/hotfix/tests
Browse files Browse the repository at this point in the history
[hotfix] Added more utility tests
  • Loading branch information
neogeek authored Jan 28, 2022
2 parents 7274cba + 75a86f0 commit ecf4094
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"./packages/doxdox"
],
"scripts": {
"test": "npm run test --workspaces --if-present",
"test": "DEBUG=true npm run test --workspaces --if-present",
"build": "npm run build --workspaces --if-present",
"prettier-check": "npx prettier@2 --check \"packages/**/*.ts\"",
"prettier-fix": "npx prettier@2 --write \"packages/**/*.ts\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
Expand Down
102 changes: 78 additions & 24 deletions packages/doxdox-core/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import { join } from 'path';

import {
findFileInPath,
getRootDirPath,
findParentNodeModules,
getIgnoreConfigInPath,
getProjectPackage,
getRootDirPath,
isDirectory,
isFile,
parseIgnoreConfig,
slugify,
getProjectPackage
sanitizePath,
slugify
} from './utils';

describe('utils', () => {
Expand Down Expand Up @@ -38,6 +42,21 @@ describe('utils', () => {
});
});

describe('findParentNodeModules', () => {
it('find node_modules with input directory', async () => {
assert.equal(
await findParentNodeModules('./'),
join(process.cwd(), '../../node_modules')
);
});
it('fail to find node_modules with input directory with depth of 1', async () => {
assert.notEqual(
await findParentNodeModules('./', 1),
join(process.cwd(), '../../node_modules')
);
});
});

describe('getIgnoreConfigInPath', () => {
it('find ignore config with input directory', async () => {
assert.deepEqual(await getIgnoreConfigInPath('./'), [
Expand Down Expand Up @@ -67,6 +86,54 @@ describe('utils', () => {
});
});

describe('getProjectPackage', () => {
it('gets contents from project package', async () => {
const { name, description, version, exports } = JSON.parse(
await fs.readFile('./package.json', 'utf8')
);

assert.deepEqual(await getProjectPackage('./'), {
name,
description,
version,
exports
});
});
it('file to get contents from folder without package file', async () => {
assert.deepEqual(await getProjectPackage('./src/'), {});
});
});

describe('getRootDirPath', () => {
it('get dir path', () => {
assert.equal(getRootDirPath(), join(process.cwd(), './src'));
});
});

describe('isDirectory', () => {
it('return true with directory input', async () => {
assert.equal(await isDirectory('./'), true);
});
it('return false with file input', async () => {
assert.equal(await isDirectory('./package.json'), false);
});
it('return false with invalid input', async () => {
assert.equal(await isDirectory('./invalid.txt'), false);
});
});

describe('isFile', () => {
it('return true with file input', async () => {
assert.equal(await isFile('./package.json'), true);
});
it('return false with directory input', async () => {
assert.equal(await isFile('./'), false);
});
it('return false with invalid input', async () => {
assert.equal(await isFile('./invalid.txt'), false);
});
});

describe('parseIgnoreConfig', () => {
it('parse ignore config', () => {
assert.deepEqual(
Expand Down Expand Up @@ -101,9 +168,14 @@ describe('utils', () => {
});
});

describe('getRootDirPath', () => {
it('get dir path', () => {
assert.equal(getRootDirPath(), join(process.cwd(), './src'));
describe('sanitizePath', () => {
it('sanitize path', () => {
assert.equal(
sanitizePath(
'file:///Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
),
'/Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
);
});
});

Expand All @@ -112,22 +184,4 @@ describe('utils', () => {
assert.equal(slugify('./src/utils.ts'), 'src-utils-ts');
});
});

describe('getProjectPackage', () => {
it('gets contents from project package', async () => {
const { name, description, version, exports } = JSON.parse(
await fs.readFile('./package.json', 'utf8')
);

assert.deepEqual(await getProjectPackage('./'), {
name,
description,
version,
exports
});
});
it('file to get contents from folder without package file', async () => {
assert.deepEqual(await getProjectPackage('./src/'), {});
});
});
});
2 changes: 1 addition & 1 deletion packages/doxdox-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-parser-jsdoc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-parser-template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-renderer-bootstrap/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-renderer-dash/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-renderer-github-wiki/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-renderer-json/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-renderer-markdown/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox-renderer-template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/doxdox/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "ES2020",
"module": "es2020",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,
Expand Down

0 comments on commit ecf4094

Please sign in to comment.