Skip to content

Commit

Permalink
test: configure playwright for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Apr 27, 2020
1 parent 2792f43 commit 67404f4
Show file tree
Hide file tree
Showing 14 changed files with 578 additions and 77 deletions.
54 changes: 44 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
- v1-dependencies-
- run: yarn install --frozen-lockfile
- run:
name: Install project dependencies
command: yarn install --frozen-lockfile
- save_cache:
key: v1-dependencies-{{ checksum "yarn.lock" }}
paths: node_modules
Expand All @@ -28,28 +30,57 @@ jobs:
steps:
- attach_workspace:
at: ~/project
- run: |
yarn lint
yarn typescript
- run:
name: Lint files
command: yarn lint
- run:
name: Typecheck files
command: yarn typescript
unit-tests:
<<: *defaults
steps:
- attach_workspace:
at: ~/project
- run: |
yarn test --coverage
cat ./coverage/lcov.info | ./node_modules/.bin/codecov
- run:
name: Run unit tests
command: yarn test --coverage
- run:
name: Upload test coverage
command: cat ./coverage/lcov.info | ./node_modules/.bin/codecov
- store_artifacts:
path: coverage
destination: coverage
integration-tests:
<<: *defaults
steps:
- attach_workspace:
at: ~/project
- run:
name: Install Headless Chrome dependencies
command: |
sudo apt-get install -yq \
gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- run:
name: Build example for web
command: yarn example expo build:web --no-pwa
- run:
name: Run integration tests
command: yarn example test --maxWorkers=2
build-packages:
<<: *defaults
steps:
- attach_workspace:
at: ~/project
- run: |
yarn lerna run prepare
node scripts/check-types-path.js
- run:
name: Build packages in the monorepo
command: yarn lerna run prepare
- run:
name: Verify paths for types
command: node scripts/check-types-path.js

workflows:
version: 2
Expand All @@ -62,6 +93,9 @@ workflows:
- unit-tests:
requires:
- install-dependencies
- integration-tests:
requires:
- install-dependencies
- build-packages:
requires:
- install-dependencies
10 changes: 0 additions & 10 deletions example/e2e/.eslintrc.json

This file was deleted.

44 changes: 44 additions & 0 deletions example/e2e/__integration_tests__/Link.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { page } from '../config/setup-playwright';

beforeEach(async () => {
await page.click('[data-testid=LinkComponent]');
});

it('loads the article page', async () => {
expect(await page.evaluate(() => location.pathname + location.search)).toBe(
'/link-component/Article?author=Gandalf'
);
expect(
((await page.accessibility.snapshot()) as any)?.children?.find(
(it: any) => it.role === 'heading'
)?.name
).toBe('Article by Gandalf');
});

it('goes to the album page and goes back', async () => {
await page.click('[href="/link-component/Album"]');

expect(await page.evaluate(() => location.pathname + location.search)).toBe(
'/link-component/Album'
);

expect(
((await page.accessibility.snapshot()) as any)?.children?.find(
(it: any) => it.role === 'heading'
)?.name
).toBe('Album');

await page.click('[aria-label="Article by Gandalf, back"]');

await page.waitForNavigation();

expect(await page.evaluate(() => location.pathname + location.search)).toBe(
'/link-component/Article?author=Gandalf'
);

expect(
((await page.accessibility.snapshot()) as any)?.children?.find(
(it: any) => it.role === 'heading'
)?.name
).toBe('Article by Gandalf');
});
9 changes: 0 additions & 9 deletions example/e2e/__integration_tests__/index.test.js

This file was deleted.

13 changes: 13 additions & 0 deletions example/e2e/__integration_tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { page } from '../config/setup-playwright';

it('loads the example app', async () => {
const snapshot = await page.accessibility.snapshot();

// @ts-ignore
expect(snapshot?.children?.find((it) => it.role === 'heading')?.name).toBe(
'Examples'
);
const title = await page.$eval('[role=heading]', (el) => el.textContent);

expect(title).toBe('Examples');
});
6 changes: 0 additions & 6 deletions example/e2e/config.json

This file was deleted.

24 changes: 24 additions & 0 deletions example/e2e/config/setup-playwright.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-env jest */

import { chromium, Browser, BrowserContext, Page } from 'playwright';

let browser: Browser;
let context: BrowserContext;
let page: Page;

beforeAll(async () => {
browser = await chromium.launch();
});

afterAll(async () => {
await browser.close();
});

beforeEach(async () => {
context = await browser.newContext();
page = await context.newPage();

await page.goto('http://localhost:3579');
});

export { browser, context, page };
8 changes: 8 additions & 0 deletions example/e2e/config/setup-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { setup } from 'jest-dev-server';

export default async function () {
await setup({
command: 'yarn serve -l 3579 web-build',
port: 3579,
});
}
5 changes: 5 additions & 0 deletions example/e2e/config/teardown-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { teardown } from 'jest-dev-server';

export default async function () {
await teardown();
}
28 changes: 0 additions & 28 deletions example/e2e/init.js

This file was deleted.

6 changes: 6 additions & 0 deletions example/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testRegex: '/__integration_tests__/.*\\.(test|spec)\\.(js|tsx?)$',
globalSetup: './e2e/config/setup-server.tsx',
globalTeardown: './e2e/config/teardown-server.tsx',
setupFilesAfterEnv: ['./e2e/config/setup-playwright.tsx'],
};
8 changes: 7 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"web": "expo start:web",
"native": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios"
"ios": "react-native run-ios",
"test": "jest"
},
"dependencies": {
"@expo/vector-icons": "^10.0.0",
Expand All @@ -32,10 +33,15 @@
},
"devDependencies": {
"@expo/webpack-config": "^0.11.19",
"@types/jest-dev-server": "^4.2.0",
"@types/react": "^16.9.23",
"@types/react-native": "^0.60.22",
"babel-preset-expo": "^8.1.0",
"expo-cli": "^3.17.18",
"jest": "^25.2.7",
"jest-dev-server": "^4.4.0",
"playwright": "^0.14.0",
"serve": "^11.3.0",
"typescript": "^3.8.3"
}
}
1 change: 1 addition & 0 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export default function App() {
(name) => (
<List.Item
key={name}
testID={name}
title={SCREENS[name].title}
onPress={() => navigation.navigate(name)}
/>
Expand Down
Loading

0 comments on commit 67404f4

Please sign in to comment.