Skip to content

Commit c6bf13d

Browse files
committed
test: Even more tests
1 parent e02b91f commit c6bf13d

File tree

2 files changed

+264
-0
lines changed

2 files changed

+264
-0
lines changed

__tests__/__snapshots__/index.js.snap

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`build 1`] = `
4+
Array [
5+
Object {
6+
"augments": Array [],
7+
"description": Object {
8+
"children": Array [
9+
Object {
10+
"children": Array [
11+
Object {
12+
"position": Position {
13+
"end": Object {
14+
"column": 3,
15+
"line": 1,
16+
"offset": 2,
17+
},
18+
"indent": Array [],
19+
"start": Object {
20+
"column": 1,
21+
"line": 1,
22+
"offset": 0,
23+
},
24+
},
25+
"type": "text",
26+
"value": "hi",
27+
},
28+
],
29+
"position": Position {
30+
"end": Object {
31+
"column": 3,
32+
"line": 1,
33+
"offset": 2,
34+
},
35+
"indent": Array [],
36+
"start": Object {
37+
"column": 1,
38+
"line": 1,
39+
"offset": 0,
40+
},
41+
},
42+
"type": "paragraph",
43+
},
44+
],
45+
"position": Object {
46+
"end": Object {
47+
"column": 3,
48+
"line": 1,
49+
"offset": 2,
50+
},
51+
"start": Object {
52+
"column": 1,
53+
"line": 1,
54+
"offset": 0,
55+
},
56+
},
57+
"type": "root",
58+
},
59+
"errors": Array [],
60+
"examples": Array [],
61+
"loc": SourceLocation {
62+
"end": Position {
63+
"column": 9,
64+
"line": 1,
65+
},
66+
"start": Position {
67+
"column": 0,
68+
"line": 1,
69+
},
70+
},
71+
"members": Object {
72+
"events": Array [],
73+
"global": Array [],
74+
"inner": Array [],
75+
"instance": Array [],
76+
"static": Array [],
77+
},
78+
"name": "name",
79+
"namespace": "name",
80+
"params": Array [],
81+
"path": Array [
82+
Object {
83+
"kind": undefined,
84+
"name": "name",
85+
},
86+
],
87+
"properties": Array [],
88+
"returns": Array [],
89+
"sees": Array [],
90+
"tags": Array [],
91+
"throws": Array [],
92+
"todos": Array [],
93+
},
94+
]
95+
`;
96+
97+
exports[`build 2`] = `
98+
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
99+
100+
## name
101+
102+
hi
103+
"
104+
`;
105+
106+
exports[`build 3`] = `
107+
"[
108+
{
109+
\\"description\\": {
110+
\\"type\\": \\"root\\",
111+
\\"children\\": [
112+
{
113+
\\"type\\": \\"paragraph\\",
114+
\\"children\\": [
115+
{
116+
\\"type\\": \\"text\\",
117+
\\"value\\": \\"hi\\",
118+
\\"position\\": {
119+
\\"start\\": {
120+
\\"line\\": 1,
121+
\\"column\\": 1,
122+
\\"offset\\": 0
123+
},
124+
\\"end\\": {
125+
\\"line\\": 1,
126+
\\"column\\": 3,
127+
\\"offset\\": 2
128+
},
129+
\\"indent\\": []
130+
}
131+
}
132+
],
133+
\\"position\\": {
134+
\\"start\\": {
135+
\\"line\\": 1,
136+
\\"column\\": 1,
137+
\\"offset\\": 0
138+
},
139+
\\"end\\": {
140+
\\"line\\": 1,
141+
\\"column\\": 3,
142+
\\"offset\\": 2
143+
},
144+
\\"indent\\": []
145+
}
146+
}
147+
],
148+
\\"position\\": {
149+
\\"start\\": {
150+
\\"line\\": 1,
151+
\\"column\\": 1,
152+
\\"offset\\": 0
153+
},
154+
\\"end\\": {
155+
\\"line\\": 1,
156+
\\"column\\": 3,
157+
\\"offset\\": 2
158+
}
159+
}
160+
},
161+
\\"tags\\": [],
162+
\\"loc\\": {
163+
\\"start\\": {
164+
\\"line\\": 1,
165+
\\"column\\": 0
166+
},
167+
\\"end\\": {
168+
\\"line\\": 1,
169+
\\"column\\": 9
170+
}
171+
},
172+
\\"augments\\": [],
173+
\\"examples\\": [],
174+
\\"params\\": [],
175+
\\"properties\\": [],
176+
\\"returns\\": [],
177+
\\"sees\\": [],
178+
\\"throws\\": [],
179+
\\"todos\\": [],
180+
\\"name\\": \\"name\\",
181+
\\"members\\": {
182+
\\"global\\": [],
183+
\\"inner\\": [],
184+
\\"instance\\": [],
185+
\\"events\\": [],
186+
\\"static\\": []
187+
},
188+
\\"path\\": [
189+
{
190+
\\"name\\": \\"name\\"
191+
}
192+
],
193+
\\"namespace\\": \\"name\\"
194+
}
195+
]"
196+
`;

__tests__/index.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
var documentation = require('../src/');
2+
var os = require('os');
3+
var path = require('path');
4+
var fs = require('fs');
5+
6+
function inputs(contents) {
7+
var dirEntry = os.tmpdir();
8+
var paths = {};
9+
for (var filename in contents) {
10+
paths[filename] = path.join(dirEntry, '/', filename);
11+
fs.writeFileSync(paths[filename], contents[filename]);
12+
}
13+
return {
14+
paths
15+
};
16+
}
17+
18+
function cleanup(comments) {
19+
comments.forEach(c => {
20+
delete c.context;
21+
});
22+
}
23+
24+
test('lint', async function() {
25+
var { paths } = inputs({
26+
'index.js': '/** hi */var name = 1;'
27+
});
28+
29+
const data = await documentation.lint([paths['index.js']], {});
30+
expect(data).toEqual('');
31+
});
32+
33+
test('build', async function() {
34+
var { paths } = inputs({
35+
'index.js': '/** hi */var name = 1;'
36+
});
37+
38+
const data = await documentation.build([paths['index.js']], {});
39+
cleanup(data);
40+
expect(data).toMatchSnapshot();
41+
42+
const md = await documentation.formats.md(data);
43+
expect(md).toMatchSnapshot();
44+
45+
const json = await documentation.formats.json(data, {});
46+
expect(json).toMatchSnapshot();
47+
});
48+
49+
test('expandInputs', async function() {
50+
var { paths } = inputs({
51+
'index.js': '/** hi */var name = 1;'
52+
});
53+
54+
{
55+
const data = await documentation.expandInputs([paths['index.js']], {
56+
parseExtension: ['js']
57+
});
58+
expect(data.length).toEqual(1);
59+
}
60+
61+
{
62+
const data = await documentation.expandInputs([paths['index.js']], {
63+
parseExtension: ['js'],
64+
shallow: true
65+
});
66+
expect(data.length).toEqual(1);
67+
}
68+
});

0 commit comments

Comments
 (0)