Skip to content

Commit fff6c3b

Browse files
add option to create tests with Playwright (#4056)
* add option to create tests with Playwright * typo * Update packages/create-svelte/bin.js Co-authored-by: Ben McCann <[email protected]> * fix * Update packages/create-svelte/bin.js Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Ben McCann <[email protected]>
1 parent 6895e5f commit fff6c3b

File tree

8 files changed

+57
-2
lines changed

8 files changed

+57
-2
lines changed

Diff for: .changeset/green-garlics-warn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-svelte': patch
3+
---
4+
5+
Add option to create integration tests with Playwright

Diff for: packages/create-svelte/bin.js

+13
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ async function main() {
9292
initial: false,
9393
active: 'Yes',
9494
inactive: 'No'
95+
},
96+
{
97+
type: 'toggle',
98+
name: 'playwright',
99+
message: 'Add Playwright for browser testing?',
100+
initial: false,
101+
active: 'Yes',
102+
inactive: 'No'
95103
}
96104
],
97105
{
@@ -124,6 +132,11 @@ async function main() {
124132
console.log(cyan(' https://github.com/sveltejs/prettier-plugin-svelte#options'));
125133
}
126134

135+
if (options.playwright) {
136+
console.log(bold('✔ Playwright'));
137+
console.log(cyan(' https://playwright.dev'));
138+
}
139+
127140
console.log('\nInstall community-maintained integrations:');
128141
console.log(cyan(' https://github.com/svelte-add/svelte-adders'));
129142

Diff for: packages/create-svelte/scripts/update-template-repo-contents.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ await create(repo, {
1818
template: 'default',
1919
eslint: false,
2020
typescript: false,
21-
prettier: true
21+
prettier: true,
22+
playwright: false
2223
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test('about page has expected h1', async ({ page }) => {
4+
await page.goto('/about');
5+
expect(await page.textContent('h1')).toBe('About this app');
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test('index page has expected h1', async ({ page }) => {
4+
await page.goto('/');
5+
expect(await page.textContent('h1')).toBe('Welcome to SvelteKit');
6+
});
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"devDependencies": {
3+
"@playwright/test": "^1.19.1"
4+
},
5+
"scripts": {
6+
"test": "playwright test"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('@playwright/test').PlaywrightTestConfig} */
2+
const config = {
3+
webServer: {
4+
command: 'npm run build && npm run preview',
5+
port: 3000
6+
}
7+
};
8+
9+
export default config;

Diff for: packages/create-svelte/types/internal.d.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ export type Options = {
44
typescript: boolean;
55
prettier: boolean;
66
eslint: boolean;
7+
playwright: boolean;
78
};
89

910
export type File = {
1011
name: string;
1112
contents: string;
1213
};
1314

14-
export type Condition = 'eslint' | 'prettier' | 'typescript' | 'skeleton' | 'default';
15+
export type Condition =
16+
| 'eslint'
17+
| 'prettier'
18+
| 'typescript'
19+
| 'playwright'
20+
| 'skeleton'
21+
| 'default';
1522

1623
export type Common = {
1724
files: Array<{

0 commit comments

Comments
 (0)