Skip to content

Commit

Permalink
add option to create tests with Playwright (#4056)
Browse files Browse the repository at this point in the history
* add option to create tests with Playwright

* typo

* Update packages/create-svelte/bin.js

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

* fix

* Update packages/create-svelte/bin.js

Co-authored-by: Rich Harris <richard.a.harris@gmail.com>

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
Rich-Harris and benmccann committed Feb 23, 2022
1 parent 6895e5f commit fff6c3b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-garlics-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Add option to create integration tests with Playwright
13 changes: 13 additions & 0 deletions packages/create-svelte/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
],
{
Expand Down Expand Up @@ -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'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ await create(repo, {
template: 'default',
eslint: false,
typescript: false,
prettier: true
prettier: true,
playwright: false
});
Original file line number Diff line number Diff line change
@@ -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');
});
Original file line number Diff line number Diff line change
@@ -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');
});
8 changes: 8 additions & 0 deletions packages/create-svelte/shared/+playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"devDependencies": {
"@playwright/test": "^1.19.1"
},
"scripts": {
"test": "playwright test"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
webServer: {
command: 'npm run build && npm run preview',
port: 3000
}
};

export default config;
9 changes: 8 additions & 1 deletion packages/create-svelte/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ export type Options = {
typescript: boolean;
prettier: boolean;
eslint: boolean;
playwright: boolean;
};

export type File = {
name: string;
contents: string;
};

export type Condition = 'eslint' | 'prettier' | 'typescript' | 'skeleton' | 'default';
export type Condition =
| 'eslint'
| 'prettier'
| 'typescript'
| 'playwright'
| 'skeleton'
| 'default';

export type Common = {
files: Array<{
Expand Down

0 comments on commit fff6c3b

Please sign in to comment.