diff --git a/tests/lib/screenshot-testing/support/app.js b/tests/lib/screenshot-testing/support/app.js index 71f1c73ff2cddd49598e5812c3b1c89b0ccad881..9aa89c7efd09afaaa186e09a5301be174c7721d7 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 7505068e6f484c489384e3f946d919313357d79f..1678a634d419046d712cc1ed9e38b1801019eb6d 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 9d812a3d7ffd8bc2605a6e9f20f0c3996cb317cb..a49f24eb7fd90a233461dc8122d86c69536dcc5e 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