Skip to content

Support vitest flavored snapshot file #40

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ To pass your values, add them in tsconfig.json:
]
}]
```

**snapshotFileFlavor**
Snapshot file flavor, default:
```json
"jest"
```

You can set it to `vitest` to support [vitest snapshots](https://vitest.dev/guide/snapshot.html).
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface Configuration {
* Note: vscode doesn't render correctly both css + jsx in separate tags, so this option doesn't do anything now
*/
extractCSSForJSTag: boolean;

snapshotFileFlavor: 'jest' | 'vitest';
}

export const defaultConfig: Configuration = {
Expand All @@ -56,4 +58,5 @@ export const defaultConfig: Configuration = {
snapshotDir: "__snapshots__",
useJSTagsForSnapshotHover: false,
extractCSSForJSTag: true,
snapshotFileFlavor: 'jest',
}
4 changes: 2 additions & 2 deletions src/getsnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export function tryGetSnapshotForPosition(

const customName = node.parent.parent.arguments.find(arg => ts.isStringLiteral(arg));
// let snapshotName = blockInfo.blockNames.join(" ") + " " + (snapshotCallsInBlock + 1);
let snapshotName = blockInfo.blockNames.join(" ");
let snapshotName = blockInfo.blockNames.join(config.snapshotFileFlavor === "vitest" ? " > " : " ");
if (customName) {
snapshotName += ": " + (customName as ts.StringLiteralLike).text + " " + snapshotCallsInBlock.namedCalls[(customName as ts.StringLiteralLike).text];
snapshotName += (config.snapshotFileFlavor === "vitest" ? " > " : ": ") + (customName as ts.StringLiteralLike).text + " " + snapshotCallsInBlock.namedCalls[(customName as ts.StringLiteralLike).text];
} else {
snapshotName += " " + (snapshotCallsInBlock.anonymousCalls);
}
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function init(modules: { typescript: typeof ts_module }) {
if (typeof info.config.extractCSSForJSTag !== "undefined") {
config.extractCSSForJSTag = info.config.extractCSSForJSTag;
}
if (typeof info.config.snapshotFileFlavor !== "undefined") {
config.snapshotFileFlavor = info.config.snapshotFileFlavor
}

for (const k in oldLS) {
(proxy as any)[k] = function () {
Expand Down