Skip to content

Commit 1b338e2

Browse files
authored
Merge pull request #127 from docsbydoxdox/hotfix/use-jest-expect
[hotfix] Switched to using jest expect for tests.
2 parents 97daa5e + 66f6f74 commit 1b338e2

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed
Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import assert from 'assert';
2-
31
import { promises as fs } from 'fs';
42

53
import { join } from 'path';
@@ -19,40 +17,34 @@ import {
1917
describe('utils', () => {
2018
describe('findFileInPath', () => {
2119
it('find package with input directory', async () => {
22-
assert.equal(
23-
await findFileInPath('./'),
20+
expect(await findFileInPath('./')).toEqual(
2421
join(process.cwd(), './package.json')
2522
);
2623
});
2724

2825
it('find package with input file', async () => {
29-
assert.equal(
30-
await findFileInPath('./package.json'),
26+
expect(await findFileInPath('./package.json')).toEqual(
3127
join(process.cwd(), './package.json')
3228
);
3329
});
3430

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

3935
it('fail to find package with invalid directory', async () => {
40-
assert.equal(await findFileInPath('../testing'), null);
36+
expect(await findFileInPath('../testing')).toBeNull();
4137
});
4238
});
4339

4440
describe('findParentNodeModules', () => {
4541
it('find node_modules with input directory', async () => {
46-
assert.equal(
47-
await findParentNodeModules('./'),
42+
expect(await findParentNodeModules('./')).toEqual(
4843
join(process.cwd(), '../../node_modules')
4944
);
5045
});
5146
it('fail to find node_modules with input directory with depth of 1', async () => {
52-
assert.notEqual(
53-
await findParentNodeModules('./', 1),
54-
join(process.cwd(), '../../node_modules')
55-
);
47+
expect(await findParentNodeModules('./', 1)).toBeNull();
5648
});
5749
});
5850

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

65-
assert.deepEqual(await getProjectPackage('./'), {
66-
name,
67-
description,
68-
version,
69-
exports
70-
});
57+
expect(await getProjectPackage('./')).toEqual(
58+
expect.objectContaining({
59+
name,
60+
description,
61+
version,
62+
exports
63+
})
64+
);
7165
});
7266
it('file to get contents from folder without package file', async () => {
73-
assert.deepEqual(await getProjectPackage('./src/'), {});
67+
expect(await getProjectPackage('./src/')).toEqual({});
7468
});
7569
});
7670

7771
describe('getRootDirPath', () => {
7872
it('get dir path', () => {
79-
assert.equal(getRootDirPath(), join(process.cwd(), './src'));
73+
expect(getRootDirPath()).toEqual(join(process.cwd(), './src'));
8074
});
8175
});
8276

8377
describe('isDirectory', () => {
8478
it('return true with directory input', async () => {
85-
assert.equal(await isDirectory('./'), true);
79+
expect(await isDirectory('./')).toBeTruthy();
8680
});
8781
it('return false with file input', async () => {
88-
assert.equal(await isDirectory('./package.json'), false);
82+
expect(await isDirectory('./package.json')).toBeFalsy();
8983
});
9084
it('return false with invalid input', async () => {
91-
assert.equal(await isDirectory('./invalid.txt'), false);
85+
expect(await isDirectory('./invalid.txt')).toBeFalsy();
9286
});
9387
});
9488

9589
describe('isFile', () => {
9690
it('return true with file input', async () => {
97-
assert.equal(await isFile('./package.json'), true);
91+
expect(await isFile('./package.json')).toBeTruthy();
9892
});
9993
it('return false with directory input', async () => {
100-
assert.equal(await isFile('./'), false);
94+
expect(await isFile('./')).toBeFalsy();
10195
});
10296
it('return false with invalid input', async () => {
103-
assert.equal(await isFile('./invalid.txt'), false);
97+
expect(await isFile('./invalid.txt')).toBeFalsy();
10498
});
10599
});
106100

107101
describe('parseIgnoreConfig', () => {
108102
it('parse ignore config', () => {
109-
assert.deepEqual(
103+
expect(
110104
parseIgnoreConfig(`**/*.test.*
111105
./coverage/
112-
./dist/`),
113-
['!**/*.test.*', '!./coverage/', '!./dist/']
106+
./dist/`)
107+
).toEqual(
108+
expect.arrayContaining([
109+
'!**/*.test.*',
110+
'!./coverage/',
111+
'!./dist/'
112+
])
114113
);
115114
});
116115
it('parse ignore config with empty lines', () => {
117-
assert.deepEqual(
116+
expect(
118117
parseIgnoreConfig(`**/*.test.*
119118
120119
./coverage/
121120
122-
./dist/`),
123-
['!**/*.test.*', '!./coverage/', '!./dist/']
121+
./dist/`)
122+
).toEqual(
123+
expect.arrayContaining([
124+
'!**/*.test.*',
125+
'!./coverage/',
126+
'!./dist/'
127+
])
124128
);
125129
});
126130
it('parse ignore config with ! leading characters', () => {
127-
assert.deepEqual(
131+
expect(
128132
parseIgnoreConfig(`!**/*.test.*
129133
130134
!./coverage/
131135
132-
!./dist/`),
133-
['!**/*.test.*', '!./coverage/', '!./dist/']
136+
!./dist/`)
137+
).toEqual(
138+
expect.arrayContaining([
139+
'!**/*.test.*',
140+
'!./coverage/',
141+
'!./dist/'
142+
])
134143
);
135144
});
136145
it('parse ignore config with empty contents', () => {
137-
assert.deepEqual(parseIgnoreConfig(''), []);
146+
expect(parseIgnoreConfig('')).toEqual([]);
138147
});
139148
});
140149

141150
describe('sanitizePath', () => {
142151
it('sanitize path', () => {
143-
assert.equal(
152+
expect(
144153
sanitizePath(
145154
'file:///Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
146-
),
155+
)
156+
).toEqual(
147157
'/Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
148158
);
149159
});
150160
});
151161

152162
describe('slugify', () => {
153163
it('slugify path', () => {
154-
assert.equal(slugify('./src/utils.ts'), 'src-utils-ts');
164+
expect(slugify('./src/utils.ts')).toEqual('src-utils-ts');
155165
});
156166
});
157167
});

0 commit comments

Comments
 (0)