Skip to content

Commit

Permalink
[test] Move backstop to test folder and run backstop-test-studio on test
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofferjs committed Jan 16, 2019
1 parent f4944ee commit 38595b4
Show file tree
Hide file tree
Showing 25 changed files with 56 additions and 23 deletions.
53 changes: 42 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const chalk = require('chalk')
const globby = require('globby')
const mergeStream = require('merge-stream')
const backstop = require('backstopjs')
const waitPort = require('wait-port')
const kill = require('kill-port')

const isWindows = /^win/.test(process.platform)

Expand Down Expand Up @@ -242,33 +244,62 @@ gulp.task('storybook', ['watch-js', 'watch-ts', 'watch-assets'], () => {
})

gulp.task('backstop', cb => {
const DRONE = !!process.env.DRONE
backstop('test', {
docker: !DRONE,
config: './backstop_data/backstop.js'
})
.then(() => {
gutil.log(gutil.colors.green('Backstop test success'))
gulp.start('backstop-test-studio')

const params = {
host: 'localhost',
port: 5000,
timeout: 100 * 60 * 10
}

waitPort(params)
.then(open => {
if (open) {
backstop('test', {
docker: true,
config: './test/backstop/backstop.js'
})
.then(() => {
kill(params.port).then(() => {
gutil.log(gutil.colors.green('Backstop test success'))
process.exit(0)
})
})
.catch(() => {
kill(params.port)
throw new gutil.PluginError({
plugin: 'backstop',
message: 'Tests failed'
})
})
} else {
kill(params.port)
throw new gutil.PluginError({
plugin: 'backstop',
message: 'The backstop-studio did not start'
})
}
})
.catch(() => {
.catch(err => {
kill(params.port)
throw new gutil.PluginError({
plugin: 'backstop',
message: 'Tests failed'
message: `An unknown error occured while waiting for the port: ${err}`
})
})
})

gulp.task('backstop:approve', cb => {
backstop('approve', {
docker: true,
config: './backstop_data/backstop.js'
config: './test/backstop/backstop.js'
})
})

gulp.task('backstop:reference', cb => {
backstop('reference', {
docker: true,
config: './backstop_data/backstop.js'
config: './test/backstop/backstop.js'
})
.then(() => {
gutil.log(gutil.colors.green('References created'))
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"gulp-watch": "^5.0.1",
"hard-rejection": "^1.0.0",
"husky": "^0.14.3",
"kill-port": "^1.3.2",
"lerna": "^3.4.0",
"merge-stream": "^1.0.1",
"minimist": "^1.2.0",
Expand All @@ -98,6 +99,7 @@
"stylelint-config-standard": "^18.0.0",
"through2": "^2.0.3",
"typescript": "^3.2.2",
"wait-port": "^0.2.2",
"yarn": "^1.3.2"
}
}
File renamed without changes.
24 changes: 12 additions & 12 deletions backstop_data/backstop.js → test/backstop/backstop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/no-commonjs, camelcase */
const DRONE = process.env.DRONE
/* eslint-disable import/no-commonjs, camelcase, no-process-env */
const URL = 'http://host.docker.internal:5000'

const URL = DRONE ? 'https://backstop.sanity.studio' : 'http://host.docker.internal:5000'
const loggedInUserCookiePath = './test/backstop/engineScripts/cookies.json'

module.exports = {
id: 'content_studio',
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = {
},
{
label: 'Front',
cookiePath: './backstop_data/engineScripts/cookies.json',
cookiePath: loggedInUserCookiePath,
url: URL,
delay: 1000,
readySelector: '[class^="PaneItem_item"]',
Expand All @@ -53,7 +53,7 @@ module.exports = {
},
{
label: 'Book pane',
cookiePath: './backstop_data/engineScripts/cookies.json',
cookiePath: loggedInUserCookiePath,
url: `${URL}/desk/book`,
delay: 1000,
readySelector: '[class^="PaneItem_item"]',
Expand All @@ -64,7 +64,7 @@ module.exports = {
},
{
label: 'Book document',
cookiePath: './backstop_data/engineScripts/cookies.json',
cookiePath: loggedInUserCookiePath,
url: `${URL}/desk/book;c6b1208f-cd89-4a55-88f1-0b979e005f0a`,
delay: 1000,
readySelector: '[class^="Editor_root"]',
Expand All @@ -75,13 +75,13 @@ module.exports = {
}
],
paths: {
bitmaps_reference: 'backstop_data/bitmapsReference',
bitmaps_test: 'backstop_data/bitmapsTest',
engine_scripts: 'backstop_data/engineScripts',
html_report: 'backstop_data/htmlReport',
ci_report: 'backstop_data/ciReport'
bitmaps_reference: 'test/backstop/bitmapsReference',
bitmaps_test: 'test/backstop/bitmapsTest',
engine_scripts: 'test/backstop/engineScripts',
html_report: 'test/backstop/htmlReport',
ci_report: 'test/backstop/ciReport'
},
report: ['browser', 'CI'],
report: process.env.CI ? ['browser', 'CI'] : ['browser'],
engine: 'puppeteer',
engineOptions: {
args: ['--no-sandbox']
Expand Down
File renamed without changes.

0 comments on commit 38595b4

Please sign in to comment.