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

Adding automatic clean up of bitmaps_test directory option #836

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion core/command/approve.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var fs = require('../util/fs');
var path = require('path');
var map = require('p-map');
const cleanupBitmapsTestDir = require('../util/cleanupBitmapsTestDir');

var FAILED_DIFF_RE = /^failed_diff_/;
var FILTER_DEFAULT = /\w+/;
Expand Down Expand Up @@ -38,7 +39,10 @@ module.exports = {
}
}
return true;
}).then(resolve).catch(reject);
}).then(() => {
cleanupBitmapsTestDir(config)
.finally(resolve);
}).catch(reject);
});
});
});
Expand Down
38 changes: 21 additions & 17 deletions core/command/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@ const createBitmaps = require('../util/createBitmaps');
const fs = require('../util/fs');
const logger = require('../util/logger')('clean');
const { shouldRunDocker, runDocker } = require('../util/runDocker');
const cleanupBitmapsTestDir = require('../util/cleanupBitmapsTestDir');

module.exports = {
execute: function (config) {
if (shouldRunDocker(config)) {
return runDocker(config, 'reference');
} else {
var firstStep;
// do not remove reference directory if we are in incremental mode
if (config.args.filter || config.args.i) {
firstStep = Promise.resolve();
} else {
firstStep = fs.remove(config.bitmaps_reference).then(function () {
logger.success(config.bitmaps_reference + ' was cleaned.');
});
}
return cleanupBitmapsTestDir(config)
.finally(() => {
if (shouldRunDocker(config)) {
return runDocker(config, 'reference');
} else {
var firstStep;
// do not remove reference directory if we are in incremental mode
if (config.args.filter || config.args.i) {
firstStep = Promise.resolve();
} else {
firstStep = fs.remove(config.bitmaps_reference).then(function () {
logger.success(config.bitmaps_reference + ' was cleaned.');
});
}

return firstStep.then(function () {
return createBitmaps(config, true);
}).then(function () {
console.log('\nRun `$ backstop test` to generate diff report.\n');
return firstStep.then(function () {
return createBitmaps(config, true);
}).then(function () {
console.log('\nRun `$ backstop test` to generate diff report.\n');
});
}
});
}
}
};
20 changes: 12 additions & 8 deletions core/command/test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
const createBitmaps = require('../util/createBitmaps');
const { shouldRunDocker, runDocker } = require('../util/runDocker');
const cleanupBitmapsTestDir = require('../util/cleanupBitmapsTestDir');

// 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 (shouldRunDocker(config)) {
return runDocker(config, 'test')
.finally(() => executeCommand('_openReport', config));
} else {
return createBitmaps(config, false).then(function () {
return executeCommand('_report', config);
return cleanupBitmapsTestDir(config)
.finally(() => {
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);
});
}
});
}
}
};
13 changes: 13 additions & 0 deletions core/util/cleanupBitmapsTestDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var fs = require('../util/fs');
var logger = require('../util/logger')('clean');

function cleanupBitmapsTestDir (config) {
if (config.cleanupBitmapsTestDir) {
return fs.remove(config.bitmaps_test).then(function () {
logger.success(config.bitmaps_test + ' was cleaned.');
});
}
return Promise.resolve();
}

module.exports = cleanupBitmapsTestDir;
1 change: 1 addition & 0 deletions core/util/extendConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function extendConfig (config, userConfig) {
config.resembleOutputOptions = userConfig.resembleOutputOptions;
config.asyncCompareLimit = userConfig.asyncCompareLimit;
config.backstopVersion = version;
config.cleanupBitmapsTestDir = userConfig.cleanupBitmapsTestDir || false;
return config;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"init": "node ./cli/index.js init",
"reference": "node ./cli/index.js reference",
"test": "node ./cli/index.js test",
"approve": "node ./cli/index.js approve",
"openReport": "node ./cli/index.js openReport",
"echo": "node ./cli/index.js echo",
"unit-test": "mocha --reporter spec --recursive test/cli",
Expand Down