Skip to content

Commit

Permalink
fix: revert to working binaries, add binaries error logging (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem-Babich authored Jun 26, 2023
1 parent b75fe31 commit 5d8f926
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Binary file modified bin/linux/glibc-64/bring-to-front
Binary file not shown.
Binary file modified bin/linux/glibc-64/close
100755 → 100644
Binary file not shown.
Binary file modified bin/linux/glibc-64/find-window
Binary file not shown.
Binary file modified bin/linux/glibc-64/generate-thumbnail
100755 → 100644
Binary file not shown.
Binary file modified bin/linux/glibc-64/get-window-size
100755 → 100644
Binary file not shown.
Binary file modified bin/linux/glibc-64/maximize
100755 → 100644
Binary file not shown.
Binary file modified bin/linux/glibc-64/resize
100755 → 100644
Binary file not shown.
Binary file modified bin/linux/glibc-64/screenshot
100755 → 100644
Binary file not shown.
18 changes: 5 additions & 13 deletions src/api/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 });
}
}
7 changes: 5 additions & 2 deletions src/utils/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+)/;

Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 17 additions & 0 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
@@ -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));
}
}
}

0 comments on commit 5d8f926

Please sign in to comment.