Skip to content

Commit

Permalink
Merge pull request #1 from chandlerprall/visual-regression-rests-521
Browse files Browse the repository at this point in the history
refactor run-visual-tests.js into async/await
  • Loading branch information
cuff-links authored Apr 24, 2018
2 parents 9304c4b + b1eeea6 commit 72a5ca5
Showing 1 changed file with 70 additions and 24 deletions.
94 changes: 70 additions & 24 deletions scripts/run-visual-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
const { execSync } = require('child_process');
const git = require('nodegit');

const checkoutOpts = {
checkoutStrategy: git.Checkout.STRATEGY.SAFE
};

(async function run() {
const repo = await git.Repository.open("./");

let currentBranch = await repo.getCurrentBranch();
const initialBranch = currentBranch.shorthand();

if (initialBranch === 'master') {
throw new Error("Must be on branch to test against master. Currently on master.")
}
console.log(displayCurrentBranch(currentBranch));

console.log('Switching to master');
await repo.checkoutBranch("master", checkoutOpts);
currentBranch = await repo.getCurrentBranch();
console.log(displayCurrentBranch(currentBranch));

console.log('running tests');
execSync('yarn start-test-server-and-visual-test', { stdio: [0,1,2] } );

console.log('Switching to ' + initialBranch);
await repo.checkoutBranch(initialBranch, checkoutOpts);
currentBranch = await repo.getCurrentBranch();
console.log(displayCurrentBranch(currentBranch));

console.log('running tests');
execSync('yarn start-test-server-and-visual-test', { stdio: [0,1,2] } );
})()
.then(function() {
console.log('Finished.')
})
.catch(function(err){
console.log(err);
});

function displayCurrentBranch(branch) {
return "Currently on " + branch.shorthand() + ": " + branch.target();
}

// stop script
return;


var initialBranch;

(function IIFE(){
Expand All @@ -12,32 +58,32 @@ var initialBranch;
.then(function(repo) {
self.repo = repo;
return self.repo.getCurrentBranch()
.then(function (branch) {
initialBranch = branch.shorthand();
if (initialBranch === 'master') {
throw new Error("Must be on branch to test against master. Currently on master.")
}
console.log(displayCurrentBranch(branch));
})
.then(function (){
console.log('Switching to master');
return self.repo.checkoutBranch("master", checkoutOpts)
})
.then(function(){
return self.repo.getCurrentBranch()
.then(function (branch) {
console.log(displayCurrentBranch(branch));
execSync('yarn start-test-server-and-visual-test', { stdio: [0,1,2] } );
initialBranch = branch.shorthand();
if (initialBranch === 'master') {
throw new Error("Must be on branch to test against master. Currently on master.")
}
console.log(displayCurrentBranch(branch));
})
.then(function (){
console.log('Switching to master');
return self.repo.checkoutBranch("master", checkoutOpts)
})
.then(function(){
return self.repo.getCurrentBranch()
.then(function (branch) {
console.log(displayCurrentBranch(branch));
execSync('yarn start-test-server-and-visual-test', { stdio: [0,1,2] } );
})
})
.then(function() {
console.log('Switching to ' + initialBranch);
return self.repo.checkoutBranch(initialBranch, checkoutOpts)
})
})
.then(function() {
console.log('Switching to ' + initialBranch);
return self.repo.checkoutBranch(initialBranch, checkoutOpts)
})
.then(self.repo.getCurrentBranch().then(function(branch) {
console.log(displayCurrentBranch(branch))
execSync('yarn start-test-server-and-visual-test', { stdio: [0,1,2] } )
}))
.then(self.repo.getCurrentBranch().then(function(branch) {
console.log(displayCurrentBranch(branch))
execSync('yarn start-test-server-and-visual-test', { stdio: [0,1,2] } )
}))
})
.catch(function(err){
console.log(err);
Expand Down

0 comments on commit 72a5ca5

Please sign in to comment.