diff --git a/README.md b/README.md index 27e864a..2704c83 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ To build native binaries from source files, execute the gulp task corresponding 'buildMac' 'buildLinux' ``` -Note that the application for a particular platform must be built on a machine with the same platform. +**Important note**: The application for a particular platform must be built on a machine with the same platform. Since this package can be used on old OS version such as NodeJS 16 docker container, it is important to build binaries on the old OS version for the binaries to contain corresponding dependencies(for example glibc-2.31 for node16 docker image). The *bin* directory contains pre-built native binaries. Consider using them if your contribution does not affect the native modules. diff --git a/bin/linux/glibc-64/bring-to-front b/bin/linux/glibc-64/bring-to-front index 361ed39..351e2ea 100755 Binary files a/bin/linux/glibc-64/bring-to-front and b/bin/linux/glibc-64/bring-to-front differ diff --git a/bin/linux/glibc-64/close b/bin/linux/glibc-64/close old mode 100755 new mode 100644 index c26c46a..08c9cd6 Binary files a/bin/linux/glibc-64/close and b/bin/linux/glibc-64/close differ diff --git a/bin/linux/glibc-64/find-window b/bin/linux/glibc-64/find-window index 1dfd724..e6d1017 100755 Binary files a/bin/linux/glibc-64/find-window and b/bin/linux/glibc-64/find-window differ diff --git a/bin/linux/glibc-64/generate-thumbnail b/bin/linux/glibc-64/generate-thumbnail old mode 100755 new mode 100644 index 0a607f9..d07d08a Binary files a/bin/linux/glibc-64/generate-thumbnail and b/bin/linux/glibc-64/generate-thumbnail differ diff --git a/bin/linux/glibc-64/get-window-size b/bin/linux/glibc-64/get-window-size old mode 100755 new mode 100644 index b7895b1..8a8190a Binary files a/bin/linux/glibc-64/get-window-size and b/bin/linux/glibc-64/get-window-size differ diff --git a/bin/linux/glibc-64/maximize b/bin/linux/glibc-64/maximize old mode 100755 new mode 100644 index eb1074a..3db7791 Binary files a/bin/linux/glibc-64/maximize and b/bin/linux/glibc-64/maximize differ diff --git a/bin/linux/glibc-64/resize b/bin/linux/glibc-64/resize old mode 100755 new mode 100644 index e21c56f..3001ab0 Binary files a/bin/linux/glibc-64/resize and b/bin/linux/glibc-64/resize differ diff --git a/bin/linux/glibc-64/screenshot b/bin/linux/glibc-64/screenshot old mode 100755 new mode 100644 index 1867dfe..f9f2318 Binary files a/bin/linux/glibc-64/screenshot and b/bin/linux/glibc-64/screenshot differ diff --git a/src/api/open.js b/src/api/open.js index 5d20b56..13e871e 100644 --- a/src/api/open.js +++ b/src/api/open.js @@ -4,19 +4,9 @@ import OS from 'os-family'; import { exec } from '../utils/exec'; import exists from '../utils/fs-exists-promised'; import { BrowserPathNotSetError, UnableToRunBrowsersError } from '../errors'; -import debug from 'debug'; -import { inspect } from 'util'; +import Logger from '../utils/logger'; -const LOGGER = debug('testcafe:browser-tools:open'); - -function log (data) { - try { - LOGGER(inspect(data, { isTestCafeInspect: true, compact: false })); - } - catch (e) { - LOGGER(e.stack ? e.stack : String(e)); - } -} +const logger = new Logger('testcafe:browser-tools:open'); async function checkBrowserPath (browserInfo) { if (!browserInfo.path) { @@ -84,11 +74,13 @@ export default async function (browserInfo, pageUrl) { var command = getOpenCommand(browserInfo, pageUrl); try { - log(command); + logger.log(command); await exec(command); } catch (err) { + logger.log(err); + throw new UnableToRunBrowsersError({ path: browserInfo.path }); } } diff --git a/src/utils/exec.js b/src/utils/exec.js index 492627e..f528e26 100644 --- a/src/utils/exec.js +++ b/src/utils/exec.js @@ -12,7 +12,9 @@ import BINARIES from '../binaries'; import flattenWhitespace from './flatten-whitespace'; import getEnvironmentVariable from './get-environment-variable'; import { NativeBinaryHasFailedError } from '../errors'; +import Logger from './logger'; +const logger = new Logger('testcafe:browser-tools:exec'); const EXIT_CODE_REGEXP = /Exit code: (-?\d+)/; @@ -46,7 +48,6 @@ function getTempPipePath () { var execFilePromise = promisify(childProc.execFile); var execPromise = promisify(childProc.exec); - function readPipe (pipePath) { return new Promise((resolve, reject) => { let data = ''; @@ -98,7 +99,7 @@ async function runWithMacApp (binaryPath, args) { try { const [data] = await Promise.all([ readPipe(pipePath), - spawnApp(pipePath, binaryPath, args) + spawnApp(pipePath, binaryPath, args), ]); const exitCodeMatch = data.match(EXIT_CODE_REGEXP); @@ -127,6 +128,8 @@ export async function execFile (filePath, args) { return await execFilePromise(filePath, args); } catch (err) { + logger.log(err); + if (err instanceof NativeBinaryHasFailedError) throw err; diff --git a/src/utils/logger.js b/src/utils/logger.js new file mode 100644 index 0000000..a39d6db --- /dev/null +++ b/src/utils/logger.js @@ -0,0 +1,17 @@ +import debug from 'debug'; +import { inspect } from 'util'; + +export default class Logger { + constructor (namespace) { + this.logger = debug(namespace); + } + + log (data) { + try { + this.logger(inspect(data, { isTestCafeInspect: true, compact: false })); + } + catch (e) { + this.logger(e.stack ? e.stack : String(e)); + } + } +}