mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-15 21:00:02 +01:00
* add toCliString function fixes #140 Signed-off-by: tech4GT <varun.gupta1798@gmail.com> * update docs Signed-off-by: tech4GT <varun.gupta1798@gmail.com> * add test Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
This commit is contained in:
committed by
Jeffrey Warren
parent
5ab018fb84
commit
5b4e904636
@@ -13,12 +13,12 @@ function copy(g, a) {
|
||||
var b = {};
|
||||
var i = 0;
|
||||
for (var v in a)
|
||||
if (g) {
|
||||
if (v != "sequencer") b[v] = a[v];
|
||||
}
|
||||
else {
|
||||
if (v != "sequencer" && v != "global1" && v != "global2" && !global1.hasOwnProperty(v)) i++;
|
||||
}
|
||||
if (g) {
|
||||
if (v != "sequencer") b[v] = a[v];
|
||||
}
|
||||
else {
|
||||
if (v != "sequencer" && v != "global1" && v != "global2" && !global1.hasOwnProperty(v)) i++;
|
||||
}
|
||||
if (g) return b;
|
||||
else return i;
|
||||
}
|
||||
@@ -28,19 +28,19 @@ var global1 = copy(true, parent);
|
||||
var sequencer = ImageSequencer({ ui: false });
|
||||
var red = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
||||
|
||||
test('Image Sequencer has tests', function (t) {
|
||||
test('Image Sequencer has tests', function(t) {
|
||||
t.equal(true, true, "Initial Test");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('loadImages loads a DataURL image and creates a step.', function (t) {
|
||||
test('loadImages loads a DataURL image and creates a step.', function(t) {
|
||||
sequencer.loadImages('test', red);
|
||||
t.equal(sequencer.images.test.steps.length, 1, "Initial Step Created");
|
||||
t.equal(typeof (sequencer.images.test.steps[0].output.src), "string", "Initial output exists");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('modulesInfo() returns info for each module', function (t) {
|
||||
test('modulesInfo() returns info for each module', function(t) {
|
||||
var info = sequencer.modulesInfo();
|
||||
t.equal(Object.keys(info).length, Object.keys(sequencer.modules).length);
|
||||
t.equal(info.hasOwnProperty(Object.keys(sequencer.modules)[0]), true);
|
||||
@@ -50,38 +50,38 @@ test('modulesInfo() returns info for each module', function (t) {
|
||||
});
|
||||
|
||||
if (!sequencer.options.inBrowser)
|
||||
test('loadImage loads an image from URL and creates a step. (NodeJS)', function (t) {
|
||||
require('dns').resolve('www.github.com', function (err) {
|
||||
if (err) {
|
||||
console.log("Test aborted due to no internet");
|
||||
t.end();
|
||||
}
|
||||
else {
|
||||
sequencer.loadImage('URL', 'https://ccpandhare.github.io/image-sequencer/examples/images/red.jpg', function () {
|
||||
t.equal(sequencer.images.URL.steps.length, 1, "Initial Step Created");
|
||||
t.equal(typeof (sequencer.images.URL.steps[0].output.src), "string", "Initial output exists");
|
||||
t.end();
|
||||
test('loadImage loads an image from URL and creates a step. (NodeJS)', function(t) {
|
||||
require('dns').resolve('www.github.com', function(err) {
|
||||
if (err) {
|
||||
console.log("Test aborted due to no internet");
|
||||
t.end();
|
||||
}
|
||||
else {
|
||||
sequencer.loadImage('URL', 'https://ccpandhare.github.io/image-sequencer/examples/images/red.jpg', function() {
|
||||
t.equal(sequencer.images.URL.steps.length, 1, "Initial Step Created");
|
||||
t.equal(typeof (sequencer.images.URL.steps[0].output.src), "string", "Initial output exists");
|
||||
t.end();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (!sequencer.options.inBrowser)
|
||||
test('loadImages loads an image from PATH and creates a step. (NodeJS)', function (t) {
|
||||
sequencer.loadImages('examples/images/red.jpg');
|
||||
t.equal(sequencer.images.image1.steps.length, 1, "Initial Step Created");
|
||||
t.equal(typeof (sequencer.images.image1.steps[0].output.src), "string", "Initial output exists");
|
||||
t.end();
|
||||
});
|
||||
test('loadImages loads an image from PATH and creates a step. (NodeJS)', function(t) {
|
||||
sequencer.loadImages('examples/images/red.jpg');
|
||||
t.equal(sequencer.images.image1.steps.length, 1, "Initial Step Created");
|
||||
t.equal(typeof (sequencer.images.image1.steps[0].output.src), "string", "Initial output exists");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('loadImage works too.', function (t) {
|
||||
test('loadImage works too.', function(t) {
|
||||
sequencer.loadImage('test2', red);
|
||||
t.equal(sequencer.images.test2.steps.length, 1, "Initial Step Created");
|
||||
t.equal(typeof (sequencer.images.test2.steps[0].output.src), "string", "Initial output exists");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('addSteps("image","name") adds a step', function (t) {
|
||||
test('addSteps("image","name") adds a step', function(t) {
|
||||
sequencer.addSteps('test', 'channel');
|
||||
t.equal(sequencer.images.test.steps.length, 2, "Length of steps increased")
|
||||
t.equal(sequencer.images.test.steps[1].options.name, "channel", "Correct Step Added");
|
||||
@@ -89,14 +89,14 @@ test('addSteps("image","name") adds a step', function (t) {
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('addSteps("name") adds a step', function (t) {
|
||||
test('addSteps("name") adds a step', function(t) {
|
||||
sequencer.addSteps('channel');
|
||||
t.equal(sequencer.images.test.steps.length, 3, "Length of steps increased");
|
||||
t.equal(sequencer.images.test.steps[2].options.name, "channel", "Correct Step Added");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('addSteps(["name"]) adds a step', function (t) {
|
||||
test('addSteps(["name"]) adds a step', function(t) {
|
||||
sequencer.addSteps(['channel', 'invert']);
|
||||
t.equal(sequencer.images.test.steps.length, 5, "Length of steps increased by two")
|
||||
t.equal(sequencer.images.test.steps[3].options.name, "channel", "Correct Step Added");
|
||||
@@ -104,60 +104,60 @@ test('addSteps(["name"]) adds a step', function (t) {
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('addSteps("name",o) adds a step', function (t) {
|
||||
test('addSteps("name",o) adds a step', function(t) {
|
||||
sequencer.addSteps('channel', {});
|
||||
t.equal(sequencer.images.test.steps.length, 6, "Length of steps increased");
|
||||
t.equal(sequencer.images.test.steps[5].options.name, "channel", "Correct Step Added");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('addSteps("image","name",o) adds a step', function (t) {
|
||||
test('addSteps("image","name",o) adds a step', function(t) {
|
||||
sequencer.addSteps('test', 'channel', {});
|
||||
t.equal(sequencer.images.test.steps.length, 7, "Length of steps increased");
|
||||
t.equal(sequencer.images.test.steps[6].options.name, "channel", "Correct Step Added");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('removeSteps("image",position) removes a step', function (t) {
|
||||
test('removeSteps("image",position) removes a step', function(t) {
|
||||
sequencer.removeSteps('test', 1);
|
||||
t.equal(sequencer.images.test.steps.length, 6, "Length of steps reduced");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('removeSteps({image: [positions]}) removes steps', function (t) {
|
||||
test('removeSteps({image: [positions]}) removes steps', function(t) {
|
||||
sequencer.removeSteps('test', [1, 2]);
|
||||
t.equal(sequencer.images.test.steps.length, 4, "Length of steps reduced");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('removeSteps(position) removes steps', function (t) {
|
||||
test('removeSteps(position) removes steps', function(t) {
|
||||
sequencer.removeSteps([1, 2]);
|
||||
t.equal(sequencer.images.test.steps.length, 2, "Length of steps reduced");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('insertSteps("image",position,"module",options) inserts a step', function (t) {
|
||||
test('insertSteps("image",position,"module",options) inserts a step', function(t) {
|
||||
sequencer.insertSteps('test', 1, 'channel', {});
|
||||
t.equal(sequencer.images.test.steps.length, 3, "Length of Steps increased");
|
||||
t.equal(sequencer.images.test.steps[1].options.name, "channel", "Correct Step Inserted");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('insertSteps("image",position,"module") inserts a step', function (t) {
|
||||
test('insertSteps("image",position,"module") inserts a step', function(t) {
|
||||
sequencer.insertSteps('test', 1, 'channel');
|
||||
t.equal(sequencer.images.test.steps.length, 4, "Length of Steps increased");
|
||||
t.equal(sequencer.images.test.steps[1].options.name, "channel", "Correct Step Inserted");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('insertSteps(position,"module") inserts a step', function (t) {
|
||||
test('insertSteps(position,"module") inserts a step', function(t) {
|
||||
sequencer.insertSteps(1, 'channel');
|
||||
t.equal(sequencer.images.test.steps.length, 5, "Length of Steps increased");
|
||||
t.equal(sequencer.images.test.steps[1].options.name, "channel", "Correct Step Inserted");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('insertSteps({image: {index: index, name: "module", o: options} }) inserts a step', function (t) {
|
||||
test('insertSteps({image: {index: index, name: "module", o: options} }) inserts a step', function(t) {
|
||||
sequencer.insertSteps({ test: { index: 1, name: 'channel', o: {} } });
|
||||
t.equal(sequencer.images.test.steps.length, 6, "Length of Steps increased");
|
||||
t.equal(sequencer.images.test.steps[1].options.name, "channel", "Correct Step Inserted");
|
||||
@@ -165,8 +165,8 @@ test('insertSteps({image: {index: index, name: "module", o: options} }) inserts
|
||||
});
|
||||
|
||||
|
||||
test('run() runs the sequencer and returns output to callback', function (t) {
|
||||
sequencer.run({mode:'test'}, function (out) {
|
||||
test('run() runs the sequencer and returns output to callback', function(t) {
|
||||
sequencer.run({ mode: 'test' }, function(out) {
|
||||
t.equal(typeof (sequencer.images.test.steps[sequencer.images.test.steps.length - 1].output), "object", "Output is Generated");
|
||||
t.equal(out, sequencer.images.test.steps[sequencer.images.test.steps.length - 1].output.src, "Output callback works");
|
||||
t.end();
|
||||
@@ -174,23 +174,28 @@ test('run() runs the sequencer and returns output to callback', function (t) {
|
||||
});
|
||||
|
||||
|
||||
test('getStep(offset) returns the step at offset distance relative to current step',function(t){
|
||||
sequencer.addSteps('test','invert',{});
|
||||
sequencer.addSteps('test','blend',{});
|
||||
sequencer.run({mode:'test'},function(out){
|
||||
t.equal(!!out,true,"Blend generates output");
|
||||
test('getStep(offset) returns the step at offset distance relative to current step', function(t) {
|
||||
sequencer.addSteps('test', 'invert', {});
|
||||
sequencer.addSteps('test', 'blend', {});
|
||||
sequencer.run({ mode: 'test' }, function(out) {
|
||||
t.equal(!!out, true, "Blend generates output");
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('replaceImage returns false in NodeJS', function (t) {
|
||||
test('toCliString() returns the CLI command for the sequence', function(t) {
|
||||
t.deepEqual(sequencer.toCliString(), `sequencer -i [PATH] -s "channel channel channel channel channel invert blend" -d '{"channel":"green"}'`, "works correctly");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('replaceImage returns false in NodeJS', function(t) {
|
||||
var returnvalue = (sequencer.options.inBrowser) ? false : sequencer.replaceImage("#selector", "test");
|
||||
t.equal(returnvalue, false, "It does.");
|
||||
t.end();
|
||||
});
|
||||
|
||||
var global2 = copy(false, parent);
|
||||
test('No Global Variables Created', function (t) {
|
||||
test('No Global Variables Created', function(t) {
|
||||
t.equal(0, global2, "None Created.");
|
||||
t.end();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user