-
Notifications
You must be signed in to change notification settings - Fork 3.4k
breaking: remove support for svelte 4 and support svelte 5 #30700
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import { createEntries } from '@cypress/mount-utils/create-rollup-entry.mjs' | ||
|
||
const config = { | ||
external: [ | ||
|
||
'svelte', | ||
], | ||
} | ||
|
||
// updated respectExternal to false due to this issue: https://github.com/Swatinem/rollup-plugin-dts/issues/162#issuecomment-1702374232 | ||
export default createEntries({ formats: ['es', 'cjs'], input: 'src/index.ts', dtsOptions: { respectExternal: false } }) | ||
export default createEntries({ formats: ['es', 'cjs'], input: 'src/index.ts', dtsOptions: { respectExternal: false }, config }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,33 +2,25 @@ import { | |
getContainerEl, | ||
setupHooks, | ||
} from '@cypress/mount-utils' | ||
import type { ComponentConstructorOptions, ComponentProps, SvelteComponent } from 'svelte' | ||
import { mount as svelteMount, unmount as svelteUnmount } from 'svelte' | ||
import type { MountOptions, Component } from 'svelte' | ||
|
||
const DEFAULT_COMP_NAME = 'unknown' | ||
|
||
type SvelteConstructor<T> = new (...args: any[]) => T; | ||
type SvelteComponentOptions<T extends SvelteComponent> = Omit< | ||
ComponentConstructorOptions<ComponentProps<T>>, | ||
'hydrate' | 'target' | '$$inline' | ||
>; | ||
|
||
export interface MountOptions<T extends SvelteComponent> | ||
extends SvelteComponentOptions<T> { | ||
log?: boolean | ||
} | ||
|
||
export interface MountReturn<T extends SvelteComponent> { | ||
component: T | ||
export interface MountReturn{ | ||
component: Record<string, any> | ||
} | ||
|
||
let componentInstance: SvelteComponent | undefined | ||
let componentInstance: Record<string, any> | undefined | ||
|
||
const cleanup = () => { | ||
componentInstance?.$destroy() | ||
if (componentInstance) { | ||
svelteUnmount(componentInstance) | ||
} | ||
} | ||
|
||
// Extract the component name from the object passed to mount | ||
const getComponentDisplayName = <T extends SvelteComponent>(Component: SvelteConstructor<T>): string => { | ||
const getComponentDisplayName = (Component: Component<Record<string, any>, Record<string, any>, any>): string => { | ||
if (Component.name) { | ||
const [, match] = /Proxy\<(\w+)\>/.exec(Component.name) || [] | ||
|
||
|
@@ -41,7 +33,7 @@ const getComponentDisplayName = <T extends SvelteComponent>(Component: SvelteCon | |
/** | ||
* Mounts a Svelte component inside the Cypress browser | ||
* | ||
* @param {SvelteConstructor<T>} Component Svelte component being mounted | ||
* @param {Record<string, any>} Component Svelte component being mounted | ||
* @param {MountReturn<T extends SvelteComponent>} options options to customize the component being mounted | ||
* @returns Cypress.Chainable<MountReturn> | ||
* | ||
|
@@ -56,19 +48,24 @@ const getComponentDisplayName = <T extends SvelteComponent>(Component: SvelteCon | |
* | ||
* @see {@link https://on.cypress.io/mounting-svelte} for more details. | ||
*/ | ||
export function mount<T extends SvelteComponent> ( | ||
Component: SvelteConstructor<T>, | ||
options: MountOptions<T> = {}, | ||
): Cypress.Chainable<MountReturn<T>> { | ||
export function mount ( | ||
Component: Component<Record<string, any>, Record<string, any>, any>, | ||
|
||
options: Omit<MountOptions, 'target'> & {log?: boolean} = {}, | ||
): Cypress.Chainable<MountReturn> { | ||
// In Svelte 5, the component name is no longer easily discoverable and logs as "wrapper" | ||
// so we default the logging of it to false as it doesn't provide a lot of value | ||
options.log = options.log || false | ||
|
||
|
||
return cy.then(() => { | ||
// Remove last mounted component if cy.mount is called more than once in a test | ||
cleanup() | ||
|
||
const target = getContainerEl() | ||
|
||
const ComponentConstructor = ((Component as any).default || Component) as SvelteConstructor<T> | ||
const ComponentConstructor = ((Component as any).default || Component) as Component<Record<string, any>, Record<string, any>, any> | ||
|
||
componentInstance = new ComponentConstructor({ | ||
// @see https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes | ||
componentInstance = svelteMount(ComponentConstructor, { | ||
target, | ||
...options, | ||
}) | ||
|
@@ -85,7 +82,7 @@ export function mount<T extends SvelteComponent> ( | |
}) | ||
} | ||
}) | ||
.wrap({ component: componentInstance as T }, { log: false }) | ||
.wrap({ component: componentInstance as Record<string, any> }, { log: false }) | ||
}) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,16 @@ We will also attempt to scaffold a configuration file for projects using React a | |
|
||
### Supported Frameworks and Libraries | ||
|
||
| Name | Version | Dev Server | Version | Library | Component Adaptor | Example Project | | ||
| ---------------- | ------- | ---------- | -------- | -------------- | -------------------------- | ------------------------------------------------------------------- | | ||
| React | - | Vite | 4.x, 5.x | React 16, 17 | `@cypress/react@latest` | [Link](../../system-tests/projects/react-vite-ts-configured) | | ||
| React | - | Webpack | 4.x, 5.x | React 16, 17 | `@cypress/vue@latest` | [Link](../../system-tests/projects/react18) | | ||
| Vue | - | Vite | 4.x, 5.x | Vue 3 | `@cypress/react@latest` | [Link](../../system-tests/projects/vue3-vite-ts-configured) | | ||
| Vue | - | Webpack | 4.x, 5.x | Vue 3 | `@cypress/vue@latest` | [Link](../../system-tests/projects/vue3-webpack-ts-configured) | | ||
| Angular | - | Webpack | 5.x | Angular 17, 18 | `@cypress/angular@latest` | [Link](../../system-tests/projects/angular-cli-configured) | | ||
| Svelte | - | Vite | 4.x, 5.x | Svelte 4 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-vite-configured) | | ||
| Svelte | - | Webpack | 4.x, 5.x | Svelte 4 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-webpack-configured) | | ||
| Next.js | 14.x | Webpack | 4.x, 5.x | React 18 | `@cypress/react@latest` | [Link](../../system-tests/projects/nextjs-configured) | | ||
| Name | Version| Dev Server | Version | Library | Component Adaptor | Example Project | | ||
| ---------------- | -------| ---------- | ------- | ------------------ | -------------------------- | ------------------------------------------------------------------- | | ||
| React | - | Vite | 4, 5 | React 18, 19 | `@cypress/react@latest` | [Link](../../system-tests/projects/react-vite-ts-configured) | | ||
|
||
| React | - | Webpack | 4, 5 | React 18, 19 | `@cypress/vue@latest` | [Link](../../system-tests/projects/react18) | | ||
| Vue | - | Vite | 4, 5, 6 | Vue 3 | `@cypress/react@latest` | [Link](../../system-tests/projects/vue3-vite-ts-configured) | | ||
| Vue | - | Webpack | 4, 5 | Vue 3 | `@cypress/vue@latest` | [Link](../../system-tests/projects/vue3-webpack-ts-configured) | | ||
| Angular | - | Webpack | 5 | Angular 17, 18, 19 | `@cypress/angular@latest` | [Link](../../system-tests/projects/angular-cli-configured) | | ||
| Svelte | - | Vite | 4, 5, 6 | Svelte 5 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-vite-configured) | | ||
| Svelte | - | Webpack | 4, 5 | Svelte 5 | `@cypress/svelte@latest` | [Link](../../system-tests/projects/svelte-webpack-configured) | | ||
| Next.js | 14, 15 | Webpack | 4, 5 | React 18, 19 | `@cypress/react@latest` | [Link](../../system-tests/projects/nextjs-configured) | | ||
|
||
### Adding More Projects | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { mount } from 'cypress/svelte' | ||
import '../../src/app.css' | ||
|
||
// Augment the Cypress namespace to include type definitions for | ||
// your custom command. | ||
// Alternatively, can be defined in cypress/support/component.d.ts | ||
// with a <reference path="./component" /> at the top of your spec. | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
mount: typeof mount | ||
} | ||
} | ||
} | ||
|
||
Cypress.Commands.add('mount', mount) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<script> | ||
let count = 0 | ||
<script lang="ts"> | ||
|
||
let count: number = $state(0) | ||
const increment = () => { | ||
count += 1 | ||
} | ||
</script> | ||
|
||
<button on:click={increment}> | ||
<button onclick={increment}> | ||
count is {count} | ||
</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts"> | ||
let { count } = $props() | ||
count = count || 0 | ||
</script> | ||
|
||
<button> | ||
count is {count} | ||
</button> |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { mount } from 'svelte' | ||
import './app.css' | ||
import App from './App.svelte' | ||
|
||
const app = mount(App, { | ||
target: document.getElementById('app')!, | ||
}) | ||
|
||
export default app |
Uh oh!
There was an error while loading. Please reload this page.