Skip to content

Instantly share code, notes, and snippets.

@dan2k3k4
Last active June 8, 2017 19:53
Show Gist options
  • Select an option

  • Save dan2k3k4/ca1e2fc7f22f0b0f851305dbb625f404 to your computer and use it in GitHub Desktop.

Select an option

Save dan2k3k4/ca1e2fc7f22f0b0f851305dbb625f404 to your computer and use it in GitHub Desktop.

Revisions

  1. dan2k3k4 revised this gist Jun 8, 2017. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,7 @@ if (isset($matches[1])) {
    $url = trim($matches[1]);

    // Generate screenshot of frontpage
    $headlessChrome = sprintf('/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --disable-gpu --screenshot --window-size=1920,1080 http://%s', $url);
    exec($headlessChrome, $output);
    exec(sprintf('/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --disable-gpu --screenshot --window-size=1920,1080 http://%s', $url));

    // Move screenshot.png to tests-visual/ directory
    if (is_file('screenshot.png')) {
    @@ -32,8 +31,8 @@ if (isset($matches[1])) {

    // Lets diff our screenshot and open that too
    if (is_file('tests-visual/screenshot-old.png')) {
    exec('compare tests-visual/screenshot-old.png tests-visual/screenshot.png -compose src tests-visual/diff.png', $output);
    exec('compare tests-visual/screenshot-old.png tests-visual/screenshot.png tests-visual/diff.png');

    exec('open tests-visual/diff.png', $output);
    exec('open tests-visual/diff.png');
    }
    }
  2. dan2k3k4 created this gist Jun 8, 2017.
    39 changes: 39 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/usr/local/bin/php

    <?php
    /**
    * Just a quick script for Headless Chrome testing
    */

    if (!is_dir('tests-visual')) {
    mkdir('tests-visual', 0777);
    }

    // Rename older screenshot to screenshot-old
    if (is_file('tests-visual/screenshot.png')) {
    rename('tests-visual/screenshot.png', 'tests-visual/screenshot-old.png');
    }

    // Get URL to test
    $pattern = '/hostname: &hostname ([^ ]+)/';
    preg_match($pattern, file_get_contents('docker-compose.yml'), $matches);
    if (isset($matches[1])) {
    // We can now test our app
    $url = trim($matches[1]);

    // Generate screenshot of frontpage
    $headlessChrome = sprintf('/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --disable-gpu --screenshot --window-size=1920,1080 http://%s', $url);
    exec($headlessChrome, $output);

    // Move screenshot.png to tests-visual/ directory
    if (is_file('screenshot.png')) {
    rename('screenshot.png', 'tests-visual/screenshot.png');
    }

    // Lets diff our screenshot and open that too
    if (is_file('tests-visual/screenshot-old.png')) {
    exec('compare tests-visual/screenshot-old.png tests-visual/screenshot.png -compose src tests-visual/diff.png', $output);

    exec('open tests-visual/diff.png', $output);
    }
    }