-
-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test/e2e] Add a mechanism to stub binaries (#3485)
* Ability to stub legendary commands and skip some code during e2e tests * Simplify legendary stubbing in e2e tests * Add command stubbing for gogdl and nile. Refactor. * Reset all stubs after each test * Remove unneeded comment * Allow stubbing binaries commands with a promise too * remove old test
- Loading branch information
Showing
15 changed files
with
306 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { expect, test } from '@playwright/test' | ||
import { electronTest } from './helpers' | ||
|
||
electronTest('Settings', async (app, page) => { | ||
// stub `legendary --version` | ||
await app.evaluate(({ ipcMain }) => { | ||
ipcMain.emit('setLegendaryCommandStub', [ | ||
{ | ||
commandParts: ['--version'], | ||
stdout: 'legendary version "1.2.3", codename "Some Name"' | ||
} | ||
]) | ||
}) | ||
|
||
// stub `gogdl --version` | ||
await app.evaluate(({ ipcMain }) => { | ||
ipcMain.emit('setGogdlCommandStub', [ | ||
{ | ||
commandParts: ['--version'], | ||
stdout: '2.3.4' | ||
} | ||
]) | ||
}) | ||
|
||
// stub `nile --version` | ||
await app.evaluate(({ ipcMain }) => { | ||
ipcMain.emit('setNileCommandStub', [ | ||
{ | ||
commandParts: ['--version'], | ||
stdout: '1.1.1 JoJo' | ||
} | ||
]) | ||
}) | ||
|
||
await test.step('shows the Advanced settings', async () => { | ||
await page.getByTestId('settings').click() | ||
page.getByText('Global Settings') | ||
await page.getByText('Advanced').click() | ||
}) | ||
|
||
await test.step('shows alternative binaries inputs', async () => { | ||
await expect( | ||
page.getByLabel('Choose an Alternative Legendary Binary') | ||
).toBeVisible() | ||
await expect( | ||
page.getByLabel('Choose an Alternative GOGDL Binary to use') | ||
).toBeVisible() | ||
await expect( | ||
page.getByLabel('Choose an Alternative Nile Binary') | ||
).toBeVisible() | ||
}) | ||
|
||
await test.step('shows the binaries versions from the binaries', async () => { | ||
await expect( | ||
page.getByText('Legendary Version: 1.2.3 Some Name') | ||
).toBeVisible() | ||
await expect(page.getByText('GOGDL Version: 2.3.4')).toBeVisible() | ||
await expect(page.getByText('Nile Version: 1.1.1 JoJo')).toBeVisible() | ||
}) | ||
|
||
await test.step('shows the default experimental features', async () => { | ||
await expect(page.getByLabel('New design')).not.toBeChecked() | ||
await expect(page.getByLabel('Help component')).not.toBeChecked() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ipcMain } from 'electron' | ||
import { RunnerCommandStub } from 'common/types' | ||
|
||
/* | ||
* Multiple parts of a command can be set for the stub to be able to stub | ||
* similar commands | ||
* | ||
* The first stub for which all commandParts are included in the executed | ||
* command will be selected. The stubs should be declared from more | ||
* precise to less precise to avoid unreachable stubs. | ||
* | ||
* We can stub a Promise<ExecResult> as a response, or stub stdout/stderr | ||
* values as an alternative to make the stubbing easier | ||
*/ | ||
const defaultStubs: RunnerCommandStub[] = [ | ||
{ | ||
commandParts: ['--version'], | ||
stdout: '0.7.1' | ||
} | ||
] | ||
|
||
let currentStubs = [...defaultStubs] | ||
|
||
export const runGogdlCommandStub = async (command: string[]) => { | ||
const stub = currentStubs.find((stub) => | ||
stub.commandParts.every((part) => command.includes(part)) | ||
) | ||
|
||
if (stub?.response) return stub.response | ||
|
||
return Promise.resolve({ | ||
stdout: stub?.stdout || '', | ||
stderr: stub?.stderr || '' | ||
}) | ||
} | ||
|
||
// Add listeners to be called from e2e tests to stub the gogdl command calls | ||
if (process.env.CI === 'e2e') { | ||
ipcMain.on('setGogdlCommandStub', (stubs) => (currentStubs = [...stubs])) | ||
ipcMain.on('resetGogdlCommandStub', () => (currentStubs = [...defaultStubs])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ipcMain } from 'electron' | ||
import { RunnerCommandStub } from 'common/types' | ||
import { LegendaryCommand } from './commands' | ||
|
||
/* | ||
* Multiple parts of a command can be set for the stub to be able to stub | ||
* similar commands | ||
* | ||
* The first stub for which all commandParts are included in the executed | ||
* command will be selected. The stubs should be declared from more | ||
* precise to less precise to avoid unreachable stubs. | ||
* | ||
* We can stub a Promise<ExecResult> as a response, or stub stdout/stderr | ||
* values as an alternative to make the stubbing easier | ||
*/ | ||
const defaultStubs: RunnerCommandStub[] = [ | ||
{ | ||
commandParts: ['--version'], | ||
response: Promise.resolve({ | ||
stdout: 'legendary version "0.20.33", codename "Undue Alarm"', | ||
stderr: '' | ||
}) | ||
} | ||
] | ||
|
||
let currentStubs = [...defaultStubs] | ||
|
||
export const runLegendaryCommandStub = async (command: LegendaryCommand) => { | ||
const stub = currentStubs.find((stub) => | ||
stub.commandParts.every((part) => command[part]) | ||
) | ||
|
||
if (stub?.response) return stub.response | ||
|
||
return Promise.resolve({ | ||
stdout: stub?.stdout || '', | ||
stderr: stub?.stderr || '' | ||
}) | ||
} | ||
|
||
// Add listeners to be called from e2e tests to stub the legendary command calls | ||
if (process.env.CI === 'e2e') { | ||
ipcMain.on('setLegendaryCommandStub', (stubs) => (currentStubs = [...stubs])) | ||
ipcMain.on( | ||
'resetLegendaryCommandStub', | ||
() => (currentStubs = [...defaultStubs]) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ipcMain } from 'electron' | ||
import { RunnerCommandStub } from 'common/types' | ||
|
||
/* | ||
* Multiple parts of a command can be set for the stub to be able to stub | ||
* similar commands | ||
* | ||
* The first stub for which all commandParts are included in the executed | ||
* command will be selected. The stubs should be declared from more | ||
* precise to less precise to avoid unreachable stubs. | ||
* | ||
* We can stub a Promise<ExecResult> as a response, or stub stdout/stderr | ||
* values as an alternative to make the stubbing easier | ||
*/ | ||
const defaultStubs: RunnerCommandStub[] = [ | ||
{ | ||
commandParts: ['--version'], | ||
stdout: '1.0.0 Jonathan Joestar' | ||
} | ||
] | ||
|
||
let currentStubs = [...defaultStubs] | ||
|
||
export const runNileCommandStub = async (command: string[]) => { | ||
const stub = currentStubs.find((stub) => | ||
stub.commandParts.every((part) => command.includes(part)) | ||
) | ||
|
||
if (stub?.response) return stub.response | ||
|
||
return Promise.resolve({ | ||
stdout: stub?.stdout || '', | ||
stderr: stub?.stderr || '' | ||
}) | ||
} | ||
|
||
// Add listeners to be called from e2e tests to stub the nile command calls | ||
if (process.env.CI === 'e2e') { | ||
ipcMain.on('setNileCommandStub', (stubs) => (currentStubs = [...stubs])) | ||
ipcMain.on('resetNileCommandStub', () => (currentStubs = [...defaultStubs])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.