Skip to content

Commit

Permalink
add playwrite tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbonothing64 committed Dec 11, 2023
1 parent 0a03c3f commit 8dac82c
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 48 deletions.
4 changes: 4 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
86 changes: 44 additions & 42 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
{
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-vercel": "^3.1.0",
"@sveltejs/kit": "^1.27.7",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"autoprefixer": "^10.4.16",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.30.0",
"postcss": "^8.4.32",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.0.0",
"svelte": "^4.2.8",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.3.6",
"tslib": "^2.4.1",
"typescript": "^5.3.3",
"vite": "^4.5.1"
},
"type": "module",
"dependencies": {
"@popperjs/core": "^2.11.8",
"flowbite": "^2.2.0",
"flowbite-svelte": "^0.44.20",
"svelte-french-toast": "^1.2.0",
"tailwind-merge": "^2.1.0",
"zod": "^3.22.4",
"zod-form-data": "^2.0.2"
}
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@playwright/test": "^1.40.1",
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-vercel": "^3.1.0",
"@sveltejs/kit": "^1.27.7",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"autoprefixer": "^10.4.16",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.30.0",
"postcss": "^8.4.32",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.0.0",
"svelte": "^4.2.8",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.3.6",
"tslib": "^2.4.1",
"typescript": "^5.3.3",
"vite": "^4.5.1"
},
"type": "module",
"dependencies": {
"@popperjs/core": "^2.11.8",
"flowbite": "^2.2.0",
"flowbite-svelte": "^0.44.20",
"svelte-french-toast": "^1.2.0",
"tailwind-merge": "^2.1.0",
"zod": "^3.22.4",
"zod-form-data": "^2.0.2"
}
}
77 changes: 77 additions & 0 deletions app/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
61 changes: 55 additions & 6 deletions app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions app/tests/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { test, expect } from '@playwright/test';

test('test page load', async ({ page }) => {
await page.goto('http://localhost:5173/');
await expect(page.getByRole('heading', { name: '🐜 Minimise for Python Tutor' })).toBeVisible();
await expect(page.getByText('/5600')).toBeVisible();
});

test('test minimise', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByPlaceholder('Your python code...').click();
await page
.getByPlaceholder('Your python code...')
.fill(
'"""Hello world"""\n\n\ndef main():\n """Hello world"""\n print("hi" + "bye")\n\n\nmain()'
);
await page.getByRole('button', { name: 'Get link' }).click();
await expect(page.getByRole('heading', { name: 'Minimised code' })).toBeVisible();
await page.getByText('Your code was reduced by 98').click();
await page.locator('#link').click();
await expect(page.locator('#link')).toBeVisible();
await page.getByRole('button', { name: 'Show Code' }).click();
await page.getByRole('textbox', { name: 'Your python code...' }).click();
});

// test('test minimise tiny', async ({ page }) => {
// await page.goto('http://localhost:5173/');
// await page.getByPlaceholder('Your python code...').click();
// await page
// .getByPlaceholder('Your python code...')
// .fill(
// '"""Hello world"""\n\n\ndef main():\n """Hello world"""\n print("hi" + "bye")\n\n\nmain()'
// );
// await page.getByLabel('Tiny Indent').check();
// await page.getByRole('button', { name: 'Get link' }).click();
// await expect(page.getByRole('heading', { name: 'Minimised code' })).toBeVisible();
// await page.getByText('Your code was reduced by 98').click();
// await page.locator('#link').click();
// await expect(page.locator('#link')).toBeVisible();
// await page.getByRole('button', { name: 'Show Code' }).click();
// await page.getByRole('textbox', { name: 'Your python code...' }).click();
// });

1 comment on commit 8dac82c

@vercel
Copy link

@vercel vercel bot commented on 8dac82c Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.