-
Notifications
You must be signed in to change notification settings - Fork 381
WIP Elef/remove experimental from typedoc #6651
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
base: main
Are you sure you want to change the base?
Changes from all commits
845b750
347a488
4d6561b
0d3c98c
a627eb8
b037879
02d730d
c4b7cf0
d8c5dc2
6b7da9f
def7a20
0c3d485
dea5e8e
4171b93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -46,6 +46,26 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext { | |||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
this.partials = { | ||||||||||||||||||||||||||||||||||||
...superPartials, | ||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||
* This hides the "Experimental" text and "Example" section from the output (by default). | ||||||||||||||||||||||||||||||||||||
* @param {import('typedoc').Comment} model | ||||||||||||||||||||||||||||||||||||
* @param {{ headingLevel?: number; showSummary?: boolean; showTags?: boolean; showReturns?: boolean; isTableColumn?: boolean }} [options] | ||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||
comment: (model, options) => { | ||||||||||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||||||||||
model.hasModifier('@experimental') && | ||||||||||||||||||||||||||||||||||||
[ReflectionKind.Class, ReflectionKind.Interface].includes(this.page?.model?.kind) | ||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||
model.removeModifier('@experimental'); | ||||||||||||||||||||||||||||||||||||
model.removeTags('@example'); | ||||||||||||||||||||||||||||||||||||
model.removeTags('@see'); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
const res = superPartials.comment(model, options); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return res.replace(/^\n+/, ''); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return superPartials.comment(model, options); | ||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||
* This hides the "Type parameters" section and the signature title from the output (by default). Shows the signature title if the `@displayFunctionSignature` tag is present. | ||||||||||||||||||||||||||||||||||||
* @param {import('typedoc').SignatureReflection} model | ||||||||||||||||||||||||||||||||||||
|
@@ -218,13 +238,19 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext { | |||||||||||||||||||||||||||||||||||
const customizedModel = model; | ||||||||||||||||||||||||||||||||||||
customizedModel.typeParameters = undefined; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Extract the Accessors group (if any) and prevent default rendering for it | ||||||||||||||||||||||||||||||||||||
const originalGroups = customizedModel.groups; | ||||||||||||||||||||||||||||||||||||
const accessorsGroup = originalGroups?.find(g => g.title === 'Accessors'); | ||||||||||||||||||||||||||||||||||||
const groupsWithoutAccessors = originalGroups?.filter(g => g.title !== 'Accessors'); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// When an interface extends another interface, typedoc will generate a "Methods" group | ||||||||||||||||||||||||||||||||||||
// We want to hide this group from being rendered | ||||||||||||||||||||||||||||||||||||
const groupsWithoutMethods = originalGroups?.filter(g => g.title !== 'Methods'); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Extract the Accessors group (if any) and prevent default rendering for it | ||||||||||||||||||||||||||||||||||||
const accessorsGroup = groupsWithoutMethods?.find(g => g.title === 'Accessors'); | ||||||||||||||||||||||||||||||||||||
const groupsWithoutAccessors = groupsWithoutMethods?.filter(g => g.title !== 'Accessors'); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+243
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainHiding every “Methods” group is too broad; restrict to interfaces (extends case). As written, you’ll also remove legitimate methods from classes. Limit the filter to interface pages only. - const groupsWithoutMethods = originalGroups?.filter(g => g.title !== 'Methods');
+ const isInterface = customizedModel?.kind === ReflectionKind.Interface;
+ const groupsWithoutMethods = isInterface
+ ? originalGroups?.filter(g => g.title !== 'Methods')
+ : originalGroups; Build a sample class with methods in the docs to confirm the Methods section remains visible. 🏁 Script executed: #!/bin/bash
# Locate ReflectionKind usage and import in custom-theme.mjs
grep -R "ReflectionKind" -n .typedoc/custom-theme.mjs || true
# Locate where customizedModel is defined or passed in
grep -R "customizedModel" -n .typedoc/custom-theme.mjs || true Length of output: 1133 Restrict “Methods” filtering to interfaces only - const groupsWithoutMethods = originalGroups?.filter(g => g.title !== 'Methods');
+ const isInterface = customizedModel.kind === ReflectionKind.Interface;
+ const groupsWithoutMethods = isInterface
+ ? originalGroups.filter(g => g.title !== 'Methods')
+ : originalGroups; [matches .typedoc/custom-theme.mjs:243] 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
customizedModel.groups = groupsWithoutAccessors; | ||||||||||||||||||||||||||||||||||||
const nonAccessorOutput = superPartials.memberWithGroups(customizedModel, options); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
customizedModel.groups = originalGroups; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/** @type {string[]} */ | ||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Snapshot Testing for Clerk Resources | ||
|
||
This directory contains snapshot tests for Clerk resource classes using Vitest. Snapshot tests help ensure that the structure and serialization of resource objects remain consistent over time. | ||
|
||
## What are Snapshot Tests? | ||
|
||
Snapshot tests capture the output of a function or object and store it as a "snapshot" file. When the test runs again, the current output is compared against the stored snapshot. If they differ, the test fails, alerting you to potential breaking changes. | ||
|
||
## How to Add Snapshot Tests | ||
|
||
### Basic Pattern | ||
|
||
```typescript | ||
describe('ResourceName Snapshots', () => { | ||
it('should match snapshot for resource instance structure', () => { | ||
const resource = new ResourceName({ | ||
// Provide test data that represents a typical resource | ||
id: 'test_123', | ||
name: 'Test Resource', | ||
// ... other properties | ||
}); | ||
|
||
const snapshot = { | ||
id: resource.id, | ||
name: resource.name, | ||
// Include relevant public properties | ||
}; | ||
|
||
expect(snapshot).toMatchSnapshot(); | ||
}); | ||
}); | ||
``` | ||
|
||
### Testing Different States | ||
|
||
```typescript | ||
it('should match snapshot for empty/null state', () => { | ||
const resource = new ResourceName({ | ||
id: 'empty_test', | ||
name: null, | ||
// ... other properties with null/empty values | ||
} as any); // Use 'as any' if TypeScript complains about null values | ||
|
||
expect({ | ||
id: resource.id, | ||
name: resource.name, | ||
}).toMatchSnapshot(); | ||
}); | ||
``` | ||
|
||
### Testing Serialization Methods | ||
|
||
For resources with `__internal_toSnapshot()` methods: | ||
|
||
```typescript | ||
it('should match snapshot for __internal_toSnapshot method', () => { | ||
const resource = new ResourceName(testData); | ||
expect(resource.__internal_toSnapshot()).toMatchSnapshot(); | ||
}); | ||
``` | ||
|
||
## Best Practices | ||
|
||
1. **Use Fixed Dates**: Use `vi.useFakeTimers()` and `vi.setSystemTime()` to ensure consistent timestamps in snapshots. | ||
|
||
2. **Include Relevant Properties**: Focus on public API properties that consumers rely on, not internal implementation details. | ||
|
||
3. **Test Edge Cases**: Include tests for null values, empty states, and different configurations. | ||
|
||
4. **Keep Snapshots Small**: Focus on the essential structure rather than including every property. | ||
|
||
5. **Update When Intentional**: When you intentionally change a resource's structure, update the snapshots using `npm test -- --update-snapshots`. | ||
|
||
## Running Snapshot Tests | ||
|
||
```bash | ||
# Run all resource tests | ||
npm test -- src/core/resources/__tests__/*.spec.ts | ||
|
||
# Run specific test file | ||
npm test -- src/core/resources/__tests__/Client.spec.ts | ||
|
||
# Update snapshots when structure changes intentionally | ||
npm test -- --update-snapshots | ||
``` | ||
|
||
## Examples | ||
|
||
See the following files for examples: | ||
|
||
- `Client.spec.ts` - Complex resource with nested objects | ||
- `Environment.spec.ts` - Resource with configuration objects | ||
- `Image.spec.ts` - Simple resource with basic properties | ||
|
||
## When Snapshots Fail | ||
|
||
When a snapshot test fails: | ||
|
||
1. **Review the diff** to understand what changed | ||
2. **Determine if the change is intentional**: | ||
- If yes: Update the snapshot with `--update-snapshots` | ||
- If no: Fix the code to maintain backward compatibility | ||
3. **Consider the impact** on API consumers | ||
4. **Update documentation** if the public API changed | ||
|
||
## Snapshot Files | ||
|
||
Snapshot files are stored in `__snapshots__/` directories and should be committed to version control. They serve as documentation of your resource structures and help catch unintended changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid mutating
typeParameters
; restore after rendering.You unset
typeParameters
and never restore it, which may affect downstream partials that read the same model instance.Also applies to: 254-255
🤖 Prompt for AI Agents