Skip to content

Commit

Permalink
test: replace Spectron with Playwright (azerothcore#1583)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoBorzi authored Dec 25, 2021
1 parent 1a385fc commit 0ce4934
Show file tree
Hide file tree
Showing 11 changed files with 1,619 additions and 2,995 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Unit and Integration tests
uses: nick-invision/retry@v2
with:
max_attempts: 3
max_attempts: 5
command: npm run test-ci
timeout_minutes: 20
- name: Build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ testem.log
/e2e/*.js
!/e2e/protractor.conf.js
/e2e/*.map
/e2e/tracing

# System Files
.DS_Store
Expand Down
43 changes: 0 additions & 43 deletions e2e/common-setup.ts

This file was deleted.

31 changes: 0 additions & 31 deletions e2e/main.e2e.ts

This file was deleted.

54 changes: 54 additions & 0 deletions e2e/main.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright';
import { test, expect } from '@playwright/test';
const PATH = require('path');

test.describe('Check Home Page', async () => {
let app: ElectronApplication;
let firstWindow: Page;
let context: BrowserContext;

test.beforeAll(async () => {
app = await electron.launch({ args: [PATH.join(__dirname, '../main.js'), PATH.join(__dirname, '../app/package.json')] });
context = app.context();
await context.tracing.start({ screenshots: true, snapshots: true });
firstWindow = await app.firstWindow();
});

test('Launch electron app', async () => {
const windowState: { isVisible: boolean; isDevToolsOpened: boolean; isCrashed: boolean } = await app.evaluate(async (process) => {
const mainWindow = process.BrowserWindow.getAllWindows()[0];

const getState = () => ({
isVisible: mainWindow.isVisible(),
isDevToolsOpened: mainWindow.webContents.isDevToolsOpened(),
isCrashed: mainWindow.webContents.isCrashed(),
});

return new Promise((resolve) => {
if (mainWindow.isVisible()) {
resolve(getState());
} else {
mainWindow.once('ready-to-show', () => setTimeout(() => resolve(getState()), 0));
}
});
});

expect(windowState.isVisible).toBeTruthy();
expect(windowState.isDevToolsOpened).toBeFalsy();
expect(windowState.isCrashed).toBeFalsy();
});

test('sqlite should correctly work', async () => {
const sleep = (time) => new Promise((r) => setTimeout(r, time));
await sleep(500);
const selector = '#sqlite-e2e-test';
const expectedText = 'Tricks and Treats of Azeroth';
const element = await firstWindow.$(selector);
const text = await element.getAttribute('e2e');
expect(text).toEqual(expectedText);
});

test.afterAll(async () => {
await context.tracing.stop({ path: 'e2e/tracing/trace.zip' });
});
});
19 changes: 19 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
testDir: '.',
timeout: 45000,
outputDir: './screenshots',
use: {
headless: false,
viewport: { width: 1280, height: 720 },
launchOptions: {
slowMo: 1000,
},
trace: 'on',
},
expect: {
toMatchSnapshot: { threshold: 0.2 },
},
};

module.exports = config;
4 changes: 2 additions & 2 deletions e2e/tsconfig.e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"types": ["mocha"]
"types": ["node"]
},
"include": ["**/*.ts"]
"include": ["**.spec.ts"]
}
3 changes: 0 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import * as path from 'path';
import * as url from 'url';
import * as settings from 'electron-settings';

// Initialize remote module
require('@electron/remote/main').initialize();

let win, serve;
const args = process.argv.slice(1);
serve = args.some((val) => val === '--serve');
Expand Down
Loading

0 comments on commit 0ce4934

Please sign in to comment.