Skip to content

Commit a4f0957

Browse files
johnny/VIDSOL-211-removing noise from unit and integration test
- removing noise - adding scripts to debug locally
1 parent 08a7772 commit a4f0957

File tree

7 files changed

+76
-18
lines changed

7 files changed

+76
-18
lines changed

customWordList.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const customWordList = [
1010
'jiraiOSComponentId',
1111
'supportedLngs',
1212
'applinks',
13+
'PWDEBUG',
1314
];
1415

1516
export default customWordList;

frontend/src/Context/AppConfig/actions/loadAppConfig.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import tryCatch from '@utils/tryCatch';
22
import type { AppConfig } from '../AppConfigContext.types';
3+
import env from '../../../env';
34

45
export type AppConfigApi = import('../AppConfigContext').AppConfigApi;
56

@@ -11,7 +12,12 @@ export type AppConfigApi = import('../AppConfigContext').AppConfigApi;
1112
*/
1213
function loadAppConfig(this: AppConfigApi['actions']) {
1314
return async (_: AppConfigApi) => {
15+
const fallbackConfig: Partial<AppConfig> = {};
16+
1417
const { result: config, error } = await tryCatch(async () => {
18+
// Skip fetching config in CI environments
19+
if (env.VITE_AVOID_FETCHING_APP_CONFIG) return {};
20+
1521
const response = await fetch('/config.json', { cache: 'no-cache' });
1622

1723
const contentType = response.headers.get('content-type');
@@ -25,13 +31,19 @@ function loadAppConfig(this: AppConfigApi['actions']) {
2531
const json: Partial<AppConfig> = await response.json();
2632

2733
return json;
28-
}, {});
34+
}, fallbackConfig);
35+
36+
if (error && env.MODE === 'development') {
37+
console.error(
38+
[
39+
'There was an error loading config.json',
40+
'Please make sure to provide a valid config.json file in the public folder.',
41+
].join('\n'),
42+
error
43+
);
44+
}
2945

3046
this.updateAppConfig({ ...config, isAppConfigLoaded: true });
31-
32-
if (error && !process.env.CI) {
33-
console.warn(error);
34-
}
3547
};
3648
}
3749

frontend/src/env.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export type EnvArg = {
77
VITE_BYPASS_WAITING_ROOM: boolean;
88
VITE_API_URL: string;
99
VITE_TUNNEL_DOMAIN: string;
10+
VITE_AVOID_FETCHING_APP_CONFIG: string;
11+
MODE: 'development' | 'production' | 'test';
1012
};
1113

1214
export class Env {
@@ -22,6 +24,10 @@ export class Env {
2224

2325
public VITE_TUNNEL_DOMAIN: string | undefined;
2426

27+
public VITE_AVOID_FETCHING_APP_CONFIG: boolean = true;
28+
29+
public MODE: 'development' | 'production' | 'test';
30+
2531
constructor(env: Partial<EnvArg>) {
2632
this.VITE_ENABLE_REPORT_ISSUE = Boolean(env.VITE_ENABLE_REPORT_ISSUE ?? false);
2733
this.VITE_I18N_FALLBACK_LANGUAGE = env.VITE_I18N_FALLBACK_LANGUAGE || 'en';
@@ -33,6 +39,8 @@ export class Env {
3339
this.setViteApiUrl(env.VITE_API_URL);
3440

3541
this.VITE_TUNNEL_DOMAIN = env.VITE_TUNNEL_DOMAIN;
42+
this.VITE_AVOID_FETCHING_APP_CONFIG = Boolean(env.VITE_AVOID_FETCHING_APP_CONFIG === 'true');
43+
this.MODE = env.MODE || 'development';
3644
}
3745

3846
setViteApiUrl = (envUrl: string | undefined) => {

integration-tests/fixtures/testWithLogging.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import { BrowserContext, Page, test as baseTest } from '@playwright/test';
1111
import startElectronApp from '../electronHelper';
1212

13+
const isDebugMode = process.env.debugMode === 'true';
14+
1315
const projectType = process.env.PROJECT_TYPE;
14-
const baseURL = 'http://127.0.0.1:3345/';
16+
const baseURL = isDebugMode ? 'http://localhost:5173/' : 'http://127.0.0.1:3345/';
1517

1618
const addLogger = (page: Page, context: BrowserContext) => {
1719
// Get page index to help identify which tab logs are coming from

integration-tests/playwright.config.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { defineConfig, devices } from '@playwright/test';
22
import path = require('path');
33

4+
const isHeadedMode = process.env.headedMode === 'true';
5+
const isDebugMode = process.env.debugMode === 'true';
6+
47
const chromiumFlags = [
58
'--use-fake-ui-for-media-stream',
69
'--autoplay-policy=no-user-gesture-required',
@@ -19,7 +22,8 @@ const height = 824;
1922

2023
const fakeDeviceChromiumFlags = [
2124
...chromiumFlags,
22-
'--headless=new',
25+
// headless only on CI
26+
...(isHeadedMode ? [] : ['--headless=new']),
2327
'--use-fake-device-for-media-stream=device-count=5',
2428
];
2529

@@ -118,8 +122,15 @@ export default defineConfig({
118122

119123
/* Run your local dev server before starting the tests */
120124
webServer: {
121-
command: 'cd .. && yarn start',
122-
url: 'http://127.0.0.1:3345',
123125
reuseExistingServer: true,
126+
env: {
127+
VITE_AVOID_FETCHING_APP_CONFIG: 'true',
128+
},
129+
...(isDebugMode
130+
? {
131+
command: 'cd .. && yarn dev',
132+
url: 'http://localhost:5173/',
133+
}
134+
: { command: 'cd .. && yarn start', url: 'http://127.0.0.1:3345' }),
124135
},
125136
});

integration-tests/project.json

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
"root": "integration-tests",
66
"sourceRoot": "integration-tests",
77
"targets": {
8-
"test": {
9-
"executor": "nx:run-commands",
10-
"options": {
11-
"cwd": "integration-tests",
12-
"command": "playwright test --project='Google Chrome Fake Devices' --project=firefox --project='Microsoft Edge' --project='Mobile Chrome' --project='Electron'"
13-
}
14-
},
158
"updateScreenshots": {
169
"executor": "nx:run-commands",
1710
"cache": false,
@@ -49,13 +42,42 @@
4942
"command": "tsc -p tsconfig.json --noEmit --watch --preserveWatchOutput"
5043
}
5144
},
45+
"test": {
46+
"executor": "nx:run-commands",
47+
"description": "Run playwright tests in all browsers",
48+
"options": {
49+
"cwd": "integration-tests",
50+
"command": "playwright test --project='Google Chrome Fake Devices' --project=firefox --project='Microsoft Edge' --project='Mobile Chrome' --project='Electron'"
51+
}
52+
},
5253
"test:": {
5354
"executor": "nx:run-commands",
54-
"description": "Run playwright tests in a specific file",
55+
"description": "Run playwright tests in a specific file using the compiled version of the app without interruptions",
56+
"options": {
57+
"cwd": "integration-tests",
58+
"description": "Run playwright tests in a specific file",
59+
"command": "playwright test {args._} --project='Google Chrome Fake Devices' --workers=1 --headed",
60+
"env": { "headedMode": "true" }
61+
}
62+
},
63+
"test:dev": {
64+
"executor": "nx:run-commands",
65+
"description": "Run playwright tests in a specific file using the dev version of the app without interruptions",
66+
"options": {
67+
"cwd": "integration-tests",
68+
"description": "Run playwright tests in a specific file",
69+
"command": "playwright test {args._} --project='Google Chrome Fake Devices' --workers=1 --headed",
70+
"env": { "headedMode": "true", "debugMode": "true" }
71+
}
72+
},
73+
"test:debug": {
74+
"executor": "nx:run-commands",
75+
"description": "Run playwright tests in a specific file in debug mode with the dev version of the app",
5576
"options": {
5677
"cwd": "integration-tests",
5778
"description": "Run playwright tests in a specific file",
58-
"command": "playwright test {args._} --project='Google Chrome Fake Devices' --project=firefox --project='Microsoft Edge' --project='Mobile Chrome' --project='Electron'"
79+
"command": "playwright test {args._} --project='Google Chrome Fake Devices' --workers=1 --timeout=0",
80+
"env": { "headedMode": "true", "debugMode": "true", "PWDEBUG": "1" }
5981
}
6082
},
6183
"lint": {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"test:frontend:watch": "nx test frontend --watch",
3535
"test:integration": "nx run integration-tests:test",
3636
"test:integration:": "nx run integration-tests:test:",
37+
"test:integration:dev": "nx run integration-tests:test:dev",
38+
"test:integration:debug": "nx run integration-tests:test:debug",
3739
"ts-check": "nx run backend:ts-check && nx run frontend:ts-check",
3840
"test:integrationUpdateScreenshots": "nx run integration-tests:updateScreenshots",
3941
"test:integrationUpdateScreenshots:": "nx run integration-tests:updateScreenshots:",

0 commit comments

Comments
 (0)