Skip to content

Commit

Permalink
Merge pull request #32 from reg-viz/introduce-ts
Browse files Browse the repository at this point in the history
Migration to TypeScript, Jest, and GH actions
  • Loading branch information
Quramy authored Oct 1, 2020
2 parents 4a8895c + 93720cb commit e6496af
Show file tree
Hide file tree
Showing 39 changed files with 3,653 additions and 2,504 deletions.
50 changes: 0 additions & 50 deletions .circleci/config.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: build

on: [pull_request, push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
yarn --frozen-lockfile
yarn build
yarn lint
yarn test:ci
env:
CI: true
# - uses: codecov/codecov-action@v1
# with:
# name: jest
# token: ${{ secrets.CODECOV_TOKEN }}
# file: ./coverage/coverage-final.json
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: publish

on: push

jobs:
publish:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm publish
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > ~/.npmrc
npm whoami
yarn --frozen-lockfile
yarn build
npm publish
if: contains(github.ref, 'tags/v')
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
CI: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ typings/

*_generated.*
.performance/

lib/
*.tsbuildinfo
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
lib/
coverage/
*.tsbuildinfo
*.png
.gitignore
.npmignore
node_modules/
*.sh
*.log
.env
.env.*
example/
7 changes: 7 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
trailingComma: all
tabWidth: 2
semi: true
singleQuote: false
bracketSpacing: true
printWidth: 120
arrowParens: avoid
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
language: node_js

node_js:
- "6"
- "8"
- "12"

script: npm run perf
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# img-diff-js

[![CircleCI](https://circleci.com/gh/reg-viz/img-diff-js.svg?style=svg)](https://circleci.com/gh/reg-viz/img-diff-js)
[![github actions](https://github.com/reg-viz/img-diff-js/workflows/build/badge.svg)](https://github.com/reg-viz/img-diff-js/actions)
[![Build Status](https://travis-ci.org/reg-viz/img-diff-js.svg?branch=master)](https://travis-ci.org/reg-viz/img-diff-js)
[![Greenkeeper badge](https://badges.greenkeeper.io/reg-viz/img-diff-js.svg)](https://greenkeeper.io/)
[![npm version](https://badge.fury.io/js/img-diff-js.svg)](https://badge.fury.io/js/img-diff-js)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)


:art: Node.js library to compare 2 images without native libs.

| Actual | Expected | Difference |
|:---:|:---:|:---:|
| Actual | Expected | Difference |
| :---------------------------: | :-------------------------------: | :-----------------------: |
| ![actual](example/actual.png) | ![expected](example/expected.png) | ![diff](example/diff.png) |

## Install
Expand All @@ -20,18 +18,19 @@ npm install img-diff-js
```

```js
const { imgDiff } = require('img-diff-js');
const { imgDiff } = require("img-diff-js");

imgDiff({
actualFilename: 'example/actual.png',
expectedFilename: 'example/expected.png',
diffFilename: 'example/diff.png',
actualFilename: "example/actual.png",
expectedFilename: "example/expected.png",
diffFilename: "example/diff.png",
}).then(result => console.log(result));
```

## API Usage

### `imgDiff(opt: ImgDiffOptions): Promise<ImgDiffResult>`

Create image differential between two images.

#### `ImgDiffOptions`
Expand All @@ -49,11 +48,11 @@ Create image differential between two images.
}
```

- `actualFilename` - *Required* - Path to actual image file.
- `expectedFilename` - *Required* - Path to expected image file.
- `diffFilename` - *Optional* - Path to differential image file. If omitted, `imgDiff` does not output image file.
- `generateOnlyDiffFile` - *Optional* - Generate only files with difference
- `options` - *Optional* - An object to pass through [pixelmatch](https://github.com/mapbox/pixelmatch#api).
- `actualFilename` - _Required_ - Path to actual image file.
- `expectedFilename` - _Required_ - Path to expected image file.
- `diffFilename` - _Optional_ - Path to differential image file. If omitted, `imgDiff` does not output image file.
- `generateOnlyDiffFile` - _Optional_ - Generate only files with difference
- `options` - _Optional_ - An object to pass through [pixelmatch](https://github.com/mapbox/pixelmatch#api).

#### `ImgDiffResult`

Expand Down Expand Up @@ -86,15 +85,16 @@ The output image format is PNG only.

## Performance

| case name | img-diff-js | image-difference | image-diff |
|:---|---:|---:|---:|
| 50 same dimension PNGs | 936 msec | 11018 msec | 16539 msec |
| 50 different dimension PNGs | 715 msec | 16077 msec | 16639 msec |
| 50 same dimension JPEGs | 1076 msec | 10910 msec | 19078 msec |
| case name | img-diff-js | image-difference | image-diff |
| :-------------------------- | ----------: | ---------------: | ---------: |
| 50 same dimension PNGs | 376 msec | 1967 msec | 3143 msec |
| 50 different dimension PNGs | 274 msec | 2979 msec | 3520 msec |
| 50 same dimension JPEGs | 449 msec | 2422 msec | 4376 msec |

The above table was captured under [Travis-CI](https://travis-ci.org/reg-viz/img-diff-js). If you want the latest result, check the raw log.

## Contribute

PR or issue is welcome :)

### Setup
Expand Down
14 changes: 0 additions & 14 deletions lib/decode-jpeg.js

This file was deleted.

21 changes: 0 additions & 21 deletions lib/decode-png.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/decode-tiff.js

This file was deleted.

82 changes: 0 additions & 82 deletions lib/index.js

This file was deleted.

Loading

0 comments on commit e6496af

Please sign in to comment.