Skip to content

Commit 44572fe

Browse files
committed
refactor: ♻️ new testing setup
1 parent 3dd1283 commit 44572fe

32 files changed

+1052
-268
lines changed

.github/workflows/unit-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
version: '^8.0.0'
2929
- name: Install dependencies
3030
run: pnpm recursive install
31+
- name: Install Playwright browsers
32+
run: pnpm exec playwright install chromium --with-deps
33+
working-directory: packages/sveltekit-embed
3134
- name: Run unit tests
3235
run: pnpm run test:ci
3336
working-directory: packages/sveltekit-embed

packages/sveltekit-embed/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SvelteKit Embed 🌱
22

3-
[docs](../../README.md)
3+
[docs](../../README.md)
File renamed without changes.

packages/sveltekit-embed/package.json

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,38 @@
4646
"svelte": "^4.0.0 || ^5.0.0"
4747
},
4848
"devDependencies": {
49+
"@eslint/compat": "^1.2.9",
50+
"@eslint/js": "^9.27.0",
4951
"@playwright/test": "^1.52.0",
50-
"@sveltejs/adapter-auto": "^4.0.0",
51-
"@sveltejs/kit": "^2.20.7",
52+
"@sveltejs/adapter-auto": "^6.0.1",
53+
"@sveltejs/kit": "^2.21.1",
5254
"@sveltejs/package": "^2.3.11",
5355
"@sveltejs/vite-plugin-svelte": "^5.0.3",
54-
"@testing-library/svelte": "^5.2.7",
55-
"@types/eslint": "^9.6.1",
56-
"@typescript-eslint/eslint-plugin": "^8.31.0",
57-
"@typescript-eslint/parser": "^8.31.0",
58-
"eslint": "^9.25.1",
59-
"eslint-config-prettier": "^10.1.2",
60-
"eslint-plugin-svelte": "^2.46.1",
56+
"@vitest/browser": "^3.1.4",
57+
"eslint": "^9.27.0",
58+
"eslint-config-prettier": "^10.1.5",
59+
"eslint-plugin-svelte": "^3.9.0",
6160
"fathom-client": "^3.7.2",
61+
"globals": "^16.1.0",
6262
"jsdom": "^26.1.0",
6363
"prettier": "^3.5.3",
64-
"prettier-plugin-svelte": "^3.3.3",
65-
"publint": "^0.3.2",
66-
"svelte": "5.28.2",
67-
"svelte-check": "^4.1.6",
68-
"tslib": "^2.8.1",
64+
"prettier-plugin-svelte": "^3.4.0",
65+
"prettier-plugin-tailwindcss": "^0.6.11",
66+
"publint": "^0.3.12",
67+
"svelte": "5.33.1",
68+
"svelte-check": "^4.2.1",
6969
"typescript": "^5.8.3",
70-
"vite": "^6.3.3",
71-
"vitest": "^3.1.2"
70+
"typescript-eslint": "^8.32.1",
71+
"vite": "^6.3.5",
72+
"vitest": "^3.1.4",
73+
"vitest-browser-svelte": "^0.1.0"
7274
},
7375
"svelte": "./dist/index.js",
7476
"types": "./dist/index.d.ts",
75-
"type": "module"
77+
"type": "module",
78+
"pnpm": {
79+
"onlyBuiltDependencies": [
80+
"esbuild"
81+
]
82+
}
7683
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import type { PlaywrightTestConfig } from '@playwright/test';
1+
import { defineConfig } from '@playwright/test';
22

3-
const config: PlaywrightTestConfig = {
3+
export default defineConfig({
44
webServer: {
5-
command: 'npm run build && npm run preview',
5+
command: 'npm run build && PORT=4173 node build/index.js',
66
port: 4173,
77
},
8-
testDir: 'tests',
9-
testMatch: /(.+\.)?(test|spec)\.[jt]s/,
10-
};
11-
12-
export default config;
8+
testDir: 'e2e',
9+
});

packages/sveltekit-embed/src/index.test.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/sveltekit-embed/src/lib/components/anchor-fm.test.ts renamed to packages/sveltekit-embed/src/lib/components/anchor-fm.svelte.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import AnchorFm from '$lib/components/anchor-fm.svelte';
2-
import { cleanup, render } from '@testing-library/svelte/svelte5';
3-
import { afterEach, describe, expect, it } from 'vitest';
2+
import { describe, expect, it } from 'vitest';
3+
import { render } from 'vitest-browser-svelte';
44

55
let episodeUrl =
66
'purrfect-dev/embed/episodes/1-31---Delivering-Digital-Content-with-GraphCMS-e14g55c/a-a650v9a';
77

88
describe('AnchorFm', () => {
9-
afterEach(() => cleanup());
10-
119
it('mounts with episode url', async () => {
1210
const { container } = render(AnchorFm, {
1311
episodeUrl,
@@ -23,7 +21,7 @@ describe('AnchorFm', () => {
2321
});
2422
const iframe = getByTestId('anchor-fm-episode');
2523
const expected_src = `https://anchor.fm/${episodeUrl}`;
26-
expect(iframe.getAttribute('src')).toBe(expected_src);
24+
await expect.element(iframe).toHaveAttribute('src', expected_src);
2725
});
2826

2927
it('mounts with custom height and width', async () => {
@@ -45,6 +43,6 @@ describe('AnchorFm', () => {
4543
disable_observer: false,
4644
});
4745
const general_observer = getByTestId('general-observer');
48-
expect(general_observer).toBeTruthy();
46+
await expect.element(general_observer).toBeInTheDocument();
4947
});
5048
});

packages/sveltekit-embed/src/lib/components/bluesky.test.ts renamed to packages/sveltekit-embed/src/lib/components/bluesky.svelte.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { cleanup, render } from '@testing-library/svelte/svelte5';
2-
import { afterEach, describe, expect, it } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
2+
import { render } from 'vitest-browser-svelte';
33
import Bluesky from './bluesky.svelte';
44

55
describe('Bluesky', () => {
6-
afterEach(() => cleanup());
7-
86
const test_post_id =
97
'did:plc:nlvjelw3dy3pddq7qoglleko/app.bsky.feed.post/3l6ud34tnwn2k';
108

@@ -20,7 +18,7 @@ describe('Bluesky', () => {
2018

2119
const iframe = getByTestId('bluesky-embed');
2220
const expected_src = `https://embed.bsky.app/embed/${test_post_id}`;
23-
expect(iframe.getAttribute('src')).toBe(expected_src);
21+
await expect.element(iframe).toHaveAttribute('src', expected_src);
2422
});
2523

2624
it('renders with custom width', async () => {
@@ -30,7 +28,7 @@ describe('Bluesky', () => {
3028
});
3129

3230
const iframe = getByTestId('bluesky-embed');
33-
expect(iframe.getAttribute('width')).toBe('50%');
31+
await expect.element(iframe).toHaveAttribute('width', '50%');
3432
});
3533

3634
it('applies custom iframe styles', async () => {
@@ -41,7 +39,8 @@ describe('Bluesky', () => {
4139
});
4240

4341
const iframe = getByTestId('bluesky-embed');
44-
const style_text = iframe.style.cssText.toLowerCase();
42+
const element = iframe.element();
43+
const style_text = element.style.cssText.toLowerCase();
4544
expect(style_text).toContain('border-radius: 8px');
4645
expect(style_text).toContain('background: rgb(240, 240, 240)');
4746
});
@@ -52,15 +51,16 @@ describe('Bluesky', () => {
5251
});
5352

5453
const iframe = getByTestId('bluesky-embed');
55-
const style_text = iframe.style.cssText.toLowerCase();
54+
const element = iframe.element();
55+
const style_text = element.style.cssText.toLowerCase();
5656
expect(style_text).toContain('position: absolute');
5757
expect(style_text).toContain('top: 0px');
5858
expect(style_text).toContain('left: 0px');
5959
expect(style_text).toContain('width: 100%');
6060
expect(style_text).toContain('height: 100%');
6161
expect(style_text).toContain('border: 0px');
62-
expect(iframe.getAttribute('frameborder')).toBe('0');
63-
expect(iframe.getAttribute('scrolling')).toBe('no');
62+
await expect.element(iframe).toHaveAttribute('frameborder', '0');
63+
await expect.element(iframe).toHaveAttribute('scrolling', 'no');
6464
});
6565

6666
it('combines default and custom iframe styles correctly', async () => {
@@ -71,7 +71,8 @@ describe('Bluesky', () => {
7171
});
7272

7373
const iframe = getByTestId('bluesky-embed');
74-
const style_text = iframe.style.cssText.toLowerCase();
74+
const element = iframe.element();
75+
const style_text = element.style.cssText.toLowerCase();
7576

7677
// Check default styles are preserved
7778
expect(style_text).toContain('position: absolute');
@@ -84,7 +85,7 @@ describe('Bluesky', () => {
8485
expect(style_text).toContain('margin: 10px');
8586
});
8687

87-
it('updates height when receiving message from iframe', () => {
88+
it('updates height when receiving message from iframe', async () => {
8889
const { getByTestId } = render(Bluesky, {
8990
post_id: test_post_id,
9091
});
@@ -97,6 +98,7 @@ describe('Bluesky', () => {
9798
window.dispatchEvent(message_event);
9899

99100
const iframe = getByTestId('bluesky-embed');
100-
expect(iframe.style.height).toBe('100%');
101+
const element = iframe.element();
102+
expect(element.style.height).toBe('100%');
101103
});
102104
});

packages/sveltekit-embed/src/lib/components/buzzsprout.test.ts renamed to packages/sveltekit-embed/src/lib/components/buzzsprout.svelte.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import Buzzsprout from '$lib/components/buzzsprout.svelte';
2-
import { cleanup, render } from '@testing-library/svelte/svelte5';
3-
import { afterEach, describe, expect, it } from 'vitest';
2+
import { render } from 'vitest-browser-svelte';
3+
import { describe, expect, it } from 'vitest';
44

55
let buzzsproutId = '12345';
66

77
describe('Buzzsprout', () => {
8-
afterEach(() => cleanup());
9-
108
it('mounts with buzzsproutId', async () => {
119
const { container } = render(Buzzsprout, {
1210
buzzsproutId,
@@ -22,7 +20,7 @@ describe('Buzzsprout', () => {
2220
});
2321
const iframe = getByTestId('buzzsprout');
2422
const expected_src = `https://www.buzzsprout.com/${buzzsproutId}?client_source=admin&iframe=true`;
25-
expect(iframe.getAttribute('src')).toBe(expected_src);
23+
await expect.element(iframe).toHaveAttribute('src', expected_src);
2624
});
2725

2826
it('mounts with custom height and width', async () => {

packages/sveltekit-embed/src/lib/components/code-pen.test.ts renamed to packages/sveltekit-embed/src/lib/components/code-pen.svelte.test.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import CodePen from '$lib/components/code-pen.svelte';
2-
import { cleanup, render } from '@testing-library/svelte/svelte5';
3-
import { afterEach, describe, expect, it } from 'vitest';
2+
import { describe, expect, it } from 'vitest';
3+
import { render } from 'vitest-browser-svelte';
44

55
let codePenId = 'abcde';
66

77
describe('CodePen', () => {
8-
afterEach(() => cleanup());
9-
108
it('mounts', async () => {
119
const { container } = render(CodePen, {
1210
codePenId,
@@ -22,22 +20,25 @@ describe('CodePen', () => {
2220
});
2321

2422
const iframe = getByTitle(`codepen-${codePenId}`);
23+
const element = iframe.element();
2524

26-
expect(iframe.getAttribute('src')).toContain(
25+
expect(element.getAttribute('src')).toContain(
2726
`codepen.io/team/codepen/embed`,
2827
);
29-
expect(iframe.getAttribute('src')).toContain(`/${codePenId}/`);
30-
expect(iframe.getAttribute('src')).toContain(`height=500px`);
31-
expect(iframe.getAttribute('src')).toContain(`theme-id=default`);
32-
expect(iframe.getAttribute('src')).toContain(
28+
expect(element.getAttribute('src')).toContain(`/${codePenId}/`);
29+
expect(element.getAttribute('src')).toContain(`height=500px`);
30+
expect(element.getAttribute('src')).toContain(`theme-id=default`);
31+
expect(element.getAttribute('src')).toContain(
3332
`default-tab=result`,
3433
);
35-
expect(iframe.getAttribute('src')).toContain(`editable=true`);
36-
expect(iframe.getAttribute('src')).toContain('/preview');
37-
expect(iframe.getAttribute('frameborder')).toBe('no');
38-
expect(iframe.getAttribute('allowfullscreen')).toBe('');
39-
expect(iframe.getAttribute('style')).toContain(`height: 500px`);
40-
expect(iframe.getAttribute('style')).toContain(`width: 100%`);
34+
expect(element.getAttribute('src')).toContain(`editable=true`);
35+
expect(element.getAttribute('src')).toContain('/preview');
36+
await expect.element(iframe).toHaveAttribute('frameborder', 'no');
37+
await expect
38+
.element(iframe)
39+
.toHaveAttribute('allowfullscreen', '');
40+
expect(element.getAttribute('style')).toContain(`height: 500px`);
41+
expect(element.getAttribute('style')).toContain(`width: 100%`);
4142
});
4243

4344
it('mounts with custom height and width', async () => {
@@ -58,6 +59,6 @@ describe('CodePen', () => {
5859
disable_observer: false,
5960
});
6061
const general_observer = getByTestId('general-observer');
61-
expect(general_observer).toBeTruthy();
62+
await expect.element(general_observer).toBeInTheDocument();
6263
});
6364
});

0 commit comments

Comments
 (0)