Skip to content

Commit

Permalink
Move tests to plugins (jimp-dev#592)
Browse files Browse the repository at this point in the history
* create test utils, move print's test to print

* move browser testing to root

* move autocrop test

* these can just be test

* move blit test

* move color tests

* move and split cover/contain

* move mask tests

* move normalize test

* move resize test

* move rotate tests

* convert jimp to use test-utils

* move test utils

* now resides in test-utils

* must configure jimp with plugins for these functions

* test node no more

* move some tests to core

* these two things are tested alot elsewhere

* rename samples to images

* split up fileTypes test

* Revert "move some tests to core"

d4fa37b

* fix circular deps

* fix lint

* fix dirnmae

* correct image path

* move image

* correct path

* babel requires node 6.9

* correct name in workflow

* same dependancies are installed regardless of node version

* maybe just attach to old directory

* change working directory. seems like the install was needed

* try increasing timeout

* maybe sync will pass?

* increase timeout for CI

* add result image

* correct path

* get tests passing

* better test output

* see if you can run parallel
  • Loading branch information
hipstersmoothie authored and turakvlad committed Sep 3, 2018
1 parent 7d0bfc4 commit 5895a34
Show file tree
Hide file tree
Showing 129 changed files with 973 additions and 394 deletions.
23 changes: 13 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,25 @@ jobs:
- run:
name: Test
command: yarn test --ci
- run:
name: Test Browser
command: yarn test:browser --ci

build-node6:
working_directory: ~/jimp-6
build-node6.14:
working_directory: ~/jimp-6.14
docker:
- image: circleci/node:6-browsers
- image: circleci/node:6.14-browsers
steps:
- checkout
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
command: yarn install --frozen-lockfile --network-timeout 100000
- run:
name: Build Packages
command: yarn build
- run:
name: Test
command: yarn test:node --ci
command: yarn test --ci

build-node8:
working_directory: ~/jimp-8
Expand All @@ -79,13 +82,13 @@ jobs:
- checkout
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
command: yarn install --frozen-lockfile --network-timeout 100000
- run:
name: Build Packages
command: yarn build
- run:
name: Test
command: yarn test:node --ci
command: yarn test --ci

build-node10:
working_directory: ~/jimp-10
Expand All @@ -95,13 +98,13 @@ jobs:
- checkout
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
command: yarn install --frozen-lockfile --network-timeout 100000
- run:
name: Build Packages
command: yarn build
- run:
name: Test
command: yarn test:node --ci
command: yarn test --ci

workflows:
version: 2
Expand All @@ -123,7 +126,7 @@ workflows:
filters:
tags:
only: /.*/
- build-node6:
- build-node6.14:
requires:
- lint
- test
Expand Down
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ You can use the coverage report to help with missed tests, but you must be aware
While developing you may want to test only on node.js:

```sh
yarn test:node
yarn test
```

...or only one test file:

```sh
yarn test:node test/some.test.js
yarn test test/some.test.js
```

...or run each time a file changes:

```sh
yarn test:node:watch
yarn test:watch
```

...or test only in a specific browser:
Expand Down
11 changes: 4 additions & 7 deletions packages/jimp/karma.conf.js → karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

module.exports = function(config) {
config.set({
basePath: '../..',

browserDisconnectTimeout: 25000,
browserNoActivityTimeout: 25000,

Expand All @@ -18,14 +16,14 @@ module.exports = function(config) {
},

preprocessors: {
'packages/jimp/**/*.js': 'browserify'
'packages/**/**/*.js': 'browserify'
},

// list of files / patterns to load in the browser
files: [
'packages/jimp/test/*.js',
'./packages/**/test/*.js',
{
pattern: 'packages/jimp/test/samples/**/*',
pattern: 'packages/**/test/images/**/*',
watched: false,
included: false,
served: true
Expand All @@ -39,8 +37,7 @@ module.exports = function(config) {
],

proxies: {
'/node_modules/@jimp/plugin-print/fonts/':
'/base/packages/plugin-print/fonts/'
'/packages/plugin-print/fonts/': '/base/packages/plugin-print/fonts/'
},

// level of logging
Expand Down
28 changes: 25 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
},
"scripts": {
"lint": "xo",
"test": "lerna run test --stream",
"test:node": "lerna run test:node --stream",
"test": "cross-env BABEL_ENV=test mocha --require @babel/register './packages/**/test/**/*.test.js'",
"test:watch": "npm run test -- --reporter min --watch",
"test:browser": "cross-env BABEL_ENV=test ENV=browser CHROME_BIN=\"$(which chrome || which chromium)\" karma start --single-run",
"test:browser:watch": "npm run -s test:browser start -- --auto-watch",
"clean": "lerna clean --yes && rm -rf node_modules && npm run clean:build",
"clean:build": "rm -rf packages/**/es packages/**/dist",
"build": "npm run clean:build && lerna run build --stream",
Expand Down Expand Up @@ -40,7 +42,21 @@
"should": "^13.2.3",
"source-map-support": "^0.5.9",
"tfilter": "^1.0.1",
"xo": "^0.22.0"
"xo": "^0.22.0",
"babelify": "^9.0.0",
"browserify": "^16.2.2",
"envify": "^4.1.0",
"express": "^4.16.3",
"karma": "^3.0.0",
"karma-browserify": "^5.3.0",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.1.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"mocha": "^5.2.0",
"nyc": "^13.0.1",
"uglify-js": "^3.4.8",
"watchify": "^3.11.0"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -92,6 +108,12 @@
"max-params": [
1,
6
],
"import/no-extraneous-dependencies": [
1,
{
"devDependencies": true
}
]
},
"overrides": [
Expand Down
7 changes: 3 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
"url": "https://github.com/oliver-moran/jimp/issues"
},
"scripts": {
"test:node": "cross-env BABEL_ENV=test mocha --require @babel/register test/**/*.js",
"test:node:watch": "npm run test:node -- --reporter min --watch",
"test:node:coverage": "nyc npm run test:node",
"test": "npm run test:node:coverage",
"test": "cross-env BABEL_ENV=test mocha --require @babel/register test/**/*.js",
"test:watch": "npm run test -- --reporter min --watch",
"test:coverage": "nyc npm run test",
"build": "npm run build:node:production && npm run build:module",
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
"build:debug": "npm run build:node:debug",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,15 @@ class Jimp extends EventEmitter {
}
}

export function addConstants(constants) {
export function addConstants(constants, jimpInstance = Jimp) {
Object.entries(constants).forEach(([name, value]) => {
Jimp[name] = value;
jimpInstance[name] = value;
});
}

export function addJimpMethods(methods) {
export function addJimpMethods(methods, jimpInstance = Jimp) {
Object.entries(methods).forEach(([name, value]) => {
Jimp.prototype[name] = value;
jimpInstance.prototype[name] = value;
});
}

Expand Down
22 changes: 15 additions & 7 deletions packages/custom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Jimp, {
jimpEvChange
} from '@jimp/core';

export default function configure(configuration) {
export default function configure(configuration, jimpInstance = Jimp) {
const jimpConfig = {
hasAlpha: {},
encoders: {},
Expand Down Expand Up @@ -38,7 +38,6 @@ export default function configure(configuration) {

function addPlugin(pluginModule) {
const plugin = pluginModule(jimpEvChange) || {};

if (!plugin.class && !plugin.constants) {
// Default to class function
addToConfig({ class: plugin });
Expand All @@ -50,17 +49,26 @@ export default function configure(configuration) {
if (configuration.types) {
configuration.types.forEach(addImageType);

Jimp.decoders = jimpConfig.decoders;
Jimp.encoders = jimpConfig.encoders;
Jimp.hasAlpha = jimpConfig.hasAlpha;
jimpInstance.decoders = {
...jimpInstance.decoders,
...jimpConfig.decoders
};
jimpInstance.encoders = {
...jimpInstance.encoders,
...jimpConfig.encoders
};
jimpInstance.hasAlpha = {
...jimpInstance.hasAlpha,
...jimpConfig.hasAlpha
};
}

if (configuration.plugins) {
configuration.plugins.forEach(addPlugin);
}

addJimpMethods(jimpConfig.class);
addConstants(jimpConfig.constants);
addJimpMethods(jimpConfig.class, jimpInstance);
addConstants(jimpConfig.constants, jimpInstance);

return Jimp;
}
28 changes: 5 additions & 23 deletions packages/jimp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
"url": "https://github.com/oliver-moran/jimp/issues"
},
"scripts": {
"test:browser": "cross-env BABEL_ENV=test ENV=browser CHROME_BIN=\"$(which chrome || which chromium)\" karma start --single-run",
"test:browser:watch": "npm run -s test:browser start -- --auto-watch",
"test:node": "cross-env BABEL_ENV=test mocha --require @babel/register",
"test:node:watch": "npm run test:node -- --reporter min --watch",
"test:node:coverage": "nyc npm run test:node",
"test": "npm run -s test:node:coverage && npm run -s test:browser",
"test": "cross-env BABEL_ENV=test mocha --require @babel/register",
"test:watch": "npm run test -- --reporter min --watch",
"test:coverage": "nyc npm run test",
"browser-build": "node tools/browser-build.js test",
"build": "npm run build:browser && npm run build:node:production && npm run build:module",
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
Expand Down Expand Up @@ -61,23 +58,8 @@
"core-js": "^2.5.7"
},
"devDependencies": {
"babelify": "^9.0.0",
"browserify": "^16.2.2",
"envify": "^4.1.0",
"express": "^4.16.3",
"husky": "^1.0.0-rc.13",
"karma": "^3.0.0",
"karma-browserify": "^5.3.0",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.1.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"mocha": "^5.2.0",
"nyc": "^13.0.1",
"should": "^13.2.3",
"tfilter": "^1.0.1",
"uglify-js": "^3.4.8",
"watchify": "^3.11.0"
"@jimp/test-utils": "^0.3.9",
"express": "^4.16.3"
},
"xo": false,
"nyc": {
Expand Down
4 changes: 2 additions & 2 deletions packages/jimp/test/async.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import should from 'should';
import { Jimp, getTestDir } from './test-helper';
import { Jimp, getTestDir } from '@jimp/test-utils';

const imagesDir = getTestDir() + '/samples';
const imagesDir = getTestDir(__dirname) + '/images';

describe('Async functions', () => {
it('write returns promise', async () => {
Expand Down
17 changes: 11 additions & 6 deletions packages/jimp/test/callbacks.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Jimp, mkJGD, hasOwnProp } from './test-helper';
import { Jimp, mkJGD, hasOwnProp } from '@jimp/test-utils';

import configure from '@jimp/custom';
import plugins from '@jimp/plugins';

const jimp = configure({ plugins: [plugins] }, Jimp);

describe('Callbacks', () => {
const targetJGD = mkJGD('▴▸▾', '◆▪▰', '▵▹▿');
Expand All @@ -8,8 +13,8 @@ describe('Callbacks', () => {
let miniImg; // stores the Jimp instances of the JGD images above.

before(done => {
const img1 = Jimp.read(targetJGD);
const img2 = Jimp.read(miniJGD);
const img1 = jimp.read(targetJGD);
const img2 = jimp.read(miniJGD);
Promise.all([img1, img2])
.then(images => {
targetImg = images[0];
Expand Down Expand Up @@ -195,15 +200,15 @@ describe('Callbacks', () => {
result: ['▴▸▾', '◆▪▰', '▵▹▿']
},
cover: {
args: [3, 2, Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP],
args: [3, 2, jimp.HORIZONTAL_ALIGN_LEFT | jimp.VERTICAL_ALIGN_TOP],
result: ['▴▸▾', '◆▪▰']
},
contain: {
args: [3, 2, Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP],
args: [3, 2, jimp.HORIZONTAL_ALIGN_LEFT | jimp.VERTICAL_ALIGN_TOP],
result: {
width: 3,
height: 2,
data: [0xaa8e1cff, 0x3955c6ff, 0, 0xaa8e1caa, 0x3955c6aa, 0]
data: [0xaa8e1cff, 0x3955c6ff, 0, 0x715f13aa, 0x263984aa, 0]
}
},
opaque: {
Expand Down
2 changes: 1 addition & 1 deletion packages/jimp/test/colordiff.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Jimp } from './test-helper';
import { Jimp } from '@jimp/test-utils';

// Convert [0..1] float to a percent value with only one decimal.
const pct = n => ((n * 1000) << 0) / 10;
Expand Down
Loading

0 comments on commit 5895a34

Please sign in to comment.