From f9beb5be8eb433764ab0432c64ac9fec13cbcaa8 Mon Sep 17 00:00:00 2001 From: Arthur Araujo Date: Thu, 28 Dec 2023 21:20:01 -0300 Subject: [PATCH] test --- .github/workflows/Checks.yml | 24 ++++++++++++++++++------ __tests__/__main__/main-window.js | 22 ++++++++++++++++------ package.json | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.github/workflows/Checks.yml b/.github/workflows/Checks.yml index 4e86a0efc..5b7a97211 100644 --- a/.github/workflows/Checks.yml +++ b/.github/workflows/Checks.yml @@ -23,7 +23,7 @@ jobs: run: | export DISPLAY=:99 # TODO: need to download driver according to electron's version - wget --directory-prefix=/tmp https://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip + wget --directory-prefix=/tmp https://chromedriver.storage.googleapis.com/100.0.4896.20/chromedriver_linux64.zip unzip -d /tmp/chromedriver /tmp/chromedriver_linux64.zip sudo chmod +x /tmp/chromedriver/chromedriver /tmp/chromedriver/chromedriver & @@ -32,15 +32,27 @@ jobs: shell: bash run: | npm install - - name: ' Lint' - shell: bash - run: | - npm run lint + # - name: ' Lint' + # shell: bash + # run: | + # npm run lint - name: ' Tests' shell: bash env: - DISPLAY: ':99' + OS: ${{ matrix.os }} run: | + if [[ $OS == 'ubuntu-20.04' ]]; then + # Avoid "failed to connect to the bus" errors on CI https://github.com/microsoft/WSL/issues/7915 + export XDG_RUNTIME_DIR=/run/user/$(id -u) + sudo mkdir -p $XDG_RUNTIME_DIR + sudo chmod 700 $XDG_RUNTIME_DIR + sudo chown $(id -un):$(id -gn) $XDG_RUNTIME_DIR + export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus + + # For ChromeDriver to work + export DISPLAY=':99' + fi + npm run test:jest - name: ' Create COV_REPORT' run: | diff --git a/__tests__/__main__/main-window.js b/__tests__/__main__/main-window.js index cbdaf244c..3c029a3af 100644 --- a/__tests__/__main__/main-window.js +++ b/__tests__/__main__/main-window.js @@ -1,7 +1,7 @@ const notification = require('../../js/notification.js'); const userPreferences = require('../../js/user-preferences.js'); const { savePreferences, defaultPreferences, resetPreferences } = userPreferences; -const { BrowserWindow, ipcMain } = require('electron'); +const { app, BrowserWindow, ipcMain } = require('electron'); jest.mock('../../js/update-manager', () => ({ checkForUpdates: jest.fn(), @@ -12,6 +12,21 @@ const mainWindowModule = require('../../js/main-window.js'); const { getMainWindow, createWindow, resetMainWindow, getLeaveByInterval, getWindowTray, triggerStartupDialogs } = mainWindowModule; const updateManager = require('../../js/update-manager.js'); +// Mocking USER_DATA_PATH for tests below +ipcMain.handle('USER_DATA_PATH', () => +{ + return new Promise((resolve) => + { + resolve(app.getPath('userData')); + }); +}); + +ipcMain.removeHandler('GET_LANGUAGE_DATA'); +ipcMain.handle('GET_LANGUAGE_DATA', () => ({ + 'language': 'en', + 'data': {} +})); + describe('main-window.js', () => { let showSpy; @@ -113,11 +128,6 @@ describe('main-window.js', () => { ipcMain.emit('FINISH_TEST', event, savedPreferences); }); - ipcMain.removeHandler('GET_LANGUAGE_DATA'); - ipcMain.handle('GET_LANGUAGE_DATA', () => ({ - 'language': 'en', - 'data': {} - })); ipcMain.on('FINISH_TEST', (event, savedPreferences) => { expect(windowSpy).toBeCalledTimes(1); diff --git a/package.json b/package.json index 25ab1432b..561396293 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "postinstall": "patch-package", "start": "electron .", "test": "npm-run-all test:*", - "test:jest": "jest --runInBand --verbose=false --detectOpenHandles --colors --transformIgnorePatterns 'node_modules/(?!astronomia)/' -- ", + "test:jest": "jest --runInBand --verbose=true --detectOpenHandles --colors --transformIgnorePatterns 'node_modules/(?!astronomia)/' -- ", "test:mocha": "nyc --reporter=lcov --reporter=json mocha tests/*", "setup:win": "node scripts/create_windows_installer.js" },