percy / percy-nightwatch

Visual testing with Nightwatch and Percy
https://percy.io
MIT License
6 stars 9 forks source link

How to launch percy using require("child_process").exec; #9

Closed lauterry closed 5 years ago

lauterry commented 5 years ago

Hi

How woud you launch

percy exec -- nightwatch -c test-e2e/conf/nightwatch.conf.local.js --group test-e2e/tests/${process.env.BRAND}/

using const exec = require("child_process").exec; ?

Here is my code :

const exec = require("child_process").exec;

const PERCY_TOKEN = process.env.PERCY_TOKEN;

exec(`percy exec -- nightwatch -c test-e2e/conf/nightwatch.conf.local.js --group test-e2e/tests/${process.env.BRAND}/ -e default`, function(
    err,
    stdout,
    stderr
) {
    if (err) {
        console.log(err);
    } else if (stderr) {
        console.log(stderr);
    }
    console.log(stdout);
});

The problem is that percy does not send data to percy.io ?

In my dashboard, the process keeps running ...

capture d ecran 2018-12-13 a 12 03 26

lauterry commented 5 years ago

Hi

Here is more details about my issue.

When I launch the visual regression tests for one to four tests with one to fous snapshots, it works. I manage to send data to percy.io.

I got in the console :

[percy] stopping percy...
[percy] waiting for 4 snapshots to complete...
[percy] done.
[percy] finalized build #131: https://percy.io/Perfectstay/La-Collection-Air-France/builds/1256151

However, if I run the tests for multiples tests with multiple snapshots, the data are not sent ? Nothing appears in the console.

Why are the data not sent in certains cases ? Is there a limit ?

Best regards

lauterry commented 5 years ago

Ok I managed to send 17 snapshots

[percy] stopping percy...
[percy] waiting for 17 snapshots to complete...
[percy] done.

However it seems that I cannot send 18 snapshots.

lauterry commented 5 years ago

Hi

Good news. I think I have found what was wrong.

The require("child_process").exec has a limit which is the maxBuffer option. (see https://nodejs.org/docs/latest-v8.x/api/child_process.html#child_process_child_process_exec_command_options_callback)

I set the nightwatch detailed_output setting to false to reduce the amount of data to be output.

I managed to send all the data to percy.io.

Sorry for the noise.

djones commented 5 years ago

Very nice catch here @lauterry. Question for you... do you think this is an issue with our SDK or was the exec call happening on your end?

When you run percy exec it calls the spawn function here https://github.com/percy/percy-agent/blob/master/src/commands/exec.ts#L51 and I don't see the same max buffer limitations in the docs for spawn.

lauterry commented 5 years ago

Hi

I think the issue was with the exec call, not in your SDK.

In fact, I prefer to run

percy exec -- nightwatch -c test-e2e/conf/nightwatch.conf.local.js --group test-e2e/tests/${process.env.BRAND}/ -e default

with spawn instead of exec.

How would you do that please ?

I can't figure it out ?

djones commented 5 years ago
percy exec -- nightwatch -c test-e2e/conf/nightwatch.conf.local.js --group test-e2e/tests/${process.env.BRAND}/ -e default

looks very much like how we intend of people integration Percy. Do you hit the same buffer limit if you do that?

I'd love to get a reproducible case going here... I see the max buffer size for exec is 200 * 1024. So I made a quick script for this:

# large-log.sh
for a in `seq 1000000`; do
  echo '.'
done

And then simply running

percy exec -- ./large-log.sh

But I don't get an error... the stdout made by the script is 5 times larger than the max buffer size.

$ percy exec -- ./large-log.sh
[percy] created build #3797: https://percy.io/test/shipyards/builds/1438369
[percy] percy has started.
. # <- 1,000,000 of these in output
[percy] stopping percy...
[percy] waiting for 0 snapshots to complete...
[percy] done.
[percy] finalized build #3797: https://percy.io/test/shipyards/builds/1438369

Any ideas on how we can reproduce this?