diff options
author | mattab <matthieu.aubry@gmail.com> | 2016-04-11 10:00:51 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2016-04-11 10:00:51 +0300 |
commit | ca0f0cbce78602f53be9f5866ef3ad528385346b (patch) | |
tree | 8f513ce0ea31139604db78a6338a0909e6244d80 /tests | |
parent | 3c4fa9be618a216bec580459872e842c6b645a26 (diff) |
handle PNG artifacts
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/screenshot-testing/support/chai-extras.js | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/tests/lib/screenshot-testing/support/chai-extras.js b/tests/lib/screenshot-testing/support/chai-extras.js index fd77c5c4f0..3cc80ef7c2 100644 --- a/tests/lib/screenshot-testing/support/chai-extras.js +++ b/tests/lib/screenshot-testing/support/chai-extras.js @@ -45,17 +45,39 @@ function getPageLogsString(pageLogs, indent) { // add capture assertion var pageRenderer = new PageRenderer(config.piwikUrl + path.join("tests", "PHPUnit", "proxy")); + +function getExpectedFilePath(fileName) { + var expectedScreenshotDir = path.join(app.runner.suite.baseDirectory, config.expectedScreenshotsDir); + + fileName = assumeFileIsImageIfNotSpecified(fileName); + + return path.join(expectedScreenshotDir, fileName); +} + function getProcessedFilePath(fileName) { - var dirsBase = app.runner.suite.baseDirectory, - processedScreenshotDir = path.join(options['store-in-ui-tests-repo'] ? uiTestsDir : dirsBase, config.processedScreenshotsDir); + var pathToUITests = options['store-in-ui-tests-repo'] ? uiTestsDir : app.runner.suite.baseDirectory; + var processedScreenshotDir = path.join(pathToUITests, config.processedScreenshotsDir); if (!fs.isDirectory(processedScreenshotDir)) { fs.makeTree(processedScreenshotDir); } + fileName = assumeFileIsImageIfNotSpecified(fileName); return path.join(processedScreenshotDir, fileName); } +function assumeFileIsImageIfNotSpecified(filename) { + if(!endsWith(filename, '.png') && !endsWith(filename, '.txt') ) { + return filename + '.png'; + } + return filename; +} + +function endsWith(string, needle) +{ + return string.substr(-1 * needle.length, needle.length) === needle; +} + function failCapture(fileTypeString, pageRenderer, testInfo, expectedFilePath, processedFilePath, message, done) { @@ -69,7 +91,7 @@ function failCapture(fileTypeString, pageRenderer, testInfo, expectedFilePath, p var indent = " "; var failureInfo = message + "\n"; failureInfo += indent + "Url to reproduce: " + pageRenderer.getCurrentUrl() + "\n"; - failureInfo += indent + "Generated " + fileTypeString + " : " + processedPath + "\n"; + failureInfo += indent + "Generated " + fileTypeString + ": " + processedPath + "\n"; failureInfo += indent + "Expected " + fileTypeString + ": " + expectedPath + "\n"; failureInfo += getPageLogsString(pageRenderer.pageLogs, indent); @@ -82,8 +104,8 @@ function failCapture(fileTypeString, pageRenderer, testInfo, expectedFilePath, p done(error); } -function getScreenshotDiffDir(dirsBase) { - return path.join(options['store-in-ui-tests-repo'] ? uiTestsDir : dirsBase, config.screenshotDiffDir); +function getScreenshotDiffDir() { + return path.join(options['store-in-ui-tests-repo'] ? uiTestsDir : app.runner.suite.baseDirectory, config.screenshotDiffDir); } function capture(screenName, compareAgainst, selector, pageSetupFn, comparisonThreshold, done) { @@ -93,11 +115,9 @@ function capture(screenName, compareAgainst, selector, pageSetupFn, comparisonTh } var screenshotFileName = screenName, - dirsBase = app.runner.suite.baseDirectory, - expectedScreenshotDir = path.join(dirsBase, config.expectedScreenshotsDir), - expectedScreenshotPath = path.join(expectedScreenshotDir, compareAgainst), + expectedScreenshotPath = getExpectedFilePath(compareAgainst), processedScreenshotPath = getProcessedFilePath(screenName), - screenshotDiffDir = getScreenshotDiffDir(dirsBase); + screenshotDiffDir = getScreenshotDiffDir(); if (!fs.isDirectory(screenshotDiffDir)) { fs.makeTree(screenshotDiffDir); @@ -119,7 +139,7 @@ function capture(screenName, compareAgainst, selector, pageSetupFn, comparisonTh name: screenName, processed: fs.isFile(processedScreenshotPath) ? processedScreenshotPath : null, expected: fs.isFile(expectedScreenshotPath) ? expectedScreenshotPath : null, - baseDirectory: dirsBase + baseDirectory: app.runner.suite.baseDirectory }; var fail = function (message) { @@ -220,11 +240,10 @@ function compareContents(compareAgainst, pageSetupFn, done) { throw new Error("No 'done' callback specified in 'pageContents' assertion."); } - var dirsBase = app.runner.suite.baseDirectory, - expectedScreenshotDir = path.join(dirsBase, config.expectedScreenshotsDir), - expectedFilePath = path.join(expectedScreenshotDir, compareAgainst), + var screenshotDiffDir = getScreenshotDiffDir(), processedFilePath = getProcessedFilePath(compareAgainst), - screenshotDiffDir = getScreenshotDiffDir(dirsBase); + expectedFilePath = getExpectedFilePath(compareAgainst); + if (!fs.isDirectory(screenshotDiffDir)) { fs.makeTree(screenshotDiffDir); @@ -264,7 +283,7 @@ function compareContents(compareAgainst, pageSetupFn, done) { name: filename, processed: fs.isFile(processedFilePath) ? processedFilePath : null, expected: fs.isFile(expectedFilePath) ? expectedFilePath : null, - baseDirectory: dirsBase + baseDirectory: app.runner.suite.baseDirectory }; if (!fs.isFile(testInfo.expected)) { |