From adff8af42c0de97a0cbf989f1847e10b246d1cb4 Mon Sep 17 00:00:00 2001 From: hsd-bot Date: Fri, 30 Oct 2026 11:47:18 -0400 Subject: [PATCH 1/3] build: stamp the package version into the built file header Co-Authored-By: Claude Opus 5.5 --- bower.json | 12 ------------ js/license.js | 1 - make/build.js | 4 +++- spec/VersionSpec.js | 16 ++++++++++++++++ spec/jasmine.json | 3 ++- 5 files changed, 21 insertions(+), 15 deletions(-) delete mode 100644 bower.json create mode 100644 spec/VersionSpec.js diff --git a/bower.json b/bower.json deleted file mode 100644 index 815a9cd..0000000 --- a/bower.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "js-imagediff", - "version": "1.0.4", - "main": "imagediff.js", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ] -} diff --git a/js/license.js b/js/license.js index 9081511..ff2f0c1 100644 --- a/js/license.js +++ b/js/license.js @@ -1,4 +1,3 @@ -// js-imagediff 1.0.3 // (c) 2011-2012 Carl Sutherland, Humble Software // Distributed under the MIT License // For original source and documentation visit: diff --git a/make/build.js b/make/build.js index 438c8c2..4181e2f 100644 --- a/make/build.js +++ b/make/build.js @@ -16,7 +16,9 @@ function write (file, contents) { console.log('Wrote ' + file); } -var license = read('js/license.js'); +// The header names the package version, so it can't drift from it. +var version = require('../package.json').version; +var license = '// js-imagediff ' + version + '\n' + read('js/license.js'); var source = license + '\n' + read('js/imagediff.js'); write('imagediff.js', source); diff --git a/spec/VersionSpec.js b/spec/VersionSpec.js new file mode 100644 index 0000000..816ef10 --- /dev/null +++ b/spec/VersionSpec.js @@ -0,0 +1,16 @@ +// Checks that a built file (IMAGEDIFF_LIBRARY) names the package version in +// its header. The source has no header, so this only runs against a build. +var + fs = require('fs'), + path = require('path'), + version = require('../package.json').version, + library = process.env.IMAGEDIFF_LIBRARY; + +if (library) { + describe('the built file header', function () { + it('names the package version', function () { + var source = fs.readFileSync(path.join(__dirname, '..', library), 'utf8'); + expect(source.split('\n')[0]).toBe('// js-imagediff ' + version); + }); + }); +} diff --git a/spec/jasmine.json b/spec/jasmine.json index 5366cfb..7e484f6 100644 --- a/spec/jasmine.json +++ b/spec/jasmine.json @@ -2,7 +2,8 @@ "spec_files": [ "spec/ImageDiffSpec.js", "spec/CliSpec.js", - "spec/LoadSpec.js" + "spec/LoadSpec.js", + "spec/VersionSpec.js" ], "env": { "random": false From d4b3c6f416a025a63a453cea5940ef13120a7723 Mon Sep 17 00:00:00 2001 From: hsd-bot Date: Fri, 30 Oct 2026 11:47:18 -0400 Subject: [PATCH 2/3] docs: refresh the readme and add a 2.0.0 changelog entry Co-Authored-By: Claude Opus 5.5 --- README.md | 72 ++++++++++++++++++++++++++++++--------------- examples/index.html | 2 +- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 343457e..c89e217 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,18 @@ API NodeJS ------ -js-imagediff is available through the npm. It uses [node-canvas](https://github.com/LearnBoost/node-canvas) which requires lib cairo to be installed. -Install js-imagediff with `npm install -g imagediff`. +js-imagediff is available through npm and needs Node.js 18.12 or later on the 18 line, or 20.9 or later (`^18.12.0 || >=20.9.0`, as node-canvas 3 does). In Node.js it draws with [node-canvas](https://github.com/Automattic/node-canvas) 3, an optional dependency that installs from prebuilt binaries on common platforms; elsewhere it builds from source, which needs Cairo and the other libraries listed in the node-canvas [installation guide](https://github.com/Automattic/node-canvas#installation). + +Install the library with `npm install imagediff` and load it with `require('imagediff')`, or install the command line tool with `npm install -g imagediff`. ### Command Line -* `imagediff [-e|equal] [-t|tolerance VALUE] FILE_A FILE_B` tests equality of two image files with an optional tolerance, printing 'true' or 'false'. -* `imagediff [-d|diff] FILE_A FILE_B OUTPUT_FILE` renders an imagediff between two files, saving as the output file. +* `imagediff [-e|--equal] [-t|--tolerance VALUE] FILE_A FILE_B` tests equality of two image files with an optional tolerance, printing `true` or `false` and exiting with status 0 or 1. +* `imagediff [-d|--diff] FILE_A FILE_B OUTPUT_FILE` renders an imagediff between two files, saving it as a PNG in the output file. ### Cannot find module 'canvas' -Canvas has been moved to an optional dependency for better browser and browserify support. If you see a message that the module cannot be found, please check `npm install` first, incase there was indeed an issue installing it. This relates to https://github.com/HumbleSoftware/js-imagediff/issues/22. Please let me know if you have any issues on account of this, or know of a better work around. +Canvas is an optional dependency for better browser and bundler support, so the library loads without it and reports this error when it first needs a canvas. If you see it in Node.js, check the output of `npm install`, in case node-canvas failed to install. This relates to https://github.com/HumbleSoftware/js-imagediff/issues/22. Unit Testing Canvas ------------------- @@ -51,25 +52,28 @@ To use matchers: beforeEach(function () { jasmine.addMatchers(imagediff.jasmine); }); + + it('draws the expected image', function () { + expect(canvas).toImageDiffEqual(expectedImage, 2); + }); ``` Demo ---- -* A demo is available at http://humblesoftware.github.com/js-imagediff/ -* A Jasmine test demo is available at http://humblesoftware.github.com/js-imagediff/test.html +A demo is available at https://humblesoftware.github.io/js-imagediff/, and the same example is in [`examples/`](examples/) in this repository. Users ----- -* [Flotr2](http://humblesoftware.com/flotr2/) - unit testing +* [Flotr2](https://humblesoftware.com/flotr2/) - unit testing * [Envision.js](https://github.com/HumbleSoftware/envisionjs) - unit testing * [CSS Critic](https://github.com/cburgmer/csscritic) - A CSS regression testing framework -* [HUSL - Human-friendly HSL](http://boronine.com/husl/) - used for regression testing before release. +* [HSLuv (formerly HUSL)](https://www.hsluv.org/) - used for regression testing before release. * [SUCCSS](https://github.com/B2F/Succss) - CSS regression testing. -* [Origami.js](https://github.com/raphamorim/origami.js) - A canvas library +* [Origami.js](https://github.com/raphamorim/origami.js) - A canvas library -If you are using js-imagediff pelase drop us a line and let us know what you are doing with it. +If you are using js-imagediff please drop us a line and let us know what you are doing with it. Development ----------- @@ -94,7 +98,7 @@ npm test * `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 `