-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from mcous/e2e-svelte-5
test(e2e): add simple Svelte 5 suite
- Loading branch information
Showing
16 changed files
with
373 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
shell-emulator=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@svelte-jester-e2e/svelte-5", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"test": "pnpm install && NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --coverage --no-cache", | ||
"test:watch": "pnpm run test --watch" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/jest-dom": "^6.4.5", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"svelte": "^5.0.0-next.139", | ||
"svelte-jester": "workspace:*" | ||
}, | ||
"dependenciesMeta": { | ||
"svelte-jester": { | ||
"injected": true | ||
} | ||
}, | ||
"jest": { | ||
"transform": { | ||
"^.+\\.svelte(?:\\.js)?$": [ | ||
"svelte-jester" | ||
] | ||
}, | ||
"moduleFileExtensions": [ | ||
"js", | ||
"svelte" | ||
], | ||
"extensionsToTreatAsEsm": [ | ||
".svelte" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"@testing-library/jest-dom" | ||
], | ||
"testEnvironment": "jsdom" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
export let name; | ||
let showGreeting = false; | ||
const handleClick = () => (showGreeting = true); | ||
</script> | ||
|
||
<button on:click={handleClick}>greet</button> | ||
{#if showGreeting} | ||
<p>hello {name}</p> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { mount, unmount, tick } from 'svelte' | ||
|
||
import Subject from './legacy.svelte' | ||
|
||
let component | ||
|
||
afterEach(() => { | ||
unmount(component) | ||
component = undefined | ||
}) | ||
|
||
test('render', () => { | ||
component = mount(Subject, { | ||
target: document.body, | ||
props: { name: 'alice' } | ||
}) | ||
|
||
const button = document.querySelector('button') | ||
|
||
expect(button).toHaveRole('button') | ||
}) | ||
|
||
test('interaction', async () => { | ||
component = mount(Subject, { | ||
target: document.body, | ||
props: { name: 'alice' } | ||
}) | ||
|
||
const button = document.querySelector('button') | ||
|
||
button.click() | ||
await tick() | ||
|
||
const message = document.querySelector('p') | ||
|
||
expect(message.textContent).toMatch(/hello alice/iu) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
let { name } = $props(); | ||
let showGreeting = $state(false); | ||
const handleClick = () => (showGreeting = true); | ||
</script> | ||
|
||
<button onclick={handleClick}>greet</button> | ||
{#if showGreeting} | ||
<p>hello {name}</p> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { mount, unmount, tick } from 'svelte' | ||
|
||
import Subject from './modern.svelte' | ||
|
||
let component | ||
|
||
afterEach(() => { | ||
unmount(component) | ||
component = undefined | ||
}) | ||
|
||
test('render', () => { | ||
component = mount(Subject, { | ||
target: document.body, | ||
props: { name: 'alice' } | ||
}) | ||
|
||
const button = document.querySelector('button') | ||
|
||
expect(button).toHaveRole('button') | ||
}) | ||
|
||
test('interaction', async () => { | ||
component = mount(Subject, { | ||
target: document.body, | ||
props: { name: 'alice' } | ||
}) | ||
|
||
const button = document.querySelector('button') | ||
|
||
button.click() | ||
await tick() | ||
|
||
const message = document.querySelector('p') | ||
|
||
expect(message.textContent).toMatch(/hello alice/iu) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const createCounter = () => { | ||
let count = $state(0) | ||
|
||
return { | ||
get count () { | ||
return count | ||
}, | ||
|
||
increment () { | ||
count = count + 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { test } from '@jest/globals' | ||
|
||
// TODO(mcous, 2024-05-23): this import fails | ||
// See https://github.com/svelteness/svelte-jester/pull/283 | ||
// import * as Subject from "./module.svelte.js"; | ||
const Subject = {} | ||
|
||
test.skip('get current count', () => { | ||
const subject = Subject.createCounter() | ||
const result = subject.count | ||
|
||
expect(result).toBe(0) | ||
}) | ||
|
||
test.skip('increment', () => { | ||
const subject = Subject.createCounter() | ||
|
||
subject.increment() | ||
const result = subject.count | ||
|
||
expect(result).toBe(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.