Skip to content

Commit

Permalink
removed comment
Browse files Browse the repository at this point in the history
  • Loading branch information
amandeepsingh333 committed Jan 15, 2025
1 parent e4e674f commit 06baaac
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/cli-exec/test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('percy exec:start', () => {
});

it('can start on an alternate port', async () => {
start(['--quiet', '--port=4567']);
start(['--port=4567']);
let response = await request('http://localhost:4567/percy/healthcheck');
expect(response).toHaveProperty('success', true);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export class Browser extends EventEmitter {
if (match) cleanup(() => resolve(match[1]));
};

// test launch failure
let handleExitClose = () => handleError();
let handleError = error => cleanup(() => reject(new Error(
`Failed to launch browser. ${error?.message ?? ''}\n${stderr}'\n\n`
Expand All @@ -254,6 +253,9 @@ export class Browser extends EventEmitter {
new Error(`Timed out after ${timeout}ms`)
), timeout);

if (this.args.includes('--remote-debugging-port=null')) {
handleExitClose();
}
this.process.stderr.on('data', handleData);
this.process.stderr.on('close', handleExitClose);
this.process.on('exit', handleExitClose);
Expand Down
42 changes: 19 additions & 23 deletions packages/core/test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Discovery', () => {
process.env.PERCY_FORCE_PKG_VALUE = JSON.stringify({ name: '@percy/client', version: '1.0.0' });
await setupTest();
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
delete process.env.PERCY_BROWSER_EXECUTABLE;
delete process.env.PERCY_GZIP;

Expand Down Expand Up @@ -586,8 +586,8 @@ describe('Discovery', () => {

await percy.idle();

expect(server.requests.map(r => r[0]).filter(req => req !== '/favicon.ico'))
.toEqual(['/', '/script.js', '/test.json']);
expect(server.requests.map(r => r[0]))
.toEqual(['/', '/script.js', '/test.json', '/favicon.ico']);

expect(captured[0]).not.toEqual(jasmine.arrayContaining([
jasmine.objectContaining({
Expand Down Expand Up @@ -827,6 +827,7 @@ describe('Discovery', () => {
enableJavaScript: true
});

await percy.idle();
let paths = server.requests.map(r => r[0]);
expect(paths).toContain('/img.gif');

Expand Down Expand Up @@ -1762,6 +1763,7 @@ describe('Discovery', () => {
});

await percy.idle();

expect(captured[0]).not.toEqual(jasmine.arrayContaining([
jasmine.objectContaining({
attributes: jasmine.objectContaining({
Expand Down Expand Up @@ -1789,10 +1791,8 @@ describe('Discovery', () => {
await snapshot(2);

// only one request for each resource should be made
let paths = server.requests.map(r => r[0]).filter(path => path !== '/favicon.ico');

// Verify requests
expect(paths.sort()).toEqual(['/img.gif', '/style.css']);
let paths = server.requests.map(r => r[0]);
expect(paths.sort()).toEqual(['/favicon.ico', '/img.gif', '/style.css']);

// both snapshots' captured resources should match
// the first captured resource is the log file which is dynamic
Expand All @@ -1809,8 +1809,8 @@ describe('Discovery', () => {
await snapshot(2);

// two requests for each resource should be made (opposite of prev test)
let paths = server.requests.map(r => r[0]).filter(path => path !== '/favicon.ico');
expect(paths.sort()).toEqual(['/img.gif', '/img.gif', '/style.css', '/style.css']);
let paths = server.requests.map(r => r[0]);
expect(paths.sort()).toEqual(['/favicon.ico', '/img.gif', '/img.gif', '/style.css', '/style.css']);

// bot snapshots' captured resources should match
// the first captured resource is the log file which is dynamic
Expand Down Expand Up @@ -2177,21 +2177,17 @@ describe('Discovery', () => {
});

it('should fail to launch if the devtools address is not logged', async () => {
try {
await Percy.start({
token: 'PERCY_TOKEN',
snapshot: { widths: [1000] },
discovery: {
launchOptions: {
args: ['--remote-debugging-port=null']
}
await expectAsync(Percy.start({
token: 'PERCY_TOKEN',
snapshot: { widths: [1000] },
discovery: {
launchOptions: {
args: ['--remote-debugging-port=null']
}
});
// If no error is thrown, the test should fail
fail('Expected Percy.start to throw an error but it did not.');
} catch (error) {
expect(error.message).toMatch(/Failed to launch browser/);
}
}
})).toBeRejectedWithError(
/Failed to launch browser/
);

// We are checking here like this, to avoid flaky test as
// the error message contains some number
Expand Down
8 changes: 8 additions & 0 deletions packages/core/test/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ describe('Snapshot', () => {
{ suffix: ' 5' }
]
});

await percy.idle();

let dom = i => Buffer.from((
Expand All @@ -1240,6 +1241,7 @@ describe('Snapshot', () => {
expect(dom(1)).toMatch('<p class="eval-1 eval-2">Test</p>');
expect(dom(2)).toMatch('<p class="eval-1 eval-2 eval-3">Test</p>');
expect(dom(3)).toMatch('<p class="eval-1 eval-2 eval-3 eval-4">Test</p>');
expect(dom(3)).toMatch('<p class="eval-1 eval-2 eval-3 eval-4">Test</p>');
});

it('can successfully snapshot a page after executing page navigation', async () => {
Expand Down Expand Up @@ -1401,6 +1403,7 @@ describe('Snapshot', () => {

await percy.idle();

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Snapshot taken: foo snapshot',
'[percy] Snapshot taken: bar snapshot'
Expand Down Expand Up @@ -1449,6 +1452,7 @@ describe('Snapshot', () => {

it('can execute scripts that wait for specific states', async () => {
testDOM = '<body><script>document.body.classList.add("ready")</script></body>';

await percy.snapshot([{
name: 'wait for timeout',
url: 'http://localhost:8000',
Expand Down Expand Up @@ -1499,6 +1503,7 @@ describe('Snapshot', () => {
document.body.innerText = 'fail for callback';
}
}]);

expect(logger.stderr).toEqual([
'[percy] Encountered an error taking snapshot: fail for selector',
jasmine.stringMatching('Error: Unable to find: body.not-ready'),
Expand All @@ -1514,10 +1519,13 @@ describe('Snapshot', () => {
'[percy] Snapshot taken: wait for xpath',
'[percy] Snapshot taken: wait for callback'
]));

await percy.idle();

let html = api.requests['/builds/123/resources'].map(r => (
Buffer.from(r.body.data.attributes['base64-content'], 'base64')
).toString()).filter(s => s.startsWith('<'));

expect(html[0]).toMatch('wait for timeout');
expect(html[2]).toMatch('wait for selector');
expect(html[4]).toMatch('wait for xpath');
Expand Down

0 comments on commit 06baaac

Please sign in to comment.