Skip to content

Commit

Permalink
feat: fix and migrate smoke tests to Playwright (microsoft#1961)
Browse files Browse the repository at this point in the history
* feat: migrate e2e tests to Playwright

* fix: OS dependency

* fix: race condition

* fix: increased launch timeout
  • Loading branch information
mxschmitt authored May 11, 2020
1 parent f6505d2 commit 1dd0635
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 150 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 8 * * *'

Expand All @@ -12,6 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: microsoft/playwright-github-action@v1
- name: Set up Node.js
uses: actions/setup-node@v1
with:
Expand Down Expand Up @@ -40,10 +44,11 @@ jobs:
run: |
npm run bundle
- name: Build Tests
run: |
npm run build-test
run: npm run build-test
- name: Run Smoke Test
run: |
npm run ciserver &
sleep 10
npm run test
BROWSER=chromium npm run test
BROWSER=firefox npm run test
BROWSER=webkit npm run test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dist/*.js
dist/fonts/*
out-ci/
.DS_Store
vscode
vscode
/typings-test
78 changes: 39 additions & 39 deletions ci/core.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
import * as puppeteer from 'puppeteer';
import * as playwright from 'playwright';
import { assert } from 'chai';

const APP = 'http://127.0.0.1:8080/dist/core.html';

let browser: puppeteer.Browser;
let page: puppeteer.Page;
const width = 800;
const height = 600;
let browser: playwright.Browser;
let page: playwright.Page;

describe('Basic loading', function (): void {
this.timeout(20000);
type BrowserType = "chromium" | "firefox" | "webkit"

after(() => {
browser.close();
});
const browserType: BrowserType = process.env.BROWSER as BrowserType || "chromium"

it('should fail because page has an error', async () => {
browser = await puppeteer.launch({
headless: process.argv.indexOf('--headless') !== -1,
args: [`--window-size=${width},${height}`, `--no-sandbox`]
});
before(async () => {
console.log(`Starting browser: ${browserType}`)
browser = await playwright[browserType].launch({
headless: process.argv.includes('--headless'),
});
});
after(async () => {
await browser.close();
});
beforeEach(async function () {
this.timeout(5 * 1000)
page = await browser.newPage({
viewport: {
width: 800,
height: 600
}
});
});
afterEach(async () => {
await page.close();
});

page = (await browser.pages())[0];
describe('Basic loading', function (): void {
this.timeout(20000);

it('should fail because page has an error', async () => {
const pageErrors: any[] = [];
page.on('pageerror', (e) => {
console.log(e);
pageErrors.push(e);
});

page.on('error', (e) => {
page.on('pageerror', (e) => {
console.log(e);
pageErrors.push(e);
});
Expand All @@ -46,19 +59,6 @@ describe('Basic loading', function (): void {
describe('API Integration Tests', function (): void {
this.timeout(20000);

before(async function (): Promise<any> {
browser = await puppeteer.launch({
headless: process.argv.indexOf('--headless') !== -1,
args: [`--window-size=${width},${height}`, `--no-sandbox`]
});
page = (await browser.pages())[0];
await page.setViewport({ width, height });
});

after(() => {
browser.close();
});

beforeEach(async () => {
await page.goto(APP);
});
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('API Integration Tests', function (): void {
instance.trigger('keyboard', 'type', {
text: 'a'
});
instance.trigger('keyboard', 'undo');
instance.getModel().undo();
})()
`);
assert.equal(await page.evaluate(`instance.getModel().getLineContent(1)`), 'from banana import *');
Expand All @@ -110,7 +110,7 @@ describe('API Integration Tests', function (): void {
})()
`);

await page.waitFor(1000);
await page.waitForTimeout(1000);

assert.deepEqual(await page.evaluate(`
[
Expand All @@ -123,13 +123,13 @@ describe('API Integration Tests', function (): void {
instance.getModel().getLineContent(7),
]
`), [
'# from banana import *',
'# ',
'# class Monkey:',
'# # Bananas the monkey can eat.',
'# capacity = 10',
'# def eat(self, N):',
'\t\t\'\'\'Make the monkey eat N bananas!\'\'\''
'# from banana import *',
'# ',
'# class Monkey:',
'# # Bananas the monkey can eat.',
'# capacity = 10',
'# def eat(self, N):',
'\t\t\'\'\'Make the monkey eat N bananas!\'\'\''
]);
});
});
3 changes: 2 additions & 1 deletion ci/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"rootDir": ".",
"outDir": "../out-ci/",
"types": [
"../node_modules/@types/mocha"
"../node_modules/@types/mocha",
"../node_modules/@types/node"
],
"sourceMap": true,
"removeComments": true,
Expand Down
Loading

0 comments on commit 1dd0635

Please sign in to comment.