Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ docs: trim local setup to the essentials
## Build outputs

`imagediff.js` and `imagediff.min.js` are generated by `npm run build` and committed for releases. Rebuild and commit them only when preparing a release; ordinary PRs change `js/imagediff.js` and leave the built files alone. `npm test` runs against the source, including the CLI, so nothing needs rebuilding to test a change.

## Releasing

On the release PR, after `npm run build` and committing the build outputs, run:

```sh
npm run test:release
```

It rebuilds, runs `npm test` against the built `imagediff.js` and `imagediff.min.js` (through `require` in Node and in a page, along with the CLI specs), and then fails if the fresh build differs from the committed build outputs. Publish only once it passes.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ npm test
* `npm run test:node` runs the specs, including a smoke test of the `imagediff` CLI, in Node.js against [node-canvas](https://github.com/Automattic/node-canvas) (the optional `canvas` dependency, which `npm ci` installs from prebuilt binaries on common platforms).
* `npm run test:browser` runs the specs in headless Chromium with Playwright.
* `npm run test:serve` serves the specs at http://localhost:8085/spec/ to watch them run in a browser.
* `IMAGEDIFF_LIBRARY=imagediff.min.js npm test` runs the same specs against a built file (a path from the repository root) instead of the source: through `require` in Node and as a `<script>` global in Chromium.
* `npm run test:release` builds, runs `npm test` against `imagediff.js` and then `imagediff.min.js`, and fails if the build changed the committed build outputs. Run it on the release PR before publishing; see [CONTRIBUTING.md](CONTRIBUTING.md#releasing).
* `npm run build` (or `make imagediff`) writes `imagediff.js` (license header + `js/imagediff.js`) and `imagediff.min.js`, minified with [terser](https://terser.org/) to ES5 output. Run it only when preparing a release; see [CONTRIBUTING.md](CONTRIBUTING.md#build-outputs).

### Dev container
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test": "npm run test:node && npm run test:browser",
"test:browser": "playwright test --config=spec/playwright.config.js",
"test:node": "jasmine --config=./spec/jasmine.json",
"test:release": "npm run build && IMAGEDIFF_LIBRARY=imagediff.js npm test && IMAGEDIFF_LIBRARY=imagediff.min.js npm test && git diff --exit-code -- imagediff.js imagediff.min.js",
"test:serve": "node spec/server.js"
},
"keywords": [
Expand Down
6 changes: 5 additions & 1 deletion spec/ImageDiffSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var isNode = typeof module !== 'undefined';
var Canvas = isNode && require('canvas');
var imagediff = imagediff || require('../js/imagediff.js');
// IMAGEDIFF_LIBRARY (a path from the repository root) tests a built file
// instead of the source, e.g. IMAGEDIFF_LIBRARY=imagediff.min.js npm test.
var imagediff = imagediff || require(
require('path').join(__dirname, '..', process.env.IMAGEDIFF_LIBRARY || 'js/imagediff.js')
);

describe('ImageUtils', function() {

Expand Down
7 changes: 4 additions & 3 deletions spec/LoadSpec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Loads the library source in a fresh Node process, the way bundlers and
// installs without the optional `canvas` dependency see it.
// Loads the library source (or the build in IMAGEDIFF_LIBRARY) in a fresh
// Node process, the way bundlers and installs without the optional `canvas`
// dependency see it.
var
childProcess = require('child_process'),
path = require('path');

describe('loading imagediff', function () {

var LIBRARY = path.join(__dirname, '..', 'js', 'imagediff.js');
var LIBRARY = path.join(__dirname, '..', process.env.IMAGEDIFF_LIBRARY || 'js/imagediff.js');

// Runs `body` in a child process with `canvas` unresolvable and calls back
// with the JSON it prints.
Expand Down
5 changes: 4 additions & 1 deletion spec/browser/jasmine.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Runs the Jasmine specs in spec/index.html and reports each failed spec.
// IMAGEDIFF_LIBRARY (a path from the repository root) loads a built file
// instead of the source.
var test = require('@playwright/test').test;
var expect = require('@playwright/test').expect;

test('jasmine specs pass in the browser', async function ({ page }) {
var errors = [];
page.on('pageerror', function (error) { errors.push(error.message); });

await page.goto('/spec/');
var library = process.env.IMAGEDIFF_LIBRARY;
await page.goto('/spec/' + (library ? '?lib=' + encodeURIComponent(library) : ''));
await page.waitForFunction(function () {
return window.specResults && window.specResults.done;
});
Expand Down
6 changes: 5 additions & 1 deletion spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
jasmineDone: function (result) { window.specResults.done = result; }
});
</script>
<script src="js/imagediff.js"></script>
<script>
// ?lib= loads a built file instead of the source (see IMAGEDIFF_LIBRARY).
var lib = /[?&]lib=([^&]*)/.exec(window.location.search);
document.write('<script src="' + (lib ? decodeURIComponent(lib[1]) : 'js/imagediff.js') + '"><\/script>');
</script>
<script src="spec/ImageDiffSpec.js"></script>
</head>
<body>
Expand Down
Loading