From dc9def8fba853ed365111f0b876e548a5eca7149 Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 28 Oct 2021 10:31:11 +0200 Subject: [PATCH 1/2] Avoid chromedriver dependency when using chromedriverCustomPath --- package-lock.json | 58 ++++++++++++++++-------------------------- package.json | 3 ++- src/launcher.js | 12 +++++++-- tests/launcher.test.js | 24 ++++++++++------- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index 68c6e0d..682e010 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2124,9 +2124,9 @@ "dev": true }, "@types/yauzl": { - "version": "2.9.1", - "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz", - "integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==", + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.2.tgz", + "integrity": "sha512-8uALY5LTvSuHgloDVUvWP3pIauILm+8/0pDMokuDYIoNsOkSwd5AiHBTSEJjKTDcZr5z8UpgOWZkxBF4iJftoA==", "dev": true, "optional": true, "requires": { @@ -2188,9 +2188,9 @@ }, "dependencies": { "debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", + "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", "dev": true, "requires": { "ms": "2.1.2" @@ -3342,9 +3342,9 @@ } }, "chromedriver": { - "version": "91.0.0", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-91.0.0.tgz", - "integrity": "sha512-0eQGLDWvfVd1apkqQpt4452bCATrsj50whhVzMqPiazNSfCXXwfYWRonYxx3DVFCG3+RwSCLvsk8/vpuojCyJA==", + "version": "91.0.1", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-91.0.1.tgz", + "integrity": "sha512-9LktpHiUxM4UWUsr+jI1K1YKx2GENt6BKKJ2mibPj1Wc6ODzX/3fFIlr8CZ4Ftuyga+dHTTbAyPWKwKvybEbKA==", "dev": true, "requires": { "@testim/chrome-version": "^1.0.7", @@ -3354,13 +3354,6 @@ "https-proxy-agent": "^5.0.0", "proxy-from-env": "^1.1.0", "tcp-port-used": "^1.0.1" - }, - "dependencies": { - "mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" - } } }, "ci-info": { @@ -3789,8 +3782,7 @@ "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", - "dev": true + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=" }, "deepmerge": { "version": "4.2.2", @@ -4759,9 +4751,9 @@ }, "dependencies": { "debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", + "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", "dev": true, "requires": { "ms": "2.1.2" @@ -4993,9 +4985,9 @@ "dev": true }, "follow-redirects": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz", - "integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==", + "version": "1.14.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz", + "integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==", "dev": true }, "for-in": { @@ -5424,9 +5416,9 @@ }, "dependencies": { "debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", + "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", "dev": true, "requires": { "ms": "2.1.2" @@ -5636,8 +5628,7 @@ "ip-regex": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz", - "integrity": "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==", - "dev": true + "integrity": "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==" }, "is-accessor-descriptor": { "version": "0.1.6", @@ -5953,8 +5944,7 @@ "is-url": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz", - "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==", - "dev": true + "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==" }, "is-windows": { "version": "1.0.2", @@ -5982,7 +5972,6 @@ "version": "2.0.7", "resolved": "https://registry.npmjs.org/is2/-/is2-2.0.7.tgz", "integrity": "sha512-4vBQoURAXC6hnLFxD4VW7uc04XiwTTl/8ydYJxKvPwkWQrSjInkuM5VZVg6BGr1/natq69zDuvO9lGpLClJqvA==", - "dev": true, "requires": { "deep-is": "^0.1.3", "ip-regex": "^4.1.0", @@ -9701,7 +9690,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/tcp-port-used/-/tcp-port-used-1.0.2.tgz", "integrity": "sha512-l7ar8lLUD3XS1V2lfoJlCBaeoaWo/2xfYt81hM7VlvR4RrMVFqfmzfhLVk40hAb368uitje5gPtBRL1m/DGvLA==", - "dev": true, "requires": { "debug": "4.3.1", "is2": "^2.0.6" @@ -9711,7 +9699,6 @@ "version": "4.3.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", - "dev": true, "requires": { "ms": "2.1.2" } @@ -9719,8 +9706,7 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" } } }, diff --git a/package.json b/package.json index 97d8f33..1277b24 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "dependencies": { "@wdio/logger": "^7.5.3", "fs-extra": "^9.1.0", - "split2": "^3.2.2" + "split2": "^3.2.2", + "tcp-port-used": "^1.0.1" }, "devDependencies": { "@babel/cli": "^7.12.17", diff --git a/src/launcher.js b/src/launcher.js index 889814b..2571c62 100644 --- a/src/launcher.js +++ b/src/launcher.js @@ -2,7 +2,6 @@ import { spawn } from 'child_process' import fs from 'fs-extra' import path from 'path' import split2 from 'split2' -import { path as chromedriverPath } from 'chromedriver' import logger from '@wdio/logger' import tcpPortUsed from 'tcp-port-used' @@ -36,7 +35,7 @@ export default class ChromeDriverLauncher { this.logFileName = options.logFileName || DEFAULT_LOG_FILENAME this.capabilities = capabilities this.args = options.args || [] - this.chromedriverCustomPath = options.chromedriverCustomPath ? path.resolve(options.chromedriverCustomPath) : chromedriverPath + this.chromedriverCustomPath = options.chromedriverCustomPath ? path.resolve(options.chromedriverCustomPath) : this._getChromedriverPath() } async onPrepare() { @@ -112,4 +111,13 @@ export default class ChromeDriverLauncher { } } } + + _getChromedriverPath() { + try { + return require('chromedriver').path + } catch (e) { + log.error('Can\'t load chromedriver, please define "chromedriverCustomPath" property or install dependency via "npm install chromedriver --save-dev"') + throw e + } + } } diff --git a/tests/launcher.test.js b/tests/launcher.test.js index 39e0f11..688e3bf 100644 --- a/tests/launcher.test.js +++ b/tests/launcher.test.js @@ -1,6 +1,6 @@ import path from 'path' import fs from 'fs-extra' -import { spawn } from 'child_process' +import {spawn} from 'child_process' import ChromeDriverLauncher from '../src/launcher' jest.mock('child_process', () => { @@ -359,33 +359,39 @@ describe('ChromeDriverLauncher launcher', () => { test('should select custom chromedriver path "chromedriver.exe"', async () => { options.chromedriverCustomPath = 'chromedriver.exe' const Launcher = new ChromeDriverLauncher(options, capabilities, config) - Launcher._redirectLogStream = jest.fn() - await Launcher.onPrepare() + Launcher._redirectLogStream = jest.fn() + await Launcher.onPrepare() expect(Launcher.chromedriverCustomPath).toEqual(path.resolve(options.chromedriverCustomPath)) }) test('should select custom chromedriver path "c:\\chromedriver.exe"', async () => { options.chromedriverCustomPath = 'c:\\chromedriver.exe' const Launcher = new ChromeDriverLauncher(options, capabilities, config) - Launcher._redirectLogStream = jest.fn() - await Launcher.onPrepare() + Launcher._redirectLogStream = jest.fn() + await Launcher.onPrepare() expect(Launcher.chromedriverCustomPath).toEqual(path.resolve(options.chromedriverCustomPath)) }) test('should select custom chromedriver path "./chromedriver.exe"', async () => { options.chromedriverCustomPath = './chromedriver.exe' const Launcher = new ChromeDriverLauncher(options, capabilities, config) - Launcher._redirectLogStream = jest.fn() - await Launcher.onPrepare() + Launcher._redirectLogStream = jest.fn() + await Launcher.onPrepare() expect(Launcher.chromedriverCustomPath).toEqual(path.resolve(options.chromedriverCustomPath)) }) test('should select default chromedriver path if no custome path provided"', async () => { options.chromedriverCustomPath = undefined const Launcher = new ChromeDriverLauncher(options, capabilities, config) - Launcher._redirectLogStream = jest.fn() - await Launcher.onPrepare() + Launcher._redirectLogStream = jest.fn() + await Launcher.onPrepare() expect(Launcher.chromedriverCustomPath).not.toBeUndefined }) + + test('should throw if chromedriver not installed and no custom path provided"', async () => { + jest.mock('chromedriver', () => undefined) + options.chromedriverCustomPath = undefined + expect(() => new ChromeDriverLauncher(options, capabilities, config)).toThrow() + }) }) }) From 00974098299a5aecc041b27128e5753b96cc07bb Mon Sep 17 00:00:00 2001 From: codigodiabolico <58573480+codigodiabolico@users.noreply.github.com> Date: Thu, 28 Oct 2021 11:13:47 +0200 Subject: [PATCH 2/2] Update tests/launcher.test.js Co-authored-by: Christian Bromann --- tests/launcher.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/launcher.test.js b/tests/launcher.test.js index 688e3bf..475366e 100644 --- a/tests/launcher.test.js +++ b/tests/launcher.test.js @@ -388,7 +388,7 @@ describe('ChromeDriverLauncher launcher', () => { expect(Launcher.chromedriverCustomPath).not.toBeUndefined }) - test('should throw if chromedriver not installed and no custom path provided"', async () => { + test('should throw if chromedriver not installed and no custom path provided"', async () => { jest.mock('chromedriver', () => undefined) options.chromedriverCustomPath = undefined expect(() => new ChromeDriverLauncher(options, capabilities, config)).toThrow()