Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
use globals for generate_screenshot_path
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoryduckworth committed Apr 8, 2019
1 parent eb9317f commit 2a49240
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
3 changes: 0 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": [
"crunch"
],
"globals": {
"process": true
}
Expand Down
9 changes: 3 additions & 6 deletions lib/generate-screenshot-file-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const kebabCase = require('lodash/kebabCase'),
path = require('path'),
get = require('lodash/get')
get = require('lodash/get'),
getVrtSettings = require('./get-vrt-settings')


function appendExtensionToFilename(fileName) {
Expand Down Expand Up @@ -42,11 +43,7 @@ function defaultScreenshotFilePath(nightwatchClient, basePath, fileName) {
* @param {String} [fileName] A custom filename for the screenshot
*/
module.exports = function generateScreenshotFilePath(nightwatchClient, basePath, fileName) {
const globalSettings = get(
nightwatchClient,
'globals.test_settings.visual_regression_settings',
null
)
const globalSettings = getVrtSettings(nightwatchClient)

if (globalSettings && globalSettings.generate_screenshot_path) {
return globalSettings.generate_screenshot_path(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/nightwatch-vrt",
"version": "1.1.0",
"version": "1.1.1",
"description": "Nightwatch Visual Regression Testing tools",
"license": "MIT",
"homepage": "https://github.com/bbc/nightwatch-vrt",
Expand Down
42 changes: 31 additions & 11 deletions tests/lib/generate-screenshot-file-path-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict'

const generateScreenshotFilePath = require('../../lib/generate-screenshot-file-path')
const path = require('path')
const set = require('lodash/set')

describe('generateScreenshotFilePath', () => {
let customNameFn

function getNightwatchClient() {
return {
Expand All @@ -13,11 +11,8 @@ describe('generateScreenshotFilePath', () => {
name: 'barPlots'
},
globals: {
test_settings: {
visual_regression_settings: {
generate_screenshot_path: customNameFn
}
}
visual_regression_settings: {},
test_settings: { visual_regression_settings: {} }
}
}
}
Expand All @@ -33,10 +28,35 @@ describe('generateScreenshotFilePath', () => {
})

it('should pass the correct filename to the custom naming function', () => {
customNameFn = (client, basePath, fileName) =>
path.join(process.cwd(), basePath, client.currentTest.module, `custom-${fileName}`)
const nightwatchClient = getNightwatchClient()
const testFn = jest.fn((client, basePath, fileName) =>
path.join(process.cwd(), basePath, client.currentTest.module, `test-setting-custom-${fileName}`))

expect(generateScreenshotFilePath(getNightwatchClient(), 'baseline', 'foo-test'))
set(nightwatchClient, 'globals.test_settings.visual_regression_settings.generate_screenshot_path', testFn)

const result = generateScreenshotFilePath(nightwatchClient, 'baseline', 'foo-test')

expect(testFn).toHaveBeenCalled()
expect(result)
.toEqual(`${process.cwd()}/baseline/visualizations/test-setting-custom-foo-test.png`)
})

it('should use the base global setting for generate_screenshot_path if a test_setting exists', () => {
const nightwatchClient = getNightwatchClient()
const testFn = jest.fn((client, basePath, fileName) =>
path.join(process.cwd(), basePath, client.currentTest.module, `test-setting-custom-${fileName}`))

set(nightwatchClient, 'globals.test_settings.visual_regression_settings.generate_screenshot_path', testFn)

const customFn = jest.fn((client, basePath, fileName) =>
path.join(process.cwd(), basePath, client.currentTest.module, `custom-${fileName}`))

set(nightwatchClient, 'globals.visual_regression_settings.generate_screenshot_path', customFn)
set(nightwatchClient, 'globals.test_settings.visual_regression_settings.generate_screenshot_path', testFn)

const result = generateScreenshotFilePath(nightwatchClient, 'baseline', 'foo-test')

expect(result, 'baseline', 'foo-test')
.toEqual(`${process.cwd()}/baseline/visualizations/custom-foo-test.png`)
})
})

0 comments on commit 2a49240

Please sign in to comment.