Skip to content

Commit

Permalink
Merge pull request #127 from docsbydoxdox/hotfix/use-jest-expect
Browse files Browse the repository at this point in the history
[hotfix] Switched to using jest expect for tests.
  • Loading branch information
neogeek authored Feb 8, 2022
2 parents 97daa5e + 66f6f74 commit 1b338e2
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions packages/doxdox-core/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from 'assert';

import { promises as fs } from 'fs';

import { join } from 'path';
Expand All @@ -19,40 +17,34 @@ import {
describe('utils', () => {
describe('findFileInPath', () => {
it('find package with input directory', async () => {
assert.equal(
await findFileInPath('./'),
expect(await findFileInPath('./')).toEqual(
join(process.cwd(), './package.json')
);
});

it('find package with input file', async () => {
assert.equal(
await findFileInPath('./package.json'),
expect(await findFileInPath('./package.json')).toEqual(
join(process.cwd(), './package.json')
);
});

it('fail to find package with input non package.json file', async () => {
assert.equal(await findFileInPath('./jest.config.js'), null);
expect(await findFileInPath('./jest.config.js')).toBeNull();
});

it('fail to find package with invalid directory', async () => {
assert.equal(await findFileInPath('../testing'), null);
expect(await findFileInPath('../testing')).toBeNull();
});
});

describe('findParentNodeModules', () => {
it('find node_modules with input directory', async () => {
assert.equal(
await findParentNodeModules('./'),
expect(await findParentNodeModules('./')).toEqual(
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')
);
expect(await findParentNodeModules('./', 1)).toBeNull();
});
});

Expand All @@ -62,96 +54,114 @@ describe('utils', () => {
await fs.readFile('./package.json', 'utf8')
);

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

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

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

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

describe('parseIgnoreConfig', () => {
it('parse ignore config', () => {
assert.deepEqual(
expect(
parseIgnoreConfig(`**/*.test.*
./coverage/
./dist/`),
['!**/*.test.*', '!./coverage/', '!./dist/']
./dist/`)
).toEqual(
expect.arrayContaining([
'!**/*.test.*',
'!./coverage/',
'!./dist/'
])
);
});
it('parse ignore config with empty lines', () => {
assert.deepEqual(
expect(
parseIgnoreConfig(`**/*.test.*
./coverage/
./dist/`),
['!**/*.test.*', '!./coverage/', '!./dist/']
./dist/`)
).toEqual(
expect.arrayContaining([
'!**/*.test.*',
'!./coverage/',
'!./dist/'
])
);
});
it('parse ignore config with ! leading characters', () => {
assert.deepEqual(
expect(
parseIgnoreConfig(`!**/*.test.*
!./coverage/
!./dist/`),
['!**/*.test.*', '!./coverage/', '!./dist/']
!./dist/`)
).toEqual(
expect.arrayContaining([
'!**/*.test.*',
'!./coverage/',
'!./dist/'
])
);
});
it('parse ignore config with empty contents', () => {
assert.deepEqual(parseIgnoreConfig(''), []);
expect(parseIgnoreConfig('')).toEqual([]);
});
});

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

describe('slugify', () => {
it('slugify path', () => {
assert.equal(slugify('./src/utils.ts'), 'src-utils-ts');
expect(slugify('./src/utils.ts')).toEqual('src-utils-ts');
});
});
});

0 comments on commit 1b338e2

Please sign in to comment.