Skip to content

Commit dff6049

Browse files
authored
Merge pull request #193 from docsbydoxdox/hotfix/use-snapshots-in-dox-parser
[hotfix] Switched to using snapshots in dox parser package.
2 parents e128113 + ea6c655 commit dff6049

File tree

7 files changed

+236
-88
lines changed

7 files changed

+236
-88
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: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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": "Get the current working directory.",
104+
"fullName": "getCurrentWorkingDirectory()()",
105+
"name": "getCurrentWorkingDirectory()",
106+
"params": [],
107+
"private": false,
108+
"returns": [
109+
{
110+
"description": "Directory path.",
111+
"name": null,
112+
"types": [
113+
"string",
114+
],
115+
},
116+
],
117+
"slug": "test-mocks-function-js-getcurrentworkingdirectory",
118+
"type": "function",
119+
},
120+
{
121+
"description": "Get the root directory of the package, supplied path or URL.",
122+
"fullName": "getRootDirPath()(url)",
123+
"name": "getRootDirPath()",
124+
"params": [
125+
{
126+
"description": "Optional path or URL.",
127+
"name": "url",
128+
"types": [
129+
"string",
130+
],
131+
},
132+
],
133+
"private": false,
134+
"returns": [
135+
{
136+
"description": "Directory path.",
137+
"name": null,
138+
"types": [
139+
"string",
140+
],
141+
},
142+
],
143+
"slug": "test-mocks-function-js-getrootdirpath",
144+
"type": "function",
145+
},
146+
],
147+
"path": "./test/mocks/function.js",
148+
}
149+
`;
Lines changed: 13 additions & 87 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();
848
});
85-
it('parse empty string', async () => {
86-
await expect(parseString('test.js', '')).resolves.toEqual(
87-
expect.objectContaining({
88-
path: 'test.js',
89-
methods: []
90-
})
91-
);
9+
it('parse example jsdoc headers (function methods)', async () => {
10+
await expect(
11+
parse(process.cwd(), './test/mocks/function.js')
12+
).resolves.toMatchSnapshot();
13+
});
14+
it('parse empty file', async () => {
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)