diff --git a/.changeset/green-garlics-warn.md b/.changeset/green-garlics-warn.md new file mode 100644 index 000000000000..6ee4326c186a --- /dev/null +++ b/.changeset/green-garlics-warn.md @@ -0,0 +1,5 @@ +--- +'create-svelte': patch +--- + +Add option to create integration tests with Playwright diff --git a/packages/create-svelte/bin.js b/packages/create-svelte/bin.js index 6eadd82e9f70..8439db01fc31 100755 --- a/packages/create-svelte/bin.js +++ b/packages/create-svelte/bin.js @@ -92,6 +92,14 @@ async function main() { initial: false, active: 'Yes', inactive: 'No' + }, + { + type: 'toggle', + name: 'playwright', + message: 'Add Playwright for browser testing?', + initial: false, + active: 'Yes', + inactive: 'No' } ], { @@ -124,6 +132,11 @@ async function main() { console.log(cyan(' https://github.com/sveltejs/prettier-plugin-svelte#options')); } + if (options.playwright) { + console.log(bold('✔ Playwright')); + console.log(cyan(' https://playwright.dev')); + } + console.log('\nInstall community-maintained integrations:'); console.log(cyan(' https://github.com/svelte-add/svelte-adders')); diff --git a/packages/create-svelte/scripts/update-template-repo-contents.js b/packages/create-svelte/scripts/update-template-repo-contents.js index 0cf14aa24880..54c93b629a8e 100644 --- a/packages/create-svelte/scripts/update-template-repo-contents.js +++ b/packages/create-svelte/scripts/update-template-repo-contents.js @@ -18,5 +18,6 @@ await create(repo, { template: 'default', eslint: false, typescript: false, - prettier: true + prettier: true, + playwright: false }); diff --git a/packages/create-svelte/shared/+playwright+default/tests/test.js b/packages/create-svelte/shared/+playwright+default/tests/test.js new file mode 100644 index 000000000000..c104fe8eb7ef --- /dev/null +++ b/packages/create-svelte/shared/+playwright+default/tests/test.js @@ -0,0 +1,6 @@ +import { expect, test } from '@playwright/test'; + +test('about page has expected h1', async ({ page }) => { + await page.goto('/about'); + expect(await page.textContent('h1')).toBe('About this app'); +}); diff --git a/packages/create-svelte/shared/+playwright+skeleton/tests/test.js b/packages/create-svelte/shared/+playwright+skeleton/tests/test.js new file mode 100644 index 000000000000..4e579377eed9 --- /dev/null +++ b/packages/create-svelte/shared/+playwright+skeleton/tests/test.js @@ -0,0 +1,6 @@ +import { expect, test } from '@playwright/test'; + +test('index page has expected h1', async ({ page }) => { + await page.goto('/'); + expect(await page.textContent('h1')).toBe('Welcome to SvelteKit'); +}); diff --git a/packages/create-svelte/shared/+playwright/package.json b/packages/create-svelte/shared/+playwright/package.json new file mode 100644 index 000000000000..0181674d4b01 --- /dev/null +++ b/packages/create-svelte/shared/+playwright/package.json @@ -0,0 +1,8 @@ +{ + "devDependencies": { + "@playwright/test": "^1.19.1" + }, + "scripts": { + "test": "playwright test" + } +} diff --git a/packages/create-svelte/shared/+playwright/playwright.config.js b/packages/create-svelte/shared/+playwright/playwright.config.js new file mode 100644 index 000000000000..448008a2f186 --- /dev/null +++ b/packages/create-svelte/shared/+playwright/playwright.config.js @@ -0,0 +1,9 @@ +/** @type {import('@playwright/test').PlaywrightTestConfig} */ +const config = { + webServer: { + command: 'npm run build && npm run preview', + port: 3000 + } +}; + +export default config; diff --git a/packages/create-svelte/types/internal.d.ts b/packages/create-svelte/types/internal.d.ts index 8be632663fd4..115e9296ea6c 100644 --- a/packages/create-svelte/types/internal.d.ts +++ b/packages/create-svelte/types/internal.d.ts @@ -4,6 +4,7 @@ export type Options = { typescript: boolean; prettier: boolean; eslint: boolean; + playwright: boolean; }; export type File = { @@ -11,7 +12,13 @@ export type File = { contents: string; }; -export type Condition = 'eslint' | 'prettier' | 'typescript' | 'skeleton' | 'default'; +export type Condition = + | 'eslint' + | 'prettier' + | 'typescript' + | 'playwright' + | 'skeleton' + | 'default'; export type Common = { files: Array<{