Skip to content

Commit 77ab15b

Browse files
committed
test(api): update instadoc tests
1 parent 63de726 commit 77ab15b

File tree

10 files changed

+454
-350
lines changed

10 files changed

+454
-350
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"name": "api",
1111
"program": "${workspaceFolder}/node_modules/.bin/jest",
1212
"cwd": "${workspaceFolder}/packages/api",
13-
"args": ["file-callback"],
13+
"args": ["docs-document"],
1414
"console": "integratedTerminal",
1515
"internalConsoleOptions": "neverOpen",
1616
"disableOptimisticBPs": true,
Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
import path from 'path';
2+
import { parseFiles } from '../../../src/index';
3+
4+
describe('docs-document', () => {
5+
it('require-import', () => {
6+
const result = parseFiles(
7+
[path.resolve(__dirname, 'require-import.docs.tsx')],
8+
{
9+
collectSourceInfo: 'body',
10+
collectInnerLocations: true,
11+
collectParametersUsage: true,
12+
collectGenerics: false,
13+
},
14+
);
15+
expect(result).toMatchObject({
16+
default: {
17+
type: 'Document',
18+
kind: 15,
19+
properties: [
20+
{
21+
name: 'name',
22+
kind: 1,
23+
value: 'documentation for MyComponent',
24+
},
25+
{
26+
name: 'subcomponents',
27+
properties: [
28+
{
29+
name: 'MyComponent',
30+
kind: 17,
31+
value: 'MyComponent',
32+
},
33+
],
34+
kind: 15,
35+
type: 'Record',
36+
},
37+
],
38+
name: 'default',
39+
},
40+
});
41+
});
42+
43+
it('export-default', () => {
44+
const result = parseFiles(
45+
[path.resolve(__dirname, 'export-default.docs.tsx')],
46+
{
47+
collectSourceInfo: true,
48+
},
49+
);
50+
expect(result).toMatchObject({
51+
default: {
52+
loc: {
53+
loc: {
54+
start: {
55+
line: 4,
56+
col: 1,
57+
},
58+
end: {
59+
line: 7,
60+
col: 3,
61+
},
62+
},
63+
},
64+
kind: 26,
65+
properties: [
66+
{
67+
name: 'name',
68+
kind: 1,
69+
value: 'documentation for MyComponent',
70+
},
71+
{
72+
name: 'component',
73+
type: 'FC',
74+
kind: 15,
75+
generics: [
76+
{
77+
name: 'MyComponentProps',
78+
},
79+
],
80+
properties: [
81+
{
82+
name: 'propTypes',
83+
parent: {
84+
name: 'FunctionComponent',
85+
},
86+
optional: true,
87+
kind: 4,
88+
properties: [
89+
{
90+
kind: 15,
91+
type: 'WeakValidationMap',
92+
generics: [
93+
{
94+
name: 'T',
95+
},
96+
],
97+
},
98+
{
99+
kind: 8,
100+
},
101+
],
102+
},
103+
{
104+
name: 'contextTypes',
105+
parent: {
106+
name: 'FunctionComponent',
107+
},
108+
optional: true,
109+
kind: 4,
110+
properties: [
111+
{
112+
kind: 15,
113+
type: 'ValidationMap',
114+
generics: [
115+
{
116+
name: 'T',
117+
},
118+
],
119+
},
120+
{
121+
kind: 8,
122+
},
123+
],
124+
},
125+
{
126+
name: 'defaultProps',
127+
parent: {
128+
name: 'FunctionComponent',
129+
},
130+
optional: true,
131+
kind: 4,
132+
properties: [
133+
{
134+
kind: 15,
135+
type: 'Partial',
136+
generics: [
137+
{
138+
type: 'P',
139+
},
140+
],
141+
},
142+
{
143+
kind: 8,
144+
},
145+
],
146+
},
147+
{
148+
name: 'displayName',
149+
parent: {
150+
name: 'FunctionComponent',
151+
},
152+
optional: true,
153+
kind: 4,
154+
properties: [
155+
{
156+
kind: 1,
157+
},
158+
{
159+
kind: 8,
160+
},
161+
],
162+
},
163+
],
164+
value: {
165+
name: 'MyComponent',
166+
loc: {
167+
loc: {
168+
start: {
169+
line: 12,
170+
col: 14,
171+
},
172+
end: {
173+
line: 12,
174+
col: 25,
175+
},
176+
},
177+
},
178+
type: 'FC',
179+
kind: 11,
180+
generics: [
181+
{
182+
name: 'MyComponentProps',
183+
},
184+
],
185+
properties: [
186+
{
187+
name: 'propTypes',
188+
parent: {
189+
name: 'FunctionComponent',
190+
},
191+
},
192+
{
193+
name: 'contextTypes',
194+
parent: {
195+
name: 'FunctionComponent',
196+
},
197+
},
198+
{
199+
name: 'defaultProps',
200+
parent: {
201+
name: 'FunctionComponent',
202+
},
203+
},
204+
{
205+
name: 'displayName',
206+
parent: {
207+
name: 'FunctionComponent',
208+
},
209+
},
210+
],
211+
parameters: [
212+
{
213+
kind: 26,
214+
properties: [
215+
{
216+
name: 'name',
217+
kind: 1,
218+
value: 'some default text',
219+
},
220+
],
221+
},
222+
],
223+
returns: {
224+
name: 'Element',
225+
kind: 14,
226+
extends: [
227+
{
228+
name: 'ReactElement',
229+
},
230+
],
231+
properties: [
232+
{
233+
name: 'type',
234+
parent: {
235+
name: 'ReactElement',
236+
},
237+
type: 'T',
238+
},
239+
{
240+
name: 'props',
241+
parent: {
242+
name: 'ReactElement',
243+
},
244+
type: 'P',
245+
},
246+
{
247+
name: 'key',
248+
parent: {
249+
name: 'ReactElement',
250+
},
251+
kind: 4,
252+
properties: [
253+
{
254+
kind: 4,
255+
type: 'Key',
256+
properties: [
257+
{
258+
kind: 1,
259+
},
260+
{
261+
kind: 2,
262+
},
263+
],
264+
},
265+
{
266+
kind: 10,
267+
},
268+
],
269+
},
270+
],
271+
optional: true,
272+
},
273+
},
274+
},
275+
],
276+
name: 'default',
277+
},
278+
});
279+
});
280+
});

packages/api/test/insta-docs/document.docs.tsx renamed to packages/api/test/insta-docs/document/export-default.docs.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import React from 'react';
2-
import { MyComponent } from './component/component';
2+
import { MyComponent } from '../component/component';
33

44
export default {
55
name: 'documentation for MyComponent',
66
component: MyComponent,
77
};
88

9-
export const defaultName = () => <MyComponent />;
10-
11-
export const initializedName = ({ name = 'steve' }) => (
12-
<MyComponent name={name} />
13-
);
14-
159
export const assignedProps = ({ name } = { name: 'steve' }) => (
1610
<MyComponent name={name} />
1711
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { MyComponent } = require('../component/component');
2+
3+
type Document = {
4+
name: string;
5+
subcomponents: Record<string, any>;
6+
};
7+
export default {
8+
name: 'documentation for MyComponent',
9+
subcomponents: { MyComponent },
10+
} as Document;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import { MyComponent } from '../component/component';
3+
4+
export const assignedProps = ({ name } = { name: 'steve' }) => (
5+
<MyComponent name={name} />
6+
);
7+
8+
assignedProps.title = 'Custom title';
9+
assignedProps.controls = {
10+
name: { type: 'string', value: 'enter value here' },
11+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react';
2+
import { MyComponent } from '../component/component';
3+
4+
export const defaultName = () => <MyComponent />;

0 commit comments

Comments
 (0)