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

refactor run-visual-tests.js into async/await #1

Merged
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
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