From 360022217830478bc7487005aefd567a30d4a981 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 13 Oct 2021 14:07:37 -0700 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Create=20generat?= =?UTF-8?q?eScreenshotPath=20as=20test=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create generateScreenshotPath as test helper --- ui/desktop/tests/end2end/test-helpers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/desktop/tests/end2end/test-helpers.js b/ui/desktop/tests/end2end/test-helpers.js index 8c43b84f4..892c0773b 100644 --- a/ui/desktop/tests/end2end/test-helpers.js +++ b/ui/desktop/tests/end2end/test-helpers.js @@ -9,7 +9,11 @@ const path = require('path'); */ exports.generateScreenshotPath = (screenshotTestDirectory, fileName) => { const screenshotFormat = '.png'; +<<<<<<< HEAD const screenshotsRootPath = path.join(__dirname, 'screenshots'); +======= + const screenshotsRootPath = path.join(__dirname, '/screenshots/'); +>>>>>>> 8c489b81 (refactor: 💡 Create generateScreenshotPath as test helper) const screenshotPath = path.join( screenshotsRootPath, screenshotTestDirectory From 5dd59a6c14a936826a478a756f4814e279512d83 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Thu, 14 Oct 2021 11:24:03 -0700 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Move=20returnExe?= =?UTF-8?q?cutablePath=20to=20e2e=20test=20helpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move returnExecutablePath to end to end test helpers file. Now the two test files are importing the function from the test helpers file. --- .../tests/end2end/authentication.spec.js | 28 +++--------------- ui/desktop/tests/end2end/targets.spec.js | 9 ++++-- ui/desktop/tests/end2end/test-helpers.js | 29 +++++++++++++++++++ 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/ui/desktop/tests/end2end/authentication.spec.js b/ui/desktop/tests/end2end/authentication.spec.js index c7a02fbcd..71667b0de 100644 --- a/ui/desktop/tests/end2end/authentication.spec.js +++ b/ui/desktop/tests/end2end/authentication.spec.js @@ -1,33 +1,13 @@ /* eslint-disable no-undef */ const { test, expect } = require('@playwright/test'); const { _electron: electron } = require('playwright'); -const { generateScreenshotPath } = require('./test-helpers'); +const { + generateScreenshotPath, + returnExecutablePath, +} = require('./test-helpers'); let electronApp = null; const screenshotsDirectory = 'authentication/'; - -// TODO: move this function to a test helpers file so it could be used by other tests. -// Returns the executable path for the Boundary binary the test suite will run. -const returnExecutablePath = (platform, arch) => { - try { - // Just mac - if (platform === 'darwin') { - if (arch === 'x64') { - // Intel chips - return 'electron-app/out/Boundary-darwin-x64/Boundary.app/Contents/MacOS/Boundary'; - } else if (arch === 'arm64') { - // M1 chips - return 'electron-app/out/Boundary-darwin-arm64/Boundary.app/Contents/MacOS/Boundary'; - } else { - throw new Error('The test suite is not compatible with your arch.'); - } - } else { - throw new Error('The test suite is not compatible with your Platform.'); - } - } catch (error) { - console.error(error); - } -}; const executablePath = returnExecutablePath(process.platform, process.arch); test.beforeEach(async () => { diff --git a/ui/desktop/tests/end2end/targets.spec.js b/ui/desktop/tests/end2end/targets.spec.js index d30084031..2ee467d17 100644 --- a/ui/desktop/tests/end2end/targets.spec.js +++ b/ui/desktop/tests/end2end/targets.spec.js @@ -1,15 +1,18 @@ /* eslint-disable no-undef */ const { test, expect } = require('@playwright/test'); const { _electron: electron } = require('playwright'); -const { generateScreenshotPath } = require('./test-helpers'); +const { + generateScreenshotPath, + returnExecutablePath, +} = require('./test-helpers'); let electronApp = null; const screenshotsDirectory = 'targets/'; +const executablePath = returnExecutablePath(process.platform, process.arch); test.beforeEach(async () => { electronApp = await electron.launch({ - executablePath: - 'electron-app/out/Boundary-darwin-arm64/Boundary.app/Contents/MacOS/Boundary', + executablePath: executablePath, env: { NODE_ENV: 'test', BYPASS_APP_UPDATER: true, diff --git a/ui/desktop/tests/end2end/test-helpers.js b/ui/desktop/tests/end2end/test-helpers.js index 892c0773b..e99b95dc7 100644 --- a/ui/desktop/tests/end2end/test-helpers.js +++ b/ui/desktop/tests/end2end/test-helpers.js @@ -20,3 +20,32 @@ exports.generateScreenshotPath = (screenshotTestDirectory, fileName) => { ); return path.join(screenshotPath, fileName).concat(screenshotFormat); }; + +/** + * + * @param {string} platform The operating system. + * @param {string} arch The CPU architecture. + * @returns A full path where the Desktop Client executable is located. + */ +exports.returnExecutablePath = (platform, arch) => { + try { + // Just mac + if (platform === 'darwin') { + if (arch === 'x64') { + // Intel chips + return 'electron-app/out/Boundary-darwin-x64/Boundary.app/Contents/MacOS/Boundary'; + } else if (arch === 'arm64') { + // M1 chips + return 'electron-app/out/Boundary-darwin-arm64/Boundary.app/Contents/MacOS/Boundary'; + } else { + throw new Error('The test suite is not compatible with your arch.'); + } + } else { + throw new Error( + 'The test suite is not compatible with your Platform or Architecture.' + ); + } + } catch (error) { + console.error(error); + } +}; From a07e3f4e41b2846291198b7e7dc23a0acfb639de Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 15 Oct 2021 10:20:16 -0700 Subject: [PATCH 3/4] Forgot to commit change --- ui/desktop/tests/end2end/test-helpers.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ui/desktop/tests/end2end/test-helpers.js b/ui/desktop/tests/end2end/test-helpers.js index e99b95dc7..80282aaf6 100644 --- a/ui/desktop/tests/end2end/test-helpers.js +++ b/ui/desktop/tests/end2end/test-helpers.js @@ -9,11 +9,7 @@ const path = require('path'); */ exports.generateScreenshotPath = (screenshotTestDirectory, fileName) => { const screenshotFormat = '.png'; -<<<<<<< HEAD const screenshotsRootPath = path.join(__dirname, 'screenshots'); -======= - const screenshotsRootPath = path.join(__dirname, '/screenshots/'); ->>>>>>> 8c489b81 (refactor: 💡 Create generateScreenshotPath as test helper) const screenshotPath = path.join( screenshotsRootPath, screenshotTestDirectory From 6bcbf2b2ba3fb35380990adefa58d2b64a1e7097 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 15 Oct 2021 13:40:14 -0700 Subject: [PATCH 4/4] Simplify conditionals with a switch --- ui/desktop/tests/end2end/test-helpers.js | 27 +++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/ui/desktop/tests/end2end/test-helpers.js b/ui/desktop/tests/end2end/test-helpers.js index 80282aaf6..ff6902143 100644 --- a/ui/desktop/tests/end2end/test-helpers.js +++ b/ui/desktop/tests/end2end/test-helpers.js @@ -25,21 +25,18 @@ exports.generateScreenshotPath = (screenshotTestDirectory, fileName) => { */ exports.returnExecutablePath = (platform, arch) => { try { - // Just mac - if (platform === 'darwin') { - if (arch === 'x64') { - // Intel chips - return 'electron-app/out/Boundary-darwin-x64/Boundary.app/Contents/MacOS/Boundary'; - } else if (arch === 'arm64') { - // M1 chips - return 'electron-app/out/Boundary-darwin-arm64/Boundary.app/Contents/MacOS/Boundary'; - } else { - throw new Error('The test suite is not compatible with your arch.'); - } - } else { - throw new Error( - 'The test suite is not compatible with your Platform or Architecture.' - ); + switch (platform) { + case 'darwin': + switch (arch) { + case 'x64': // Intel chips + return 'electron-app/out/Boundary-darwin-x64/Boundary.app/Contents/MacOS/Boundary'; + case 'arm64': // M1 chips + return 'electron-app/out/Boundary-darwin-arm64/Boundary.app/Contents/MacOS/Boundary'; + default: + throw new Error('The test suite is not compatible with your arch.'); + } + default: + throw new Error('The test suite is not compatible with your platform.'); } } catch (error) { console.error(error);