Skip to content

Commit 6796dfa

Browse files
committed
test: resolve alias paths and TypeScript errors in Playwright tests
Use `process.cwd()` for absolute alias resolution to ensure consistency in CI. Add wrapper components to accept props via `mount()` for type-safe testing.
1 parent 0fc563c commit 6796dfa

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

playwright.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export default defineConfig({
1616
plugins: [svelte({ preprocess: vitePreprocess() })],
1717
resolve: {
1818
alias: {
19-
"svelte-highlight": path.resolve("src"),
20-
"svelte-highlight/styles": path.resolve("src/styles"),
21-
"svelte-highlight/languages": path.resolve("src/languages"),
19+
"svelte-highlight/styles": path.resolve(process.cwd(), "src/styles"),
20+
"svelte-highlight/languages": path.resolve(process.cwd(), "src/languages"),
21+
"svelte-highlight": path.resolve(process.cwd(), "src"),
2222
},
2323
conditions: ["browser", "module", "import"],
2424
},
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="ts">
2+
import Highlight from "svelte-highlight";
3+
import atomOneDark from "svelte-highlight/styles/atom-one-dark";
4+
5+
export let langtag: boolean = false;
6+
export let code: string = "";
7+
export let language: { name: string; register: () => void };
8+
export let style: string = "";
9+
</script>
10+
11+
<svelte:head>
12+
{@html atomOneDark}
13+
</svelte:head>
14+
15+
<Highlight {langtag} {code} {language} {style} />
16+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script lang="ts">
2+
import { HighlightAuto } from "svelte-highlight";
3+
import atomOneDark from "svelte-highlight/styles/atom-one-dark";
4+
5+
export let code: string = "";
6+
</script>
7+
8+
<svelte:head>
9+
{@html atomOneDark}
10+
</svelte:head>
11+
12+
<HighlightAuto {code} langtag />
13+

tests/e2e/e2e.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { expect, test } from "@playwright/experimental-ct-svelte";
22
import Highlight from "./Highlight.test.svelte";
33
import HighlightAutoLanguageRestriction from "./HighlightAuto.languageRestriction.test.svelte";
44
import HighlightAuto from "./HighlightAuto.test.svelte";
5+
import HighlightAutoWithProps from "./HighlightAuto.withProps.test.svelte";
6+
import HighlightWithProps from "./Highlight.withProps.test.svelte";
57
import LangTag from "./LangTag.test.svelte";
68
import LineNumbersCustomStartingLine from "./LineNumbers.customStartingLine.test.svelte";
79
import LineNumbersHideBorder from "./LineNumbers.hideBorder.test.svelte";
@@ -71,7 +73,7 @@ test("LineNumbers - custom starting number", async ({ mount, page }) => {
7173
});
7274

7375
test("Language tag styling", async ({ mount, page }) => {
74-
await mount(Highlight, {
76+
await mount(HighlightWithProps, {
7577
props: {
7678
langtag: true,
7779
code: "const x = 1;",
@@ -86,7 +88,7 @@ test("Language tag styling", async ({ mount, page }) => {
8688
});
8789

8890
test("Auto-highlighting detects language", async ({ mount, page }) => {
89-
await mount(HighlightAuto, {
91+
await mount(HighlightAutoWithProps, {
9092
props: {
9193
code: "body { color: red; }",
9294
},

0 commit comments

Comments
 (0)