Created
May 2, 2018 11:35
-
-
Save vysinsky/a0aaf8a0208a8ded34a487bcc3b0a8c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Listr = require('listr'); | |
const execa = require('execa'); | |
const axios = require('axios'); | |
const helpers = require('../utils/helpers'); | |
const execute = require('../utils/execute').execute; | |
const ExecutionError = require('../utils/ExecutionError'); | |
module.exports = backstopInParallel => ({ | |
title: 'Testing', | |
enabled: ctx => ctx.stages.indexOf('test') > -1, | |
task: () => new Listr([ | |
{ | |
title: 'Running unit tests', | |
task: () => execute('npm', ['run', 'test']) | |
.catch((e) => { throw new ExecutionError('Failed', e); }) | |
}, | |
{ | |
title: 'Running BackstopJS tests', | |
task: () => new Listr([ | |
{ | |
title: 'Starting docker-compose', | |
task: async () => { | |
try { | |
await execa.stdout('docker-compose', ['up', '-d']); | |
} catch (e) { | |
if (e.message.indexOf('connect') > -1) { | |
throw new Error('Cannot start styleguide. Ensure you have Docker running.'); | |
} else { | |
throw new Error(e); | |
} | |
} | |
} | |
}, | |
{ | |
title: 'Waiting for styleguide to fully start', | |
task: () => new Promise(async (resolve) => { | |
let loaded = false; | |
while (!loaded) { | |
try { | |
// eslint-disable-next-line no-await-in-loop | |
const response = await axios.get('http://localhost:3031'); | |
loaded = response.data | |
.indexOf('Dixons Carphone Living Style Guide') > -1; | |
} catch (e) { | |
// Do nothing | |
} | |
if (!loaded) { | |
// eslint-disable-next-line no-await-in-loop | |
await helpers.sleep(5000); | |
} | |
} | |
resolve(); | |
}) | |
}, | |
{ | |
title: 'Testing', | |
task: () => new Listr([ | |
{ | |
title: 'Currys', | |
task: () => execute('npm', ['run', 'backstop', 'test', '--', '--theme', 'currys']) | |
.catch((e) => { throw new ExecutionError('Failed', e); }) | |
}, | |
{ | |
title: 'PCWorld', | |
task: () => execute('npm', ['run', 'backstop', 'test', '--', '--theme', 'pcworld']) | |
.catch((e) => { throw new ExecutionError('Failed', e); }) | |
} | |
]) | |
} | |
], { | |
concurrent: backstopInParallel | |
}) | |
} | |
], { | |
concurrent: true | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment