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

test: use table test to snapshot fixtures #122

Merged
merged 3 commits into from
Apr 6, 2024
Merged
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
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ jobs:
run: yarn prepack

- name: Run unit tests
run: yarn test:unit

- name: Run snapshot tests
run: yarn test:snapshot
run: yarn test

# Only trigger deploy if previous steps pass and branch is main
- name: Deploy docs
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"test:unit": "vitest -r tests",
"test:snapshot": "node tests/test-snapshot",
"test": "vitest -r tests",
"test:integration": "node tests/test-integration",
"format": "prettier --write \"{src,tests,playground}/**/*.{js,ts,svelte,md}\" --ignore-path \".gitignore\"",
"prepack": "tsc"
Expand Down
18 changes: 9 additions & 9 deletions src/ComponentParser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// TODO: upgrading to Svelte 4 shows a lot of TS errors. Ignore for now but resolve.
// @ts-nocheck
import { compile, walk, parse } from "svelte/compiler";
import * as commentParser from "comment-parser";
import type { VariableDeclaration } from "estree";
import { Node } from "estree-walker";
import { compile, parse, walk } from "svelte/compiler";
import { Ast, TemplateNode, Var } from "svelte/types/compiler/interfaces";
import { getElementByTag } from "./element-tag-map";
import { Node } from "estree-walker";
import type { VariableDeclaration } from "estree";

interface CompiledSvelteCode {
vars: Var[];
Expand Down Expand Up @@ -134,7 +134,7 @@ export default class ComponentParser {
this.options = options;
}

private static mapToArray(map: Map<any, any>) {
private static mapToArray<T>(map: Map<any, T>) {
return Array.from(map, ([key, value]) => value);
}

Expand Down Expand Up @@ -370,7 +370,7 @@ export default class ComponentParser {
init.type === "ArrayExpression" ||
init.type === "ArrowFunctionExpression"
) {
value = this.sourceAtPos(init.start, init.end)?.replace(/\n/g, " ");
value = this.sourceAtPos(init.start, init.end)?.replace(/[\r\n]+/g, " ");
type = value;
isFunction = init.type === "ArrowFunctionExpression";

Expand All @@ -391,7 +391,7 @@ export default class ComponentParser {
}

if (declaration_type === "FunctionDeclaration") {
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/\n/g, " ");
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/[\r\n]+/g, " ");
type = "() => any";
kind = "function";
isFunction = true;
Expand Down Expand Up @@ -506,7 +506,7 @@ export default class ComponentParser {
init.type === "ArrayExpression" ||
init.type === "ArrowFunctionExpression"
) {
value = this.sourceAtPos(init.start, init.end)?.replace(/\n/g, " ");
value = this.sourceAtPos(init.start, init.end)?.replace(/[\r\n]+/g, " ");
type = value;
isFunction = init.type === "ArrowFunctionExpression";

Expand All @@ -527,7 +527,7 @@ export default class ComponentParser {
}

if (declaration_type === "FunctionDeclaration") {
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/\n/g, " ");
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/[\r\n]+/g, " ");
type = "() => any";
kind = "function";
isFunction = true;
Expand Down Expand Up @@ -582,7 +582,7 @@ export default class ComponentParser {
let data: string = node?.data?.trim() ?? "";

if (/^@component/.test(data)) {
this.componentComment = data.replace(/^@component/, "");
this.componentComment = data.replace(/^@component/, "").replace(/\r/g, "");
}
}

Expand Down
Loading