Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(repo): add preview app tests with playwright #102

Merged
merged 8 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ jobs:

- name: Run Tests
run: moon run :test --affected --concurrency 1 --remote

- name: Run Preview Test
# Note: We're running `pnpm i` again so that pnpm places the `email` bin in root node_modules
# We'll need that for the preview tests below
run: |
pnpm i
moon app-test:playwright
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ dist
**/.vitepress/cache

packages/**/tsconfig.json
packages/jsx-email/README.md
packages/jsx-email/README.md

test-results
playwright-report
blob-report
playwright/.cache/
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

# npm options
auth-type=legacy
Expand Down
68 changes: 0 additions & 68 deletions apps/demo/emails/local-assets.tsx

This file was deleted.

89 changes: 0 additions & 89 deletions apps/demo/fixtures/jsx-template.jsx

This file was deleted.

65 changes: 65 additions & 0 deletions apps/test/fixtures/base.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
Body,
Button,
ColorScheme,
Column,
Container,
Font,
Head,
Heading,
Hr,
Html,
Img,
Link,
Markdown,
Preview,
// QrCode,
Row,
Section,
Text
} from 'jsx-email';

export const Template = () => (
<Html>
<ColorScheme />
<Head />
<Preview>Preview Content</Preview>
<Body>
<Container>
<Section>
<Button href="https://jsx.email">Button Content</Button>
<Font
fontFamily="Roboto"
fallbackFontFamily="Verdana"
webFont={{
format: 'woff2',
url: 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2'
}}
fontWeight={400}
fontStyle="normal"
/>
<Heading>Heading Content</Heading>
<Hr />
<Img src="https://about.google/assets-main/img/glue-google-solid-logo.svg" />
<Link href="https://jsx.email"></Link>
<Markdown
markdownCustomStyles={{
codeInline: { background: 'grey' },
h1: { color: 'red' },
h2: { color: 'blue' }
}}
markdownContainerStyles={{
border: 'solid 1px black',
padding: '12px'
}}
>{`# Hello, World!`}</Markdown>
{/* <QrCode src="https://example.com" alt="QR Code" size={300} correctionLevel="H" /> */}
<Row>
<Column>Column</Column>
</Row>
<Text>Text Content</Text>
</Section>
</Container>
</Body>
</Html>
);
File renamed without changes.
18 changes: 18 additions & 0 deletions apps/test/fixtures/local-assets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Body, Html, Img, Link } from 'jsx-email';

export const TemplateName = 'local-assets';

// @ts-ignore
const baseUrl = import.meta.resolve('./static/');

export const Template = () => {
const catUrl = `${baseUrl}cat.jpeg`;
return (
<Html>
<Body>
<Img id="image" src={catUrl} alt="Cat" width="200" height="200" />
<Link href={catUrl}>{catUrl}</Link>
</Body>
</Html>
);
};
Binary file added apps/test/fixtures/static/cat.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
26 changes: 26 additions & 0 deletions apps/test/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# https://moonrepo.dev/docs/config/tasks
$schema: 'https://moonrepo.dev/schemas/tasks.json'

workspace:
inheritedTasks:
exclude: ['build', 'compile', 'release', 'test']

tasks:
dev:
command: email preview fixtures
options:
cache: false

install:
command: playwright install --with-deps
deps:
- ~:install
options:
cache: false

playwright:
command: playwright test -x
deps:
- ~:install
options:
cache: false
21 changes: 21 additions & 0 deletions apps/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "app-test",
"version": "0.0.0",
"private": true,
"description": "A project to demo and test the `email preview` CLI command",
"license": "MIT",
"peerDependencies": {
"react": "^18.2.0"
},
"dependencies": {
"@playwright/test": "^1.40.1",
"dedent": "^1.5.1",
"diffable-html": "^5.0.0",
"jsx-email": "workspace:*",
"superstruct": "^1.0.3"
},
"devDependencies": {
"@types/diffable-html": "^5.0.2",
"@types/node": "20.10.5"
}
}
42 changes: 42 additions & 0 deletions apps/test/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable import/no-default-export */
import { defineConfig, devices } from '@playwright/test';

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
forbidOnly: !!process.env.CI,
fullyParallel: true,
maxFailures: 1,
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
}

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

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] }
// }
],
reporter: 'list',
retries: process.env.CI ? 2 : 0,
snapshotPathTemplate:
'{testDir}/.snapshots/{testFileDir}/{testFileName}-{arg}{-projectName}{ext}',
testDir: './tests',
use: {
baseURL: 'http://localhost:55420',
trace: 'on-first-retry'
},
webServer: {
command: 'moon app-test:dev',
reuseExistingServer: !process.env.CI,
url: 'http://localhost:55420'
},
workers: process.env.CI ? 1 : undefined

Check warning on line 41 in apps/test/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected use of undefined

Check warning on line 41 in apps/test/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected use of undefined

Check warning on line 41 in apps/test/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected use of undefined

Check warning on line 41 in apps/test/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected use of undefined

Check warning on line 41 in apps/test/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected use of undefined
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2 class="font-medium">JSX Email Preview</h2><p class="mt-2 mb-4 text-sm">Start creating an email template by running <code class="inline-code">email create &lt;template-name&gt;</code><br><br>Run <code class="inline-code">email help create</code> for a list of options<br><br>Happy coding!</p><a href="https://jsx.email/docs/introduction" class="mt-4 inline-block focus:ring-2 focus:ring-white/20 focus:outline-none focus:bg-white/90 text-base py-2 px-4 rounded gap-2 bg-cta-bg text-cta-text hover:bg-cta-bg-hover">Read our Documentation</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2 class="font-medium">JSX Email Preview</h2><p class="mt-2 mb-4 text-sm">Start creating an email template by running <code class="inline-code">email create &lt;template-name&gt;</code><br><br>Run <code class="inline-code">email help create</code> for a list of options<br><br>Happy coding!</p><a href="https://jsx.email/docs/introduction" class="mt-4 inline-block focus:ring-2 focus:ring-white/20 focus:outline-none focus:bg-white/90 text-base py-2 px-4 rounded gap-2 bg-cta-bg text-cta-text hover:bg-cta-bg-hover">Read our Documentation</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2 class="font-medium">JSX Email Preview</h2><p class="mt-2 mb-4 text-sm">Start creating an email template by running <code class="inline-code">email create &lt;template-name&gt;</code><br><br>Run <code class="inline-code">email help create</code> for a list of options<br><br>Happy coding!</p><a href="https://jsx.email/docs/introduction" class="mt-4 inline-block focus:ring-2 focus:ring-white/20 focus:outline-none focus:bg-white/90 text-base py-2 px-4 rounded gap-2 bg-cta-bg text-cta-text hover:bg-cta-bg-hover">Read our Documentation</a>
Loading
Loading