Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: detect old electron versions and throw error #747

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fixtures/electron-in-dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Electron found in dependencies",
"scripts": {},
"dependencies": {
"electron": "^25.0.0"
"electron": "^26.0.0"
},
"devDependencies": {}
}
2 changes: 1 addition & 1 deletion fixtures/electron-in-dev-dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"scripts": {},
"dependencies": {},
"devDependencies": {
"electron": "^25.0.0"
"electron": "^26.0.0"
}
}
10 changes: 10 additions & 0 deletions fixtures/old-electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "fixture-old-electron",
"version": "1.0.0",
"description": "Old Electron found in devDependencies",
"scripts": {},
"dependencies": {},
"devDependencies": {
"electron": "^25.0.0"
}
}
10 changes: 9 additions & 1 deletion packages/wdio-electron-service/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ export default class ElectronLaunchService implements Services.ServiceInstance {

await Promise.all(
caps.map(async (cap) => {
const electronVersion = cap.browserVersion || localElectronVersion;
const electronVersion = cap.browserVersion || localElectronVersion || '';
const chromiumVersion = await getChromiumVersion(electronVersion);
log.info(`Found Electron v${electronVersion} with Chromedriver v${chromiumVersion}`);

if (Number.parseInt(electronVersion.split('.')[0]) < 26 && !cap['wdio:chromedriverOptions']?.binary) {
const invalidElectronVersionError = new SevereServiceError(
'Electron version must be 26 or higher for auto-configuration of Chromedriver. If you want to use an older version of Electron, you must configure Chromedriver manually using the wdio:chromedriverOptions capability',
);
log.error(invalidElectronVersionError.message);
throw invalidElectronVersionError;
}

let {
appBinaryPath,
appEntryPoint,
Expand Down
77 changes: 67 additions & 10 deletions packages/wdio-electron-service/test/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ beforeEach(async () => {
version: '26.2.2',
chrome: '116.0.5845.190',
},
{
version: '32.0.1',
chrome: '128.0.6613.36',
},
]);
});

Expand Down Expand Up @@ -88,6 +92,59 @@ describe('onPrepare', () => {
);
});

it('should throw an error when the local Electron version is older than v26 and Chromedriver is not configured manually', async () => {
instance = new LaunchService(
options,
[] as never,
{
services: [['electron', options]],
rootDir: getFixtureDir('old-electron'),
} as Options.Testrunner,
);
const capabilities: WebdriverIO.Capabilities[] = [
{
browserName: 'electron',
},
];
await expect(() => instance?.onPrepare({} as never, capabilities)).rejects.toThrow(
'Electron version must be 26 or higher for auto-configuration of Chromedriver. If you want to use an older version of Electron, you must configure Chromedriver manually using the wdio:chromedriverOptions capability',
);
});

it('should not throw an error when the local Electron version is older than v26 and Chromedriver is configured manually', async () => {
instance = new LaunchService(
options,
[] as never,
{
services: [['electron', options]],
rootDir: getFixtureDir('old-electron'),
} as Options.Testrunner,
);
const capabilities: WebdriverIO.Capabilities[] = [
{
'browserName': 'electron',
'wdio:chromedriverOptions': {
binary: '/path/to/chromedriver',
},
},
];
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0]).toEqual({
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
windowTypes: ['app', 'webview'],
},
'wdio:chromedriverOptions': {
binary: '/path/to/chromedriver',
},
'wdio:electronServiceOptions': {},
'wdio:enforceWebDriverClassic': true,
});
});

it('should throw an error when appBinaryPath is not specified and no build tool is found', async () => {
delete options.appBinaryPath;
(getAppBuildInfo as Mock).mockRejectedValueOnce(new Error('b0rk - no build tool found'));
Expand Down Expand Up @@ -230,7 +287,7 @@ describe('onPrepare', () => {
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0]).toEqual({
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.82',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand Down Expand Up @@ -286,7 +343,7 @@ describe('onPrepare', () => {
await instance?.onPrepare({} as never, capabilities);
expect(capabilities[0]).toEqual({
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.82',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand Down Expand Up @@ -533,7 +590,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
browserName: 'electron',
browserVersion: '26.2.2',
browserVersion: '32.0.1',
},
},
chrome: {
Expand All @@ -546,7 +603,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
browserName: 'electron',
browserVersion: '25.0.0',
browserVersion: '26.2.2',
},
},
},
Expand All @@ -561,7 +618,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
'browserName': 'chrome',
'browserVersion': '116.0.5845.190',
'browserVersion': '128.0.6613.36',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand All @@ -581,7 +638,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.190',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand All @@ -606,7 +663,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
browserName: 'electron',
browserVersion: '26.2.2',
browserVersion: '32.0.1',
},
},
},
Expand All @@ -621,7 +678,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
browserName: 'electron',
browserVersion: '25.0.0',
browserVersion: '26.2.2',
},
},
},
Expand All @@ -638,7 +695,7 @@ describe('onPrepare', () => {
myElectronProject: {
capabilities: {
'browserName': 'chrome',
'browserVersion': '116.0.5845.190',
'browserVersion': '128.0.6613.36',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand All @@ -660,7 +717,7 @@ describe('onPrepare', () => {
firstMatch: [],
alwaysMatch: {
'browserName': 'chrome',
'browserVersion': '114.0.5735.45',
'browserVersion': '116.0.5845.190',
'goog:chromeOptions': {
args: [],
binary: 'workspace/my-test-app/dist/my-test-app',
Expand Down
Loading