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: add playwright ee coverage #26293

Merged
merged 19 commits into from
Jul 28, 2022
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
22 changes: 20 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,31 @@ jobs:
docker logs presence --tail=50

cd ./apps/meteor
IS_EE=true npm run test:e2e

E2E_COVERAGE=true IS_EE=true npm run test:e2e

- name: Extract e2e:ee:coverage
run: |
cd ./apps/meteor
yarn test:e2e:nyc

- uses: codecov/codecov-action@v3
with:
directory: ./apps/meteor
flags: e2e
verbose: true

- name: Store e2e-ee-coverage
uses: actions/upload-artifact@v2
with:
name: e2e-ee-coverage
path: ./apps/meteor/coverage*

- name: Store playwright test trace
uses: actions/upload-artifact@v2
if: failure()
with:
name: playwright-test-trace
name: e2e-ee-testtrace
path: ./apps/meteor/tests/e2e/test-failures*

deploy:
Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"babel-plugin-istanbul"
]
}
3 changes: 3 additions & 0 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"deploy": "npm run build && pm2 startOrRestart pm2.json",
"coverage": "nyc -r html mocha --config ./.mocharc.js",
"test:e2e": "playwright test",
"test:e2e:nyc": "nyc report --reporter=text-summary --reporter=lcov",
"testapi": "mocha --config ./.mocharc.api.js",
"testunit": "npm run .testunit:definition && npm run .testunit:client && npm run .testunit:server",
".testunit:server": "mocha --config ./.mocharc.js",
Expand Down Expand Up @@ -141,6 +142,7 @@
"autoprefixer": "^9.8.8",
"babel-loader": "^8.2.5",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-istanbul": "^6.1.1",
"chai": "^4.3.6",
"chai-datetime": "^1.8.0",
"chai-dom": "^1.11.0",
Expand All @@ -159,6 +161,7 @@
"jsdom-global": "^3.0.2",
"mocha": "^9.2.2",
"mock-require": "^3.0.3",
"nyc": "^15.1.0",
"outdent": "~0.8.0",
"pino-pretty": "^7.6.1",
"postcss": "~8.4.14",
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/e2e/01-forgot-password.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';

import { test, expect } from './utils/test';
import { Auth } from './page-objects';

test.describe('Forgot Password', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/02-register.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import { faker } from '@faker-js/faker';

import { test, expect } from './utils/test';
import { Auth } from './page-objects';

test.describe('Register', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/03-login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import { faker } from '@faker-js/faker';

import { test, expect } from './utils/test';
import { Auth } from './page-objects';

test.describe('Login', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/05-channel-creation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import { faker } from '@faker-js/faker';

import { test, expect } from './utils/test';
import { HomeChannel, Auth } from './page-objects';

test.describe('Channel Creation', () => {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/tests/e2e/06-messaging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test, Browser, Page } from '@playwright/test';
import { Browser, Page } from '@playwright/test';

import { test, expect } from './utils/test';
import { validUserInserted } from './utils/mocks/userAndPasswordMock';
import { Auth, HomeChannel } from './page-objects';

Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/e2e/07-emoji.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';

import { test, expect } from './utils/test';
import { Auth, HomeChannel } from './page-objects';

test.describe('Emoji', () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/e2e/09-channel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';

import { test, expect } from './utils/test';
import { publicChannelCreated, setPublicChannelCreated } from './utils/mocks/checks';
import { Auth, HomeChannel } from './page-objects';

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/10-user-preferences.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import { faker } from '@faker-js/faker';

import { test, expect } from './utils/test';
import { Auth, HomeChannel, AccountProfile } from './page-objects';

test.describe('User preferences', () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/e2e/11-admin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';

import { test, expect } from './utils/test';
import { Auth, Administration } from './page-objects';

test.describe('Administration', () => {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/tests/e2e/12-settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect, Page } from '@playwright/test';
import { Page } from '@playwright/test';
import { v4 as uuid } from 'uuid';

import { test, expect } from './utils/test';
import { BASE_API_URL } from './utils/constants';
import { adminLogin, validUserInserted, registerUser } from './utils/mocks/userAndPasswordMock';
import { Auth, HomeChannel, AccountProfile, Administration } from './page-objects';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/13-permissions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { v4 as uuid } from 'uuid';
import faker from '@faker-js/faker';

import { test, expect } from './utils/test';
import { Auth, Administration, HomeChannel } from './page-objects';

test.describe('Permissions', () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/tests/e2e/14-setting-permissions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from '@playwright/test';
import faker from '@faker-js/faker';

import { validUserInserted } from './utils/mocks/userAndPasswordMock';
import { test, expect } from './utils/test';
import { Auth, Administration, HomeChannel } from './page-objects';
import { validUserInserted } from './utils/mocks/userAndPasswordMock';

test.describe('Settings Permissions', () => {
let pageAuth: Auth;
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/e2e/15-message-popup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';

import { test, expect } from './utils/test';
import { Auth, HomeChannel } from './page-objects';

test.describe('Message Popup', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/16-discussion.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '@playwright/test';
import { faker } from '@faker-js/faker';
import { v4 as uuid } from 'uuid';

import { test } from './utils/test';
import { Auth, HomeDiscussion } from './page-objects';

test.describe('[Discussion]', () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/e2e/omnichannel-agents.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';

import { test, expect } from './utils/test';
import { Auth, OmnichannelAgents } from './page-objects';

test.describe('Agents', () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/e2e/omnichannel-departaments.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from '@playwright/test';

import { test, expect } from './utils/test';
import { Auth, OmnichannelDepartaments } from './page-objects';

test.describe('Department', () => {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/tests/e2e/page-objects/administration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Locator, expect, Page } from '@playwright/test';
import { Locator, Page } from '@playwright/test';

import { expect } from '../utils/test';
import { AdminFlextab, AdminSidenav } from './fragments';

export class Administration {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/tests/e2e/page-objects/home-discussion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Locator, Page, expect } from '@playwright/test';
import { Locator, Page } from '@playwright/test';

import { expect } from '../utils/test';
import { HomeContent, HomeSidenav, HomeFlextab } from './fragments';

export class HomeDiscussion {
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/tests/e2e/page-objects/omnichannel-agents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Locator, expect, Page } from '@playwright/test';
import { Locator, Page } from '@playwright/test';

import { expect } from '../utils/test';

export class OmnichannelAgents {
private readonly page: Page;
Expand Down
41 changes: 41 additions & 0 deletions apps/meteor/tests/e2e/utils/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as fs from 'fs';
import * as path from 'path';

import { v4 as uuid } from 'uuid';
import { test as baseTest } from '@playwright/test';

const PATH_NYC_OUTPUT = path.join(process.cwd(), '.nyc_output');
// @ts-ignore
export const test = baseTest.extend({
context: async ({ context }, use) => {
if (!process.env.E2E_COVERAGE) {
await use(context);
await context.close();

return;
}

await context.addInitScript(() =>
window.addEventListener('beforeunload', () => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__))),
);

await fs.promises.mkdir(PATH_NYC_OUTPUT, { recursive: true });

await context.exposeFunction('collectIstanbulCoverage', (coverageJSON: string) => {
if (coverageJSON) {
fs.writeFileSync(path.join(PATH_NYC_OUTPUT, `playwright_coverage_${uuid()}.json`), coverageJSON);
}
});

await use(context);

await Promise.all(
context.pages().map(async (page) => {
await page.evaluate(() => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__)));
await page.close();
}),
);
},
});

export const { expect } = test;
Loading