-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding E2E testing with Playwright (#3349)
* adding Tailwind E2E tests with Playwright * package.json updates * adding e2e tests to CI workflow * using e2e for dev tests, mocha for build tests * refactor: sharing test-utils helpers * chore: update lockfile * Adding contributing docs * Revert "refactor: sharing test-utils helpers" This reverts commit 48496f4. * refactor: simpler solution to resolving e2e test fixtures * chore: updating lockfile * refactor: cleaning up how URLs are resolved in e2e tests * install playwright deps in CI * trying pnpm playwright install to fix version mismatch
- Loading branch information
Tony Sullivan
authored
May 15, 2022
1 parent
65b448b
commit 2b622b5
Showing
17 changed files
with
1,016 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,48 @@ jobs: | |
- name: Test | ||
run: pnpm run test | ||
|
||
e2e: | ||
name: 'E2E: ${{ matrix.os }} (node@${{ matrix.node_version }})' | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
ASTRO_TELEMETRY_DISABLED: true | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node_version: [14, 16] | ||
include: | ||
- os: windows-latest | ||
node_version: 16 | ||
- os: macos-latest | ||
node_version: 16 | ||
fail-fast: false | ||
needs: | ||
- build | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PNPM | ||
uses: pnpm/[email protected] | ||
|
||
- name: Setup node@${{ matrix.node_version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node_version }} | ||
cache: 'pnpm' | ||
|
||
- name: Download Build Artifacts | ||
uses: actions/download-artifact@v3 | ||
|
||
- name: Extract Artifacts | ||
run: ./.github/extract-artifacts.sh | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Test | ||
run: pnpm run test:e2e | ||
|
||
smoke: | ||
name: 'Test (Smoke) ${{ matrix.os }}' | ||
runs-on: ${{ matrix.os }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import tailwind from '@astrojs/tailwind'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [tailwind()], | ||
vite: { | ||
build: { | ||
assetsInlineLimit: 0, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/e2e-tailwindcss", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/tailwind": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require('path'); | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: { | ||
config: path.join(__dirname, 'tailwind.config.js'), // update this if your path differs! | ||
}, | ||
autoprefixer: {} | ||
}, | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/astro/e2e/fixtures/tailwindcss/src/components/Button.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
let { type = 'button' } = Astro.props; | ||
--- | ||
|
||
<button | ||
class="py-2 px-4 lg:py-3 lg:px-5 bg-purple-600 text-white font-[900] rounded-lg shadow-md hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-400 focus:ring-opacity-75" | ||
{type} | ||
> | ||
<slot /> | ||
</button> |
1 change: 1 addition & 0 deletions
1
packages/astro/e2e/fixtures/tailwindcss/src/components/Complex.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div id="complex" class="w-10/12 2xl:w-[80%]"></div> |
18 changes: 18 additions & 0 deletions
18
packages/astro/e2e/fixtures/tailwindcss/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
// Component Imports | ||
import Button from '../components/Button.astro'; | ||
import Complex from '../components/Complex.astro'; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/x-icon" href="/favicon.ico" /> | ||
<title>Astro + TailwindCSS</title> | ||
</head> | ||
|
||
<body class="bg-dawn text-midnight"> | ||
<Button>I’m a Tailwind Button!</Button> | ||
<Complex /> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
packages/astro/e2e/fixtures/tailwindcss/src/pages/markdown-page.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: "Markdown + Tailwind" | ||
setup: | | ||
import Button from '../components/Button.astro'; | ||
import Complex from '../components/Complex.astro'; | ||
--- | ||
|
||
<div class="grid place-items-center h-screen content-center"> | ||
<Button>Tailwind Button in Markdown!</Button> | ||
<Complex /> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
packages/astro/e2e/fixtures/tailwindcss/tailwind.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
content: [path.join(__dirname, 'src/**/*.{astro,html,js,jsx,md,svelte,ts,tsx,vue}')], | ||
theme: { | ||
extend: { | ||
colors: { | ||
dawn: '#f3e9fa', | ||
dusk: '#514375', | ||
midnight: '#31274a', | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { test as base, expect } from '@playwright/test'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
const test = base.extend({ | ||
astro: async ({}, use) => { | ||
const fixture = await loadFixture({ root: './fixtures/tailwindcss/' }); | ||
await use(fixture); | ||
}, | ||
}); | ||
|
||
let devServer; | ||
|
||
test.beforeAll(async ({ astro }) => { | ||
devServer = await astro.startDevServer(); | ||
}); | ||
|
||
test.afterAll(async ({ astro }) => { | ||
await devServer.stop(); | ||
}); | ||
|
||
test('Tailwind CSS', async ({ page, astro }) => { | ||
await page.goto(astro.resolveUrl('/')); | ||
|
||
await test.step('body', async () => { | ||
const body = page.locator('body'); | ||
|
||
await expect(body, 'should have classes').toHaveClass('bg-dawn text-midnight'); | ||
await expect(body, 'should have background color').toHaveCSS( | ||
'background-color', | ||
'rgb(243, 233, 250)' | ||
); | ||
await expect(body, 'should have color').toHaveCSS('color', 'rgb(49, 39, 74)'); | ||
}); | ||
|
||
await test.step('button', async () => { | ||
const button = page.locator('button'); | ||
|
||
await expect(button, 'should have bg-purple-600').toHaveClass(/bg-purple-600/); | ||
await expect(button, 'should have background color').toHaveCSS( | ||
'background-color', | ||
'rgb(147, 51, 234)' | ||
); | ||
|
||
await expect(button, 'should have lg:py-3').toHaveClass(/lg:py-3/); | ||
await expect(button, 'should have padding bottom').toHaveCSS('padding-bottom', '12px'); | ||
await expect(button, 'should have padding top').toHaveCSS('padding-top', '12px'); | ||
|
||
await expect(button, 'should have font-[900]').toHaveClass(/font-\[900\]/); | ||
await expect(button, 'should have font weight').toHaveCSS('font-weight', '900'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { loadFixture as baseLoadFixture } from '../test/test-utils.js'; | ||
|
||
export function loadFixture(inlineConfig) { | ||
if (!inlineConfig || !inlineConfig.root) | ||
throw new Error("Must provide { root: './fixtures/...' }"); | ||
|
||
// resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath | ||
// without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` | ||
return baseLoadFixture({ | ||
...inlineConfig, | ||
root: new URL(inlineConfig.root, import.meta.url).toString() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.