Skip to content

Commit c8d3c59

Browse files
committed
Switched to using snapshots in dox parser package.
1 parent e128113 commit c8d3c59

File tree

7 files changed

+272
-87
lines changed

7 files changed

+272
-87
lines changed

packages/doxdox-parser-dox/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ coverage/
22

33
src/
44

5+
test/
6+
57
.eslintrc
68

79
.prettierignore
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`dox parser parse empty string 1`] = `
4+
{
5+
"methods": [],
6+
"path": "./test/mocks/empty.js",
7+
}
8+
`;
9+
10+
exports[`dox parser parse example jsdoc headers (declaration methods) 1`] = `
11+
{
12+
"methods": [
13+
{
14+
"description": "Finds file in path.
15+
16+
console.log(await findFileInPath('./', 'package.json'));
17+
console.log(await findFileInPath('../', 'package.json'));
18+
console.log(await findFileInPath('~/git/github/doxdox/', '.package.json'));",
19+
"fullName": "findFileInPath(input, fileName)",
20+
"name": "findFileInPath",
21+
"params": [
22+
{
23+
"description": "Directory to check for file.",
24+
"name": "input",
25+
"types": [
26+
"string",
27+
],
28+
},
29+
{
30+
"description": "= 'package.json'] File name to check for.",
31+
"name": "fileName",
32+
"types": [
33+
"string",
34+
],
35+
},
36+
],
37+
"private": false,
38+
"returns": [
39+
{
40+
"description": "Path to package.json file.",
41+
"name": null,
42+
"types": [
43+
"Promise.<string|null>",
44+
],
45+
},
46+
],
47+
"slug": "test-mocks-declaration-js-findfileinpath",
48+
"type": "declaration",
49+
},
50+
{
51+
"description": "Get the current working directory.",
52+
"fullName": "getCurrentWorkingDirectory()",
53+
"name": "getCurrentWorkingDirectory",
54+
"params": [],
55+
"private": false,
56+
"returns": [
57+
{
58+
"description": "Directory path.",
59+
"name": null,
60+
"types": [
61+
"string",
62+
],
63+
},
64+
],
65+
"slug": "test-mocks-declaration-js-getcurrentworkingdirectory",
66+
"type": "declaration",
67+
},
68+
{
69+
"description": "Get the root directory of the package, supplied path or URL.",
70+
"fullName": "getRootDirPath(url)",
71+
"name": "getRootDirPath",
72+
"params": [
73+
{
74+
"description": "Optional path or URL.",
75+
"name": "url",
76+
"types": [
77+
"string",
78+
],
79+
},
80+
],
81+
"private": false,
82+
"returns": [
83+
{
84+
"description": "Directory path.",
85+
"name": null,
86+
"types": [
87+
"string",
88+
],
89+
},
90+
],
91+
"slug": "test-mocks-declaration-js-getrootdirpath",
92+
"type": "declaration",
93+
},
94+
],
95+
"path": "./test/mocks/declaration.js",
96+
}
97+
`;
98+
99+
exports[`dox parser parse example jsdoc headers (function methods) 1`] = `
100+
{
101+
"methods": [
102+
{
103+
"description": "Finds file in path.
104+
105+
console.log(await findFileInPath('./', 'package.json'));
106+
console.log(await findFileInPath('../', 'package.json'));
107+
console.log(await findFileInPath('~/git/github/doxdox/', '.package.json'));",
108+
"fullName": "findFileInPath(input, fileName)",
109+
"name": "findFileInPath",
110+
"params": [
111+
{
112+
"description": "Directory to check for file.",
113+
"name": "input",
114+
"types": [
115+
"string",
116+
],
117+
},
118+
{
119+
"description": "= 'package.json'] File name to check for.",
120+
"name": "fileName",
121+
"types": [
122+
"string",
123+
],
124+
},
125+
],
126+
"private": false,
127+
"returns": [
128+
{
129+
"description": "Path to package.json file.",
130+
"name": null,
131+
"types": [
132+
"Promise.<string|null>",
133+
],
134+
},
135+
],
136+
"slug": "test-mocks-declaration-js-findfileinpath",
137+
"type": "declaration",
138+
},
139+
{
140+
"description": "Get the current working directory.",
141+
"fullName": "getCurrentWorkingDirectory()",
142+
"name": "getCurrentWorkingDirectory",
143+
"params": [],
144+
"private": false,
145+
"returns": [
146+
{
147+
"description": "Directory path.",
148+
"name": null,
149+
"types": [
150+
"string",
151+
],
152+
},
153+
],
154+
"slug": "test-mocks-declaration-js-getcurrentworkingdirectory",
155+
"type": "declaration",
156+
},
157+
{
158+
"description": "Get the root directory of the package, supplied path or URL.",
159+
"fullName": "getRootDirPath(url)",
160+
"name": "getRootDirPath",
161+
"params": [
162+
{
163+
"description": "Optional path or URL.",
164+
"name": "url",
165+
"types": [
166+
"string",
167+
],
168+
},
169+
],
170+
"private": false,
171+
"returns": [
172+
{
173+
"description": "Directory path.",
174+
"name": null,
175+
"types": [
176+
"string",
177+
],
178+
},
179+
],
180+
"slug": "test-mocks-declaration-js-getrootdirpath",
181+
"type": "declaration",
182+
},
183+
],
184+
"path": "./test/mocks/declaration.js",
185+
}
186+
`;
Lines changed: 12 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,19 @@
1-
import { parseString } from './index';
1+
import parse from './index';
22

33
describe('dox parser', () => {
4-
it('parse example jsdoc headers', async () => {
4+
it('parse example jsdoc headers (declaration methods)', async () => {
55
await expect(
6-
parseString(
7-
'lib/utils/index.js',
8-
`/**
9-
* Finds file in path.
10-
*
11-
* console.log(await findFileInPath('./', 'package.json'));
12-
* console.log(await findFileInPath('../', 'package.json'));
13-
* console.log(await findFileInPath('~/git/github/doxdox/', '.package.json'));
14-
*
15-
* @param {string} [input] Directory to check for file.
16-
* @param {string?} [fileName = 'package.json'] File name to check for.
17-
* @return {Promise<string | null>} Path to package.json file.
18-
* @public
19-
*/
20-
21-
const findFileInPath = async (input, fileName = 'package.json') => {};
22-
23-
/**
24-
* Get the root directory of the package, supplied path or URL.
25-
*
26-
* @param {string?} [url] Optional path or URL.
27-
* @return {string} Directory path.
28-
* @public
29-
*/
30-
31-
const getRootDirPath = (url) => {};`
32-
)
33-
).resolves.toEqual(
34-
expect.objectContaining({
35-
path: 'lib/utils/index.js',
36-
methods: expect.arrayContaining([
37-
expect.objectContaining({
38-
type: 'declaration',
39-
fullName: 'findFileInPath(input, fileName)',
40-
name: 'findFileInPath',
41-
params: expect.arrayContaining([
42-
expect.objectContaining({
43-
name: 'input',
44-
types: ['string']
45-
}),
46-
expect.objectContaining({
47-
name: 'fileName',
48-
types: ['string']
49-
})
50-
]),
51-
private: false,
52-
returns: expect.arrayContaining([
53-
expect.objectContaining({
54-
name: null,
55-
description: 'Path to package.json file.',
56-
types: ['Promise.<string|null>']
57-
})
58-
]),
59-
slug: 'lib-utils-index-js-findfileinpath'
60-
}),
61-
expect.objectContaining({
62-
type: 'declaration',
63-
fullName: 'getRootDirPath(url)',
64-
name: 'getRootDirPath',
65-
params: expect.arrayContaining([
66-
expect.objectContaining({
67-
name: 'url',
68-
types: ['string']
69-
})
70-
]),
71-
private: false,
72-
returns: expect.arrayContaining([
73-
expect.objectContaining({
74-
name: null,
75-
description: 'Directory path.',
76-
types: ['string']
77-
})
78-
]),
79-
slug: 'lib-utils-index-js-getrootdirpath'
80-
})
81-
])
82-
})
83-
);
6+
parse(process.cwd(), './test/mocks/declaration.js')
7+
).resolves.toMatchSnapshot();
8+
});
9+
it('parse example jsdoc headers (function methods)', async () => {
10+
await expect(
11+
parse(process.cwd(), './test/mocks/declaration.js')
12+
).resolves.toMatchSnapshot();
8413
});
8514
it('parse empty string', async () => {
86-
await expect(parseString('test.js', '')).resolves.toEqual(
87-
expect.objectContaining({
88-
path: 'test.js',
89-
methods: []
90-
})
91-
);
15+
await expect(
16+
parse(process.cwd(), './test/mocks/empty.js')
17+
).resolves.toMatchSnapshot();
9218
});
9319
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* eslint-disable */
2+
3+
/**
4+
* Finds file in path.
5+
*
6+
* console.log(await findFileInPath('./', 'package.json'));
7+
* console.log(await findFileInPath('../', 'package.json'));
8+
* console.log(await findFileInPath('~/git/github/doxdox/', '.package.json'));
9+
*
10+
* @param {string} [input] Directory to check for file.
11+
* @param {string?} [fileName = 'package.json'] File name to check for.
12+
* @return {Promise<string | null>} Path to package.json file.
13+
* @public
14+
*/
15+
16+
const findFileInPath = async (input, fileName = 'package.json') => {};
17+
18+
/**
19+
* Get the root directory of the package, supplied path or URL.
20+
*
21+
* @param {string?} [url] Optional path or URL.
22+
* @return {string} Directory path.
23+
* @public
24+
*/
25+
26+
const getRootDirPath = url => {};
27+
28+
/**
29+
* Get the current working directory.
30+
*
31+
* @return {string} Directory path.
32+
* @public
33+
*/
34+
35+
const getCurrentWorkingDirectory = () => {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* eslint-disable */
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* eslint-disable */
2+
3+
/**
4+
* Finds file in path.
5+
*
6+
* console.log(await findFileInPath('./', 'package.json'));
7+
* console.log(await findFileInPath('../', 'package.json'));
8+
* console.log(await findFileInPath('~/git/github/doxdox/', '.package.json'));
9+
*
10+
* @param {string} [input] Directory to check for file.
11+
* @param {string?} [fileName = 'package.json'] File name to check for.
12+
* @return {Promise<string | null>} Path to package.json file.
13+
* @public
14+
*/
15+
16+
async function findFileInPath(input, fileName = 'package.json') {}
17+
18+
/**
19+
* Get the root directory of the package, supplied path or URL.
20+
*
21+
* @param {string?} [url] Optional path or URL.
22+
* @return {string} Directory path.
23+
* @public
24+
*/
25+
26+
function getRootDirPath(url) {}
27+
28+
/**
29+
* Get the current working directory.
30+
*
31+
* @return {string} Directory path.
32+
* @public
33+
*/
34+
35+
function getCurrentWorkingDirectory() {}

packages/doxdox-parser-dox/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"strict": true
1010
},
1111
"include": ["./src", "./src/.d.ts"],
12-
"exclude": ["./dist", "**/*.test.ts"]
12+
"exclude": ["./dist", "**/*.test.ts", "test/mocks/**/*.js"]
1313
}

0 commit comments

Comments
 (0)