From 29f10f146704ae961d31b82ce3bcc0f65669b03f Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Wed, 14 Dec 2022 17:10:20 -0400 Subject: [PATCH] Fixed some unit tests and add test step to run on Windows/Mac builds (#2466) * Fixed some unit tests and add test step to run on Windows/Mac builds * Update failing test * Fix backlash * Fix windows run * Fix Windows again Co-authored-by: Tasos Boulis Co-authored-by: Mattermod --- .circleci/config.yml | 2 ++ e2e/specs/downloads/downloads_manager.test.js | 1 + e2e/specs/startup/app.test.js | 2 -- .../diagnostics/steps/internal/loggerHooks.test.js | 11 +++++++++-- src/main/diagnostics/steps/internal/obfuscators.ts | 10 +++------- src/main/windows/windowManager.test.js | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1acd94f1..be663b66 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -198,6 +198,7 @@ jobs: command: nvm off; choco install nodejs-lts -y - run: npm i -g node-gyp; node-gyp install; node-gyp install --devdir="$env:USERPROFILE\.electron-gyp" --target=$(jq -r .devDependencies.electron package.json) --dist-url="https://electronjs.org/headers" - run: $env:PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1; npm ci + - run: $env:ELECTRON_DISABLE_SANDBOX=1; npm run test:unit - build: os: windows path: ./build/win @@ -222,6 +223,7 @@ jobs: command: nvm install --lts && nvm use --lts - run: jq '.mac.target=["zip"]' electron-builder.json | jq '.mac.gatekeeperAssess=false' > /tmp/electron-builder.json && cp /tmp/electron-builder.json . - run: PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci + - run: ELECTRON_DISABLE_SANDBOX=1 npm run test:unit-ci - build: os: mac path: ./build/macos diff --git a/e2e/specs/downloads/downloads_manager.test.js b/e2e/specs/downloads/downloads_manager.test.js index 15f7f521..ddb3a447 100644 --- a/e2e/specs/downloads/downloads_manager.test.js +++ b/e2e/specs/downloads/downloads_manager.test.js @@ -3,6 +3,7 @@ 'use strict'; const fs = require('fs'); + const robot = require('robotjs'); const env = require('../../modules/environment'); diff --git a/e2e/specs/startup/app.test.js b/e2e/specs/startup/app.test.js index 796033f3..fff6cd41 100644 --- a/e2e/specs/startup/app.test.js +++ b/e2e/specs/startup/app.test.js @@ -4,8 +4,6 @@ 'use strict'; -const robot = require('robotjs'); - const env = require('../../modules/environment'); const {asyncSleep} = require('../../modules/utils'); diff --git a/src/main/diagnostics/steps/internal/loggerHooks.test.js b/src/main/diagnostics/steps/internal/loggerHooks.test.js index 053834d0..6a8ba2e9 100644 --- a/src/main/diagnostics/steps/internal/loggerHooks.test.js +++ b/src/main/diagnostics/steps/internal/loggerHooks.test.js @@ -61,11 +61,18 @@ describe('main/diagnostics/loggerHooks', () => { describe('should mask paths for all OSs', () => { it('darwin', () => { + const originalPlatform = process.platform; + Object.defineProperty(process, 'platform', { + value: 'darwin', + }); const message = { data: ['/Users/user/Projects/desktop /Users/user/Projects/desktop/file.txt /Users/user/Projects/desktop/folder withSpace/file.txt'], }; const result = maskMessageDataHook(loggerMock)(message, 'file').data[0]; expect(findOccurrencesInString(MASK_PATH, result)).toBe(4); + Object.defineProperty(process, 'platform', { + value: originalPlatform, + }); }); it('linux', () => { const originalPlatform = process.platform; @@ -87,10 +94,10 @@ describe('main/diagnostics/loggerHooks', () => { value: 'win32', }); const message = { - data: ['C:/Users/user/Desktop/download.pdf C:/Users/user/Desktop/folder withSpace/file.txt'], + data: ['C:/Users/user/Desktop/download.pdf C:\\Users\\user\\Desktop\\folder withSpace\\file.txt'], }; const result = maskMessageDataHook(loggerMock)(message, 'file').data[0]; - expect(findOccurrencesInString(MASK_PATH, result)).toBe(3); + expect(findOccurrencesInString(MASK_PATH, result)).toBe(2); Object.defineProperty(process, 'platform', { value: originalPlatform, }); diff --git a/src/main/diagnostics/steps/internal/obfuscators.ts b/src/main/diagnostics/steps/internal/obfuscators.ts index e55dcc03..066480f9 100644 --- a/src/main/diagnostics/steps/internal/obfuscators.ts +++ b/src/main/diagnostics/steps/internal/obfuscators.ts @@ -5,10 +5,6 @@ import {MASK_EMAIL, MASK_IPV4, MASK_PATH, MASK_URL, REGEX_EMAIL, REGEX_IPV4, REG import {truncateString} from './utils'; -const isDarwin = process.platform === 'darwin'; -const isLinux = process.platform === 'linux'; -const isWin = process.platform === 'win32'; - function maskDataInString(str: string): string { let maskedStr = str; if (!str || typeof str !== 'string') { @@ -36,15 +32,15 @@ function maskDataInString(str: string): string { } // Paths - if (isDarwin) { + if (process.platform === 'darwin') { if (REGEX_PATH_DARWIN.test(str)) { maskedStr = maskedStr.replaceAll(RegExp(REGEX_PATH_DARWIN, 'gi'), MASK_PATH); } - } else if (isLinux) { + } else if (process.platform === 'linux') { if (REGEX_PATH_LINUX.test(str)) { maskedStr = maskedStr.replaceAll(RegExp(REGEX_PATH_LINUX, 'gi'), MASK_PATH); } - } else if (isWin) { + } else if (process.platform === 'win32') { if (REGEX_PATH_WIN32.test(str)) { maskedStr = maskedStr.replaceAll(RegExp(REGEX_PATH_WIN32, 'gi'), MASK_PATH); } diff --git a/src/main/windows/windowManager.test.js b/src/main/windows/windowManager.test.js index 1574a997..096dbb1a 100644 --- a/src/main/windows/windowManager.test.js +++ b/src/main/windows/windowManager.test.js @@ -262,7 +262,7 @@ describe('main/windows/windowManager', () => { loadingScreenState: 3, }; windowManager.mainWindow = { - getContentBounds: () => ({width: 800, height: 600}), + getContentBounds: () => ({width: 1000, height: 900}), getSize: () => [1000, 900], }; windowManager.teamDropdown = {