Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Module tests #748

Merged
merged 4 commits into from Feb 5, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -40,5 +40,7 @@ todo.txt
test.js
output.txt
output/
test/core/modules/test_outputs
test/core/modules/test_outputs/*
node_modules/
node_modules/*
@@ -48,6 +48,7 @@
"urify": "^2.1.1"
},
"devDependencies": {
"base64-img": "^1.0.4",
"browserify": "16.2.3",
"grunt": "^1.0.3",
"grunt-browser-sync": "^2.2.0",
@@ -1,22 +1,41 @@
var test = require('tape');
var base64Img = require('base64-img');
var looksSame = require('looks-same');

require('../../../src/ImageSequencer.js');

var sequencer1 = ImageSequencer({ ui: false });
var options = {brightness : 50};
var red = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
var sequencer = ImageSequencer({ ui: false });
var options = {brightness : 1};
var target = 'test_outputs';
var red = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg==";
var benchmark = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAAHdElNRQfjAgULAir0wiRrAAAADUlEQVQY02NgGAXIAAABEAAB7JfjegAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxOS0wMi0wNVQxMTowMjo0MiswMjowMCdP+X4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTktMDItMDVUMTE6MDI6NDIrMDI6MDBWEkHCAAAAAElFTkSuQmCC";

// Test 1 to check brightness module is getting loaded
test('Load brightness module', function(t) {
sequencer1.loadImages('image1', red);
sequencer1.addSteps('brightness', options);
t.equal(sequencer1.images.image1.steps[1].options.name, "brightness", "Brightness module is getting loaded.");
t.end();
sequencer.loadImages('test', red);
sequencer.addSteps('brightness', options);
t.equal(sequencer.images.test.steps[1].options.name, 'brightness', 'Brightness module is getting loaded');
t.end();
});

// Test 2 to check options are correct
test('Check Options', function(t) {
sequencer1.loadImages('image1', red);
sequencer1.addSteps('brightness', options);
t.equal(sequencer1.images.image1.steps[1].options.brightness, 50, "Options are correct");
t.end();
});
t.equal(sequencer.images.test.steps[1].options.brightness, 1, 'Options are correct');
t.end();
});

// Test 3 to check brightness module works as expected
test('Brightness module works correctly', function(t) {
sequencer.run({ mode: 'test' }, function(out) {
var result = sequencer.images.test.steps[1].output.src
base64Img.imgSync(result, target, 'result')
base64Img.imgSync(benchmark, target, 'benchmark')
result = './test_outputs/result.png'
benchmark = './test_outputs/benchmark.png'
looksSame(result, benchmark, function(err, res) {
if (err) console.log(err)
t.equal(res.equal, true)
t.end()
})
})
})
@@ -0,0 +1,41 @@
var test = require('tape')
var base64Img = require('base64-img')
var looksSame = require('looks-same')

require('../../../src/ImageSequencer')

var sequencer = ImageSequencer({ui: false})
var red = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg=="
var benchmark = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAHklEQVQ4T2Pc4u39n4ECwDhqAMNoGDCMhgHDsAgDALGCJKF4bsMPAAAAAElFTkSuQmCC"
var target = 'test_outputs'

var options = {contrast: -40}

test('Contrast module loads correctly', function(t) {
sequencer.loadImages('test', red)
sequencer.addSteps('test', 'contrast')
t.equal(sequencer.images.test.steps.length, 2, 'Contrast module loaded')
t.end()
})

test('Contrast module loads with correct options', function(t) {
sequencer.addSteps('test', 'contrast', options)
t.equal(sequencer.images.test.steps[2].options.contrast, -40, 'options loaded correctly')
t.end()
})

test('Contrast module works correctly', function(t) {
sequencer.run({mode:'test'}, function(out) {
var result = sequencer.images.test.steps[2].output.src
base64Img.imgSync(result, target, 'result')
base64Img.imgSync(benchmark, target, 'benchmark')
result = './test_outputs/result.png'
benchmark = './test_outputs/benchmark.png'
looksSame(result, benchmark, function(err, res) {
if (err) console.log(err)
t.equal(res.equal, true)
t.end()
})
})
})

This file was deleted.

@@ -0,0 +1,72 @@
'use strict';

var test = require('tape');
var looksSame = require('looks-same');
var DataURItoBuffer = require('data-uri-to-buffer');
var base64Img = require('base64-img');

// We should only test headless code here.
// http://stackoverflow.com/questions/21358015/error-jquery-requires-a-window-with-a-document#25622933

require('../../../src/ImageSequencer.js');

//require image files as DataURLs so they can be tested alike on browser and Node.
var sequencer = ImageSequencer({ ui: false });
var target = 'test_outputs'

var red = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg==";
var invert = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAHklEQVQ4T2Nk/P//PwMFgHHUAIbRMGAYDQOGYREGAPACL/GqhhwEAAAAAElFTkSuQmCC";

//Tests for Invert module

test("Load invert module", function(t) {
sequencer.loadImages('test', red);
t.equal(sequencer.images.test.steps.length, 1,'Image loaded')
sequencer.addSteps('test','invert');
t.equal(sequencer.images.test.steps[1].options.name, 'invert', 'Invert step added')
t.end()
})

test("Inverted image isn't identical", function(t) {
sequencer.run({ mode: 'test' }, function(out) {
var input = sequencer.images.test.steps[0].output.src;
var output = sequencer.images.test.steps[1].output.src;
input = DataURItoBuffer(input);
output = DataURItoBuffer(output);
t.notEqual(input,output,'Not equal')
t.end()
})
});

test("Twice inverted image is identical to original image", function(t) {
sequencer.addSteps('test','invert');
sequencer.run({ mode: 'test' }, function(out) {
var input = sequencer.images.test.steps[0].output.src
var output = sequencer.images.test.steps[2].output.src
base64Img.imgSync(input, target, 'input')
base64Img.imgSync(output, target, 'output')
input = './test_outputs/input.png'
output = './test_outputs/output.png'
looksSame(input, output, function(err, res) {
if (err) console.log(err)
t.equal(res.equal, true)
t.end();
});
})
});

test("Invert module produces correct output", function(t) {
sequencer.run({ mode: 'test' }, function(out) {
var result = sequencer.images.test.steps[1].output.src
var benchmark = invert
base64Img.imgSync(result, target, 'result')
base64Img.imgSync(benchmark, target, 'benchmark')
result = './test_outputs/result.png'
benchmark = './test_outputs/benchmark.png'
looksSame(result, benchmark, function(err, res) {
if (err) console.log(err)
t.equal(res.equal, true)
t.end()
})
})
})
@@ -87,6 +87,14 @@ after@0.8.2:
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"
integrity sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=

ajax-request@^1.2.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/ajax-request/-/ajax-request-1.2.3.tgz#99fcbec1d6d2792f85fa949535332bd14f5f3790"
integrity sha1-mfy+wdbSeS+F+pSVNTMr0U9fN5A=
dependencies:
file-system "^2.1.1"
utils-extend "^1.0.7"

ajv@^5.3.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
@@ -344,6 +352,14 @@ base64-arraybuffer@0.1.5:
resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz#73926771923b5a19747ad666aa5cd4bf9c6e9ce8"
integrity sha1-c5JncZI7Whl0etZmqlzUv5xunOg=

base64-img@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/base64-img/-/base64-img-1.0.4.tgz#3e22d55d6c74a24553d840d2b1bc12a7db078d35"
integrity sha1-PiLVXWx0okVT2EDSsbwSp9sHjTU=
dependencies:
ajax-request "^1.2.0"
file-system "^2.1.0"

base64-js@^1.0.2:
version "1.3.0"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3"
@@ -998,7 +1014,7 @@ color-name@1.1.3:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=

colors@~1.1.2:
colors@1.1.2, colors@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
integrity sha1-FopHAXVran9RoSzgyXv6KMCE7WM=
@@ -2037,6 +2053,21 @@ figures@^1.0.1, figures@^1.4.0:
escape-string-regexp "^1.0.5"
object-assign "^4.1.0"

file-match@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/file-match/-/file-match-1.0.2.tgz#c9cad265d2c8adf3a81475b0df475859069faef7"
integrity sha1-ycrSZdLIrfOoFHWw30dYWQafrvc=
dependencies:
utils-extend "^1.0.6"

file-system@^2.1.0, file-system@^2.1.1:
version "2.2.2"
resolved "https://registry.yarnpkg.com/file-system/-/file-system-2.2.2.tgz#7d65833e3a2347dcd956a813c677153ed3edd987"
integrity sha1-fWWDPjojR9zZVqgTxncVPtPt2Yc=
dependencies:
file-match "^1.0.1"
utils-extend "^1.0.4"

filename-regex@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"
@@ -3159,6 +3190,23 @@ isstream@~0.1.2:
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=

jasmine-core@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-3.3.0.tgz#dea1cdc634bc93c7e0d4ad27185df30fa971b10e"
integrity sha512-3/xSmG/d35hf80BEN66Y6g9Ca5l/Isdeg/j6zvbTYlTzeKinzmaTM4p9am5kYqOmE05D7s1t8FGjzdSnbUbceA==

jasmine-jquery@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/jasmine-jquery/-/jasmine-jquery-2.1.1.tgz#d4095e646944a26763235769ab018d9f30f0d47b"
integrity sha1-1AleZGlEomdjI1dpqwGNnzDw1Hs=

jasmine-spec-reporter@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/jasmine-spec-reporter/-/jasmine-spec-reporter-4.2.1.tgz#1d632aec0341670ad324f92ba84b4b32b35e9e22"
integrity sha512-FZBoZu7VE5nR7Nilzy+Np8KuVIOxF4oXDPDknehCYBDE080EnlPu0afdZNmpGDBRCUBv3mj5qgqCRmk6W/K8vg==
dependencies:
colors "1.1.2"

jpeg-js@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.0.4.tgz#06aaf47efec7af0b1924a59cd695a6d2b5ed870e"
@@ -3418,10 +3466,10 @@ longest@^1.0.1:
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
integrity sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=

looks-same@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/looks-same/-/looks-same-6.0.0.tgz#aa8f24291b78b966eb6fc315a41b33adeb3fc068"
integrity sha512-143Xf0qKRubHjVlWiPI2VMOMbvS94ldHsYrccXvihe6nCI7Z/JFy5ZskQzpLtYy4TFX2vbSJM1uAn5gShvqlcw==
looks-same@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/looks-same/-/looks-same-5.1.0.tgz#5cb2a797ca9db3d7996e5cc6e68489c27a6aae70"
integrity sha512-a/BdaF+Q7mqpJZ5Xz1VM9Nb+LnDu8l1A+2ZKEoaqmb9B+nlap1dKeUG8YeVUkQh4pnqsAs6mcSDUp35wkvxozw==
dependencies:
color-diff "^1.1.0"
concat-stream "^1.6.2"
@@ -5926,6 +5974,11 @@ util@~0.10.1:
dependencies:
inherits "2.0.3"

utils-extend@^1.0.4, utils-extend@^1.0.6, utils-extend@^1.0.7:
version "1.0.8"
resolved "https://registry.yarnpkg.com/utils-extend/-/utils-extend-1.0.8.tgz#ccfd7b64540f8e90ee21eec57769d0651cab8a5f"
integrity sha1-zP17ZFQPjpDuIe7Fd2nQZRyril8=

utils-merge@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.