From 99c060f4a7606401b262a831e98aa046b3486eb7 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Tue, 18 Sep 2018 22:03:22 +0200 Subject: [PATCH] Cleanup local storage before integration tests --- test/casperjs/integration/include.js | 25 +++++++++++++---- .../palettes/test-tiny-palettes.js | 10 +------ .../settings/test-export-gif-scale.js | 10 +------ .../settings/test-export-gif-simple.js | 10 +------ .../integration/settings/test-export-gif.js | 10 +------ .../settings/test-export-png-scale.js | 27 +++++-------------- .../integration/settings/test-export-png.js | 10 +------ .../settings/test-import-image-empty.js | 10 +------ .../settings/test-import-image-twice.js | 10 +------ .../integration/settings/test-import-image.js | 10 +------ .../settings/test-preferences-main.js | 10 +------ .../settings/test-resize-complete.js | 10 +------ .../settings/test-resize-content-complete.js | 10 +------ .../settings/test-resize-default-size.js | 10 +------ .../test-resize-input-synchronization.js | 10 +------ .../settings/test-resize-origin.js | 10 +------ .../integration/settings/test-resize.js | 10 +------ .../test-settings-open-panels-on-click.js | 10 +------ 18 files changed, 43 insertions(+), 169 deletions(-) diff --git a/test/casperjs/integration/include.js b/test/casperjs/integration/include.js index e0cbe29..fb4ae03 100644 --- a/test/casperjs/integration/include.js +++ b/test/casperjs/integration/include.js @@ -131,9 +131,24 @@ function setPiskelFromImageSrc(src) { }'); } -function beforeTest() { - // Cleanup local storage. - casper.evaluate(function() { - localStorage.clear(); - }, {}); +/** + * Load the piskel website in debug mode and call the provided callback when ready. + */ +function startTest(test, callback) { + return casper + // Pass "integration-test" to avoid the "unsupported browser" dialog + .start(casper.cli.get('baseUrl')+"/?debug&integration-test") + .then(function () { + casper.echo("URL loaded"); + + casper.evaluate(function() { + localStorage.clear(); + }, {}); + casper.echo("Local storage cleaned"); + + casper.waitForSelector('#drawing-canvas-container canvas', callback, test.timeout, 20000); + }) + .run(function () { + test.done(); + }); } diff --git a/test/casperjs/integration/palettes/test-tiny-palettes.js b/test/casperjs/integration/palettes/test-tiny-palettes.js index 6a68ef8..cc825b9 100644 --- a/test/casperjs/integration/palettes/test-tiny-palettes.js +++ b/test/casperjs/integration/palettes/test-tiny-palettes.js @@ -55,13 +55,5 @@ casper.test.begin('Test palette switches to tiny mode if it contains more than 1 'Check that the palette colors container is not in tiny mode'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-export-gif-scale.js b/test/casperjs/integration/settings/test-export-gif-scale.js index a8d6d41..9d5cc3c 100644 --- a/test/casperjs/integration/settings/test-export-gif-scale.js +++ b/test/casperjs/integration/settings/test-export-gif-scale.js @@ -104,13 +104,5 @@ casper.test.begin('Simple GIF (<256 colors) export test, with 2x scaling', 18, f test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-export-gif-simple.js b/test/casperjs/integration/settings/test-export-gif-simple.js index 9c2e1b2..e8e91f7 100644 --- a/test/casperjs/integration/settings/test-export-gif-simple.js +++ b/test/casperjs/integration/settings/test-export-gif-simple.js @@ -93,13 +93,5 @@ casper.test.begin('Simple GIF (<256 colors) export test', 14, function(test) { test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-export-gif.js b/test/casperjs/integration/settings/test-export-gif.js index 3e9d96d..ef57921 100644 --- a/test/casperjs/integration/settings/test-export-gif.js +++ b/test/casperjs/integration/settings/test-export-gif.js @@ -70,15 +70,7 @@ casper.test.begin('Complex GIF export test', 11, function(test) { test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); // Source for a base64 encoded PNG, 20x20, with 400 different colors. diff --git a/test/casperjs/integration/settings/test-export-png-scale.js b/test/casperjs/integration/settings/test-export-png-scale.js index c324203..ecc0b33 100644 --- a/test/casperjs/integration/settings/test-export-png-scale.js +++ b/test/casperjs/integration/settings/test-export-png-scale.js @@ -111,24 +111,11 @@ casper.test.begin('PNG export test, with 2x scaling', 32, function(test) { test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("Test with spritesheet PNG export"); - beforeTest(); - testButtonClass = '.png-download-button'; - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .then(function () { - casper.start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("Test with single frame PNG export"); - beforeTest(); - testButtonClass = '.selected-frame-download-button'; - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - }) - .run(function () { - test.done(); - }); + casper.echo("Test with spritesheet PNG export"); + testButtonClass = '.png-download-button'; + startTest(test, onTestStart).then(function () { + casper.echo("Test with single frame PNG export"); + testButtonClass = '.selected-frame-download-button'; + startTest(test, onTestStart); + }); }); diff --git a/test/casperjs/integration/settings/test-export-png.js b/test/casperjs/integration/settings/test-export-png.js index 060c1ef..5819996 100644 --- a/test/casperjs/integration/settings/test-export-png.js +++ b/test/casperjs/integration/settings/test-export-png.js @@ -97,13 +97,5 @@ casper.test.begin('PNG export test', 13, function(test) { test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-import-image-empty.js b/test/casperjs/integration/settings/test-import-image-empty.js index c81b805..fd1ed04 100644 --- a/test/casperjs/integration/settings/test-import-image-empty.js +++ b/test/casperjs/integration/settings/test-import-image-empty.js @@ -93,13 +93,5 @@ casper.test.begin('Image import test with an empty current sprite', 16, function test.assertEquals(evalLine('pskl.app.piskelController.getFrameCount()'), 1, 'Piskel has 1 frame'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug&integration-test") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-import-image-twice.js b/test/casperjs/integration/settings/test-import-image-twice.js index 47363ab..4fe18f1 100644 --- a/test/casperjs/integration/settings/test-import-image-twice.js +++ b/test/casperjs/integration/settings/test-import-image-twice.js @@ -183,13 +183,5 @@ casper.test.begin('Double Image import test', 26, function(test) { test.assertEquals(evalLine('pskl.app.piskelController.getFrameCount()'), 1, 'Piskel has 1 frame'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug&integration-test") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-import-image.js b/test/casperjs/integration/settings/test-import-image.js index 953d4fb..a811332 100644 --- a/test/casperjs/integration/settings/test-import-image.js +++ b/test/casperjs/integration/settings/test-import-image.js @@ -139,13 +139,5 @@ casper.test.begin('Simple Image import test', 27, function(test) { test.assertEquals(evalLine('pskl.app.piskelController.getFrameCount()'), 1, 'Piskel has 1 frame'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug&integration-test") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-preferences-main.js b/test/casperjs/integration/settings/test-preferences-main.js index 98bc185..e427dcf 100644 --- a/test/casperjs/integration/settings/test-preferences-main.js +++ b/test/casperjs/integration/settings/test-preferences-main.js @@ -65,13 +65,5 @@ casper.test.begin('Preferences settings panel test', 11, function(test) { test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - casper.echo("URL loaded"); - casper.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-resize-complete.js b/test/casperjs/integration/settings/test-resize-complete.js index 157ec1e..aa2388f 100644 --- a/test/casperjs/integration/settings/test-resize-complete.js +++ b/test/casperjs/integration/settings/test-resize-complete.js @@ -65,13 +65,5 @@ casper.test.begin('Test resize feature works, and check the output', 19, functio ]', 0, 0), 'Resized piskel content is as expected'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - this.echo("URL loaded"); - this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-resize-content-complete.js b/test/casperjs/integration/settings/test-resize-content-complete.js index 46f109f..b2a5ea9 100644 --- a/test/casperjs/integration/settings/test-resize-content-complete.js +++ b/test/casperjs/integration/settings/test-resize-content-complete.js @@ -66,13 +66,5 @@ casper.test.begin('Test resize content works, and check the output', 18, functio ]', 0, 0), 'Resized piskel content is as expected'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - this.echo("URL loaded"); - this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-resize-default-size.js b/test/casperjs/integration/settings/test-resize-default-size.js index e4344e7..18a810a 100644 --- a/test/casperjs/integration/settings/test-resize-default-size.js +++ b/test/casperjs/integration/settings/test-resize-default-size.js @@ -49,13 +49,5 @@ casper.test.begin('Test updating default size works', 14 , function(test) { 322, 'Piskel height is now 322 pixels'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - this.echo("URL loaded"); - this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-resize-input-synchronization.js b/test/casperjs/integration/settings/test-resize-input-synchronization.js index 78e47e7..3d72c52 100644 --- a/test/casperjs/integration/settings/test-resize-input-synchronization.js +++ b/test/casperjs/integration/settings/test-resize-input-synchronization.js @@ -85,13 +85,5 @@ casper.test.begin('Test resize panel width/height inputs are synchronized', 28 , test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - this.echo("URL loaded"); - this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-resize-origin.js b/test/casperjs/integration/settings/test-resize-origin.js index 25448c3..e9c7647 100644 --- a/test/casperjs/integration/settings/test-resize-origin.js +++ b/test/casperjs/integration/settings/test-resize-origin.js @@ -74,13 +74,5 @@ casper.test.begin('Test resize feature works, and check the output', 20, functio ]', 0, 0), 'Resized piskel content is as expected'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - this.echo("URL loaded"); - this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-resize.js b/test/casperjs/integration/settings/test-resize.js index b82f046..1cb8fa9 100644 --- a/test/casperjs/integration/settings/test-resize.js +++ b/test/casperjs/integration/settings/test-resize.js @@ -51,13 +51,5 @@ casper.test.begin('Test resize feature works', 16 , function(test) { test.assertEquals(evalLine('pskl.app.piskelController.getPiskel().getHeight()'), 320, 'Piskel height is now 320 pixels'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - this.echo("URL loaded"); - this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); }); diff --git a/test/casperjs/integration/settings/test-settings-open-panels-on-click.js b/test/casperjs/integration/settings/test-settings-open-panels-on-click.js index 7392eb8..514a561 100644 --- a/test/casperjs/integration/settings/test-settings-open-panels-on-click.js +++ b/test/casperjs/integration/settings/test-settings-open-panels-on-click.js @@ -71,13 +71,5 @@ casper.test.begin('Settings Test', 18, function(test) { test.assert(!isDrawerExpanded(), 'settings drawer is closed'); } - casper - .start(casper.cli.get('baseUrl')+"/?debug") - .then(function () { - this.echo("URL loaded"); - this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 20000); - }) - .run(function () { - test.done(); - }); + startTest(test, onTestStart); });