Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into PPLT_2492
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmay-browserstack committed Nov 16, 2023
2 parents 673b04e + bb901bc commit 7d50258
Show file tree
Hide file tree
Showing 49 changed files with 609 additions and 237 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.27.4-beta.1",
"version": "1.27.4",
"packages": [
"packages/*"
],
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-app",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.27.4-beta.1",
"@percy/cli-exec": "1.27.4-beta.1"
"@percy/cli-command": "1.27.4",
"@percy/cli-exec": "1.27.4"
}
}
6 changes: 3 additions & 3 deletions packages/cli-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-build",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"engines": {
"node": ">=14"
Expand All @@ -33,6 +33,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.27.4-beta.1"
"@percy/cli-command": "1.27.4"
}
}
10 changes: 5 additions & 5 deletions packages/cli-command/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-command",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"files": [
"dist",
Expand All @@ -36,8 +36,8 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/config": "1.27.4-beta.1",
"@percy/core": "1.27.4-beta.1",
"@percy/logger": "1.27.4-beta.1"
"@percy/config": "1.27.4",
"@percy/core": "1.27.4",
"@percy/logger": "1.27.4"
}
}
6 changes: 3 additions & 3 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-config",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"engines": {
"node": ">=14"
Expand All @@ -33,6 +33,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.27.4-beta.1"
"@percy/cli-command": "1.27.4"
}
}
6 changes: 3 additions & 3 deletions packages/cli-exec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-exec",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.27.4-beta.1",
"@percy/cli-command": "1.27.4",
"cross-spawn": "^7.0.3",
"which": "^2.0.2"
}
Expand Down
39 changes: 35 additions & 4 deletions packages/cli-exec/src/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import command from '@percy/cli-command';
import start from './start.js';
import stop from './stop.js';
import ping from './ping.js';
import { getPackageJSON } from '@percy/cli-command/utils';

const pkg = getPackageJSON(import.meta.url);

export const exec = command('exec', {
description: 'Start and stop Percy around a supplied command',
Expand Down Expand Up @@ -83,7 +86,7 @@ export const exec = command('exec', {

// run the provided command
log.info(`Running "${[command, ...args].join(' ')}"`);
let [status, error] = yield* spawn(command, args);
let [status, error] = yield* spawn(command, args, percy);

// stop percy if running (force stop if there is an error);
await percy?.stop(!!error);
Expand All @@ -94,15 +97,43 @@ export const exec = command('exec', {

// Spawn a command with cross-spawn and return an array containing the resulting status code along
// with any error encountered while running. Uses a generator pattern to handle interupt signals.
async function* spawn(cmd, args) {
async function* spawn(cmd, args, percy) {
let { default: crossSpawn } = await import('cross-spawn');
let proc, closed, error;

try {
proc = crossSpawn(cmd, args, { stdio: 'inherit' });
proc.on('close', code => (closed = code));
proc = crossSpawn(cmd, args, { stdio: 'pipe' });
// Writing stdout of proc to process
if (proc.stdout) {
proc.stdout.on('data', (data) => {
process.stdout.write(`${data}`);
});
}

if (proc.stderr) {
proc.stderr.on('data', (data) => {
process.stderr.write(`${data}`);
});
}

proc.on('error', err => (error = err));

proc.on('close', code => {
closed = code;
if (code !== 0) {
// Only send event when there is a global error code and
// percy token is present
if (process.env.PERCY_TOKEN) {
const myObject = {
errorKind: 'cli',
cliVersion: pkg.version,
message: '1'
};
percy.client.sendBuildEvents(percy.build.id, myObject);
}
}
});

// run until an event is triggered
/* eslint-disable-next-line no-unmodified-loop-condition */
while (closed == null && error == null) {
Expand Down
58 changes: 58 additions & 0 deletions packages/cli-exec/test/exec.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { logger, api, setupTest } from '@percy/cli-command/test/helpers';
import exec from '@percy/cli-exec';
import { getPackageJSON } from '@percy/cli-command/utils';

describe('percy exec', () => {
beforeEach(async () => {
Expand Down Expand Up @@ -130,6 +131,63 @@ describe('percy exec', () => {
]);
});

it('tests process.stdout', async () => {
let stdoutSpy = spyOn(process.stdout, 'write').and.resolveTo('some response');
await exec(['--', 'echo', 'Hi!']);

expect(stdoutSpy).toHaveBeenCalled();
expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual([
'[percy] Percy has started!',
'[percy] Running "echo Hi!"',
'[percy] Finalized build #1: https://percy.io/test/test/123'
]);
});

it('tests process.stderr when token is present', async () => {
const pkg = getPackageJSON(import.meta.url);
let stderrSpy = spyOn(process.stderr, 'write').and.resolveTo('some response');
await expectAsync(
exec(['--', 'node', 'random.js']) // invalid command
).toBeRejectedWithError('EEXIT: 1');

expect(stderrSpy).toHaveBeenCalled();
expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual([
'[percy] Percy has started!',
'[percy] Running "node random.js"',
'[percy] Finalized build #1: https://percy.io/test/test/123'
]);

expect(api.requests['/builds/123/send-events']).toBeDefined();
expect(api.requests['/builds/123/send-events'][0].body).toEqual({
data: {
errorKind: 'cli',
cliVersion: pkg.version,
message: '1'
}
});
});

it('tests process.stderr when token is not present', async () => {
delete process.env.PERCY_TOKEN;
let stderrSpy = spyOn(process.stderr, 'write').and.resolveTo('some response');
await expectAsync(
exec(['--', 'node', 'random.js']) // invalid command
).toBeRejectedWithError('EEXIT: 1');

expect(stderrSpy).toHaveBeenCalled();
expect(logger.stderr).toEqual([
'[percy] Skipping visual tests',
'[percy] Error: Missing Percy token'
]);
expect(logger.stdout).toEqual([
'[percy] Running "node random.js"'
]);

expect(api.requests['/builds/123/send-events']).not.toBeDefined();
});

it('does not run the command if canceled beforehand', async () => {
// delay build creation to give time to cancel
api.reply('/builds', () => new Promise(resolve => {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-snapshot",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.27.4-beta.1",
"@percy/cli-command": "1.27.4",
"yaml": "^2.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/cli-upload/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli-upload",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"engines": {
"node": ">=14"
Expand All @@ -33,7 +33,7 @@
]
},
"dependencies": {
"@percy/cli-command": "1.27.4-beta.1",
"@percy/cli-command": "1.27.4",
"fast-glob": "^3.2.11",
"image-size": "^1.0.0"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-upload/test/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe('percy upload', () => {
widths: [10],
scope: null,
'minimum-height': 10,
'enable-javascript': null
'enable-javascript': null,
'enable-layout': false
},
relationships: {
resources: {
Expand Down
22 changes: 11 additions & 11 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@percy/cli",
"version": "1.27.4-beta.1",
"version": "1.27.4",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
},
"publishConfig": {
"access": "public",
"tag": "beta"
"tag": "latest"
},
"files": [
"bin",
Expand All @@ -31,14 +31,14 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@percy/cli-app": "1.27.4-beta.1",
"@percy/cli-build": "1.27.4-beta.1",
"@percy/cli-command": "1.27.4-beta.1",
"@percy/cli-config": "1.27.4-beta.1",
"@percy/cli-exec": "1.27.4-beta.1",
"@percy/cli-snapshot": "1.27.4-beta.1",
"@percy/cli-upload": "1.27.4-beta.1",
"@percy/client": "1.27.4-beta.1",
"@percy/logger": "1.27.4-beta.1"
"@percy/cli-app": "1.27.4",
"@percy/cli-build": "1.27.4",
"@percy/cli-command": "1.27.4",
"@percy/cli-config": "1.27.4",
"@percy/cli-exec": "1.27.4",
"@percy/cli-snapshot": "1.27.4",
"@percy/cli-upload": "1.27.4",
"@percy/client": "1.27.4",
"@percy/logger": "1.27.4"
}
}
Loading

0 comments on commit 7d50258

Please sign in to comment.