From 5f88fe08526fab1f2e71d4deccadb3cfa7faaaff Mon Sep 17 00:00:00 2001 From: diosmosis <benakamoorthi@fastmail.fm> Date: Sun, 30 Mar 2014 17:23:31 +0100 Subject: [PATCH] Fix diff generation in screenshot tests for plugins (paths were not different for plugin tests). --- tests/lib/screenshot-testing/support/app.js | 23 ++++++++++--------- .../screenshot-testing/support/chai-extras.js | 3 ++- .../screenshot-testing/support/diff-viewer.js | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/lib/screenshot-testing/support/app.js b/tests/lib/screenshot-testing/support/app.js index 71f1c73ff2..9aa89c7efd 100644 --- a/tests/lib/screenshot-testing/support/app.js +++ b/tests/lib/screenshot-testing/support/app.js @@ -35,7 +35,7 @@ var walk = function (dir, pattern, result) { var Application = function () { this.runner = null; - this.diffViewerGenerator = new DiffViewerGenerator(path.join(uiTestsDir, config.screenshotDiffDir)); + this.diffViewerGenerator = new DiffViewerGenerator(); }; Application.prototype.printHelpAndExit = function () { @@ -69,6 +69,7 @@ Application.prototype.init = function () { describe = function () { var suite = oldDescribe.apply(null, arguments); suite.baseDirectory = app.currentModulePath.match(/\/plugins\//) ? path.dirname(app.currentModulePath) : uiTestsDir; + suite.diffDir = path.join(suite.baseDirectory, config.screenshotDiffDir); return suite; }; }; @@ -122,6 +123,16 @@ Application.prototype.loadTestModules = function () { } } + // remove existing diffs + fs.list(suite.diffDir).forEach(function (item) { + var file = path.join(suite.diffDir, item); + if (fs.exists(file) + && item.slice(-4) == '.png' + ) { + fs.remove(file); + } + }); + testEnvironment.setupFixture(fixture, done); options = oldOptions; @@ -159,16 +170,6 @@ Application.prototype.runTests = function () { } }); - // remove existing diffs - fs.list(config.screenshotDiffDir).forEach(function (item) { - var file = path.join(uiTestsDir, config.screenshotDiffDir, item); - if (fs.exists(file) - && item.slice(-4) == '.png' - ) { - fs.remove(file); - } - }); - this.doRunTests(); }; diff --git a/tests/lib/screenshot-testing/support/chai-extras.js b/tests/lib/screenshot-testing/support/chai-extras.js index 7505068e6f..1678a634d4 100644 --- a/tests/lib/screenshot-testing/support/chai-extras.js +++ b/tests/lib/screenshot-testing/support/chai-extras.js @@ -91,7 +91,8 @@ chai.Assertion.addChainableMethod('capture', function () { var testInfo = { name: screenName, processed: fs.isFile(processedScreenshotPath) ? processedScreenshotPath : null, - expected: fs.isFile(expectedScreenshotPath) ? expectedScreenshotPath : null + expected: fs.isFile(expectedScreenshotPath) ? expectedScreenshotPath : null, + baseDirectory: dirsBase }; var fail = function (message) { diff --git a/tests/lib/screenshot-testing/support/diff-viewer.js b/tests/lib/screenshot-testing/support/diff-viewer.js index 9d812a3d7f..a49f24eb7f 100644 --- a/tests/lib/screenshot-testing/support/diff-viewer.js +++ b/tests/lib/screenshot-testing/support/diff-viewer.js @@ -33,7 +33,7 @@ DiffViewerGenerator.prototype.checkImageMagickCompare = function (callback) { }; DiffViewerGenerator.prototype.getDiffPath = function (testInfo) { - return path.resolve(path.join(this.diffDir, testInfo.name + '.png')); + return path.resolve(path.join(testInfo.baseDirectory, config.screenshotDiffDir, testInfo.name + '.png')); }; // TODO: diff output path shouldn't be stored in piwik-ui-tests repo -- GitLab