Skip to content

Commit

Permalink
refactor: integrate playwright and web workers support
Browse files Browse the repository at this point in the history
  • Loading branch information
4gray committed Jul 2, 2022
1 parent e3a6e12 commit c578956
Show file tree
Hide file tree
Showing 11 changed files with 1,206 additions and 208 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.worker.ts
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

# compiled output
/dist
/build
/tmp
/out-tsc
/app-builds
/release
/e2e/tracing
/e2e/screenshots
/test-results
api.js
epg-worker.js
main.js
Expand Down
8 changes: 5 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"outputPath": "dist",
"outputPath": "build",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
Expand All @@ -38,7 +38,8 @@
"replaceDuplicatePlugins": true
},
"serviceWorker": true,
"ngswConfigPath": "ngsw-config.json"
"ngswConfigPath": "ngsw-config.json",
"webWorkerTsConfig": "tsconfig.worker.json"
},
"configurations": {
"dev": {
Expand Down Expand Up @@ -131,7 +132,8 @@
"customWebpackConfig": {
"path": "./angular.webpack.js",
"replaceDuplicatePlugins": true
}
},
"webWorkerTsConfig": "tsconfig.worker.json"
}
},
"lint": {
Expand Down
58 changes: 58 additions & 0 deletions e2e/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect, test } from '@playwright/test';
import {
BrowserContext,
ElectronApplication,
Page,
_electron as electron,
} from 'playwright';
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, '../electron/main.js'),
PATH.join(__dirname, '../electron/package.json'),
],
});
context = app.context();
//await context.tracing.start({ screenshots: true, snapshots: true });

firstWindow = await app.windows()[0];
const isMainWindow = (await firstWindow.title()) === 'IPTVnator';
if (!isMainWindow) {
firstWindow = await app.windows()[1];
}
await firstWindow.waitForLoadState('domcontentloaded');
});

test('Launch electron app', async () => {
const windowState = await app.evaluate(async (process) => {
let mainWindow = process.BrowserWindow.getAllWindows()[0];
const isMainWindow = mainWindow.title === 'IPTVnator';
if (!isMainWindow) {
mainWindow = process.BrowserWindow.getAllWindows()[1];
}
return {
isVisible: mainWindow.isVisible(),
isDevToolsOpened: mainWindow.webContents.isDevToolsOpened(),
isCrashed: mainWindow.webContents.isCrashed(),
};
});

expect(windowState.isVisible).toBeTruthy();
expect(windowState.isDevToolsOpened).toBeFalsy();
expect(windowState.isCrashed).toBeFalsy();
expect(app.windows()).toHaveLength(2);
});

test('Check title', async ({ page }) => {
const title = await firstWindow.title();
await firstWindow.screenshot({ path: 'e2e/screenshots/intro.png' });
expect(title).toBe('IPTVnator');
});
});
8 changes: 8 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
testDir: '.',
maxFailures: 2,
};

export default config;
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
preset: 'jest-preset-angular',
resetMocks: true,
setupFilesAfterEnv: ['<rootDir>/src/setup-jest.ts'],
testMatch: ['**/+(*.)+(spec|test).+(ts)?(x)'],
testMatch: ['**/+(*.)+(spec).+(ts)?(x)'],
coverageReporters: ['html', 'lcov'],
transformIgnorePatterns: ['node_modules/(?!.*.mjs$|@datorama/akita)'],
};
Loading

0 comments on commit c578956

Please sign in to comment.