Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs-tools: Replace doctrine with jsdoc-type-pratt-parser #26305

Merged
merged 12 commits into from
Jun 10, 2024
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ jobs:
name: Install dependencies
command: yarn install --no-immutable
working_directory: test-storybooks/portable-stories-kitchen-sink/<< parameters.directory >>
environment:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
- run:
name: Run Jest tests
command: yarn jest
Expand Down
5 changes: 2 additions & 3 deletions code/lib/docs-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@
"@storybook/core-events": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/types": "workspace:*",
"@types/doctrine": "^0.0.3",
"assert": "^2.1.0",
"doctrine": "^3.0.0",
"comment-parser": "^1.4.1",
"jsdoc-type-pratt-parser": "^4.0.0",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
22 changes: 11 additions & 11 deletions code/lib/docs-tools/src/argTypes/jsdocParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('parseJsDoc', () => {
expect(extractedTags).toBeUndefined();
});

it('should set includesJsDocto to false when the value dont contains JSDoc', () => {
it('should set includesJsDoc to false when the value dont contains JSDoc', () => {
const { includesJsDoc, description, extractedTags } = parseJsDoc('Hey!');

expect(includesJsDoc).toBeFalsy();
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('parseJsDoc', () => {
expect(extractedTags?.params).not.toBeNull();
expect(extractedTags?.params?.[0].name).toBe('event');
expect(extractedTags?.params?.[0].type).not.toBeNull();
expect(extractedTags?.params?.[0].type.name).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].type.value).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].description).toBeNull();
});

Expand All @@ -78,7 +78,7 @@ describe('parseJsDoc', () => {
expect(extractedTags?.params).not.toBeNull();
expect(extractedTags?.params?.[0].name).toBe('event');
expect(extractedTags?.params?.[0].type).not.toBeNull();
expect(extractedTags?.params?.[0].type.name).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].type.value).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].description).toBe('React event');
});

Expand All @@ -90,7 +90,7 @@ describe('parseJsDoc', () => {
['event1', 'event2', 'event3'].forEach((x, i) => {
expect(extractedTags?.params?.[i].name).toBe(x);
expect(extractedTags?.params?.[i].type).not.toBeNull();
expect(extractedTags?.params?.[i].type.name).toBe('SyntheticEvent');
expect(extractedTags?.params?.[i].type.value).toBe('SyntheticEvent');
expect(extractedTags?.params?.[i].description).toBe('React event');
});
});
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('parseJsDoc', () => {
expect(extractedTags?.params).not.toBeNull();
expect(extractedTags?.params?.[0].name).toBe('event');
expect(extractedTags?.params?.[0].type).not.toBeNull();
expect(extractedTags?.params?.[0].type.name).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].type.value).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].description).toBe('React event');
});
});
Expand Down Expand Up @@ -251,15 +251,15 @@ describe('parseJsDoc', () => {

expect(extractedTags?.returns).not.toBeNull();
expect(extractedTags?.returns?.type).not.toBeNull();
expect(extractedTags?.returns?.type.name).toBe('string');
expect(extractedTags?.returns?.type.value).toBe('string');
});

it('should return a @returns with a type and a description', () => {
const { extractedTags } = parseJsDoc('@returns {string} - A bar description');

expect(extractedTags?.returns).not.toBeNull();
expect(extractedTags?.returns?.type).not.toBeNull();
expect(extractedTags?.returns?.type.name).toBe('string');
expect(extractedTags?.returns?.type.value).toBe('string');
expect(extractedTags?.returns?.description).toBe('A bar description');
});

Expand All @@ -270,7 +270,7 @@ describe('parseJsDoc', () => {

expect(extractedTags?.returns).not.toBeNull();
expect(extractedTags?.returns?.type).not.toBeNull();
expect(extractedTags?.returns?.type.name).toBe('string');
expect(extractedTags?.returns?.type.value).toBe('string');
expect(extractedTags?.returns?.description).toBe('This is\na multiline\ndescription');
});

Expand All @@ -279,7 +279,7 @@ describe('parseJsDoc', () => {

expect(extractedTags?.returns).not.toBeNull();
expect(extractedTags?.returns?.type).not.toBeNull();
expect(extractedTags?.returns?.type.name).toBe('number');
expect(extractedTags?.returns?.type.value).toBe('number');
});

describe('getTypeName', () => {
Expand Down Expand Up @@ -353,9 +353,9 @@ describe('parseJsDoc', () => {
expect(extractedTags?.params).not.toBeNull();
expect(Object.keys(extractedTags?.params ?? []).length).toBe(1);
expect(extractedTags?.params?.[0].name).toBe('event');
expect(extractedTags?.params?.[0].type.name).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].type.value).toBe('SyntheticEvent');
expect(extractedTags?.params?.[0].description).toBe('Original event.');
expect(extractedTags?.returns).not.toBeNull();
expect(extractedTags?.returns?.type.name).toBe('string');
expect(extractedTags?.returns?.type.value).toBe('string');
});
});
Loading
Loading