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 e0cbe29e..fb4ae03d 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 6a68ef88..cc825b9e 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 a8d6d41e..9d5cc3c4 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 9c2e1b24..e8e91f72 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 3e9d96d0..ef57921c 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 c324203d..ecc0b33d 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 060c1efd..5819996b 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 c81b805d..fd1ed047 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 47363ab7..4fe18f11 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 953d4fb4..a811332c 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 98bc1851..e427dcfe 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 157ec1e0..aa2388f8 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 46f109fd..b2a5ea9c 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 e4344e74..18a810ad 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 78e47e76..3d72c52e 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 25448c35..e9c7647f 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 b82f0463..1cb8fa90 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 7392eb8c..514a5614 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); });