Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test command when using docker #831

Merged
merged 2 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Contributing to this project

## Test

```sh
npm run genConfig
npm run reference
npm run test
```
30 changes: 6 additions & 24 deletions core/command/reference.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
var createBitmaps = require('../util/createBitmaps');
var fs = require('../util/fs');
var logger = require('../util/logger')('clean');
const createBitmaps = require('../util/createBitmaps');
const fs = require('../util/fs');
const logger = require('../util/logger')('clean');
const { shouldRunDocker, runDocker } = require('../util/runDocker');

module.exports = {
execute: function (config) {
if (config.args.docker) {
const passAlongArgs = process.argv
.slice(3)
.join(' ')
.replace(/--docker/, '--moby');

const DOCKER_TEST = `docker run --rm -it --mount type=bind,source="$(pwd)",target=/src backstopjs/backstopjs reference ${passAlongArgs}`;
const { spawn } = require('child_process');
console.log('Delegating command to Docker...', DOCKER_TEST)

return new Promise((resolve, reject) => {
const dockerProcess = spawn(DOCKER_TEST, {stdio: 'inherit', shell: true});
dockerProcess.on('exit', function (code, signal) {
if (code === 0) {
resolve();
} else {
reject('');
}
});
});

if (shouldRunDocker(config)) {
return runDocker(config, 'reference');
} else {
var firstStep;
// do not remove reference directory if we are in incremental mode
Expand Down
39 changes: 11 additions & 28 deletions core/command/test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
var createBitmaps = require('../util/createBitmaps');
const createBitmaps = require('../util/createBitmaps');
const { shouldRunDocker, runDocker } = require('../util/runDocker');

// This task will generate a date-named directory with DOM screenshot files as specified in `./capture/config.json` followed by running a report.
// NOTE: If there is no bitmaps_reference directory or if the bitmaps_reference directory is empty then a new batch of reference files will be generated in the bitmaps_reference directory. Reporting will be skipped in this case.
module.exports = {
execute: function (config) {
const executeCommand = require('./index');
if (config.args.docker) {
const passAlongArgs = process.argv
.slice(3)
.join(' ')
.replace(/--docker/, '--moby');

const DOCKER_TEST = `docker run --rm -it --mount type=bind,source="$(pwd)",target=/src backstopjs/backstopjs reference ${passAlongArgs}`;
const { spawn } = require('child_process');
console.log('Delegating command to Docker...', DOCKER_TEST)

return new Promise((resolve, reject) => {
const dockerProcess = spawn(DOCKER_TEST, {stdio: 'inherit', shell: true});
dockerProcess.on('exit', function (code, signal) {
if (code === 0) {
resolve();
} else {
reject('');
}
});
}).finally(() => executeCommand('_openReport', config));

} else {
return createBitmaps(config, false).then(function () {
return executeCommand('_report', config);
});
}
const executeCommand = require('./index');
if (shouldRunDocker(config)) {
return runDocker(config, 'test')
.finally(() => executeCommand('_openReport', config));
} else {
return createBitmaps(config, false).then(function () {
return executeCommand('_report', config);
});
}
}
};
25 changes: 25 additions & 0 deletions core/util/runDocker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports.shouldRunDocker = (config) => config.args.docker;

module.exports.runDocker = (config, backstopCommand) => {
if (config.args.docker) {
const passAlongArgs = process.argv
.slice(3)
.join('" "') // in case of spaces in a command
.replace(/--docker/, '--moby');

const DOCKER_COMMAND = `docker run --rm -it --mount type=bind,source="${process.cwd()}",target=/src backstopjs/backstopjs ${backstopCommand} "${passAlongArgs}"`;
const { spawn } = require('child_process');
console.log('Delegating command to Docker...', DOCKER_COMMAND);

return new Promise((resolve, reject) => {
const dockerProcess = spawn(DOCKER_COMMAND, {stdio: 'inherit', shell: true});
dockerProcess.on('exit', function (code, signal) {
if (code === 0) {
resolve();
} else {
reject('');
}
});
});
}
};