Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Dec 19, 2018
1 parent 1255b04 commit 71dcfef
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 69 deletions.
80 changes: 38 additions & 42 deletions tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,34 @@ module.exports = yargs
desc: 'has new remote commits',
handler: () => {
run('git rev-parse --is-inside-work-tree')
.then(() =>
run('git remote -v update')
.then(() =>
Promise.all([
run('git rev-parse @'),
run('git rev-parse @{u}'),
run('git merge-base @ @{u}'),
])
.then(values => {
const [{ stdout: $local }, { stdout: $remote }, { stdout: $base }] = values;
.then(() => run('git remote -v update')
.then(() => Promise.all([
run('git rev-parse @'),
run('git rev-parse @{u}'),
run('git merge-base @ @{u}'),
])
.then(values => {
const [{ stdout: $local }, { stdout: $remote }, { stdout: $base }] = values;

if ($local === $remote) {
console.log(chalk.green('✔ Repo is up-to-date!'));
}
else if ($local === $base) {
console.log(chalk.red('⊘ Error'), 'You need to pull, there are new commits.');
process.exit(1);
}
})
.catch(err => {
if (err.message.includes('no upstream configured ')) {
console.log(chalk.yellow('⚠ Warning'), 'No upstream. Is this a new branch?');
return;
}

console.log(chalk.yellow('⚠ Warning'), err.message);
}))
if ($local === $remote) {
console.log(chalk.green('✔ Repo is up-to-date!'));
}
else if ($local === $base) {
console.log(chalk.red('⊘ Error'), 'You need to pull, there are new commits.');
process.exit(1);
}
})
.catch(err => {
throw new Error(err);
if (err.message.includes('no upstream configured ')) {
console.log(chalk.yellow('⚠ Warning'), 'No upstream. Is this a new branch?');
return;
}

console.log(chalk.yellow('⚠ Warning'), err.message);
}))
.catch(err => {
throw new Error(err);
}))
.catch(() => {
console.log('not under git');
});
Expand All @@ -67,21 +65,19 @@ module.exports = yargs
.command({
command: 'update',
desc: 'run `npm update` if package.json has changed',
handler: () => {
return run('git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD')
.then(({ stdout }) => {
if (stdout.match('package.json')) {
console.log(chalk.yellow('▼ Updating...'));
exec('npm update').stdout.pipe(process.stdout);
}
else {
console.log(chalk.green('✔ Nothing to update'));
}
})
.catch(err => {
throw new Error(err);
});
},
handler: () => run('git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD')
.then(({ stdout }) => {
if (stdout.match('package.json')) {
console.log(chalk.yellow('▼ Updating...'));
exec('npm update').stdout.pipe(process.stdout);
}
else {
console.log(chalk.green('✔ Nothing to update'));
}
})
.catch(err => {
throw new Error(err);
}),
})
.demandCommand()
.help()
Expand Down
31 changes: 5 additions & 26 deletions test/__setup__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,13 @@ import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

Object.defineProperty(window.location, 'href', {
writable: true,
value: 'http://localhost:3000/',
});

Object.defineProperty(window.location, 'pathname', {
writable: true,
value: '/',
});

Object.defineProperty(window.location, 'search', {
writable: true,
value: '',
});

Object.defineProperty(window, 'pageYOffset', {
writable: true,
value: '',
});

const react = document.createElement('div');
react.id = 'react';
react.style.height = '100vh';
document.body.appendChild(react);

window.matchMedia = () =>
({
matches: false,
addListener: () => {},
removeListener: () => {},
});
window.matchMedia = () => ({
matches: false,
addListener: () => {},
removeListener: () => {},
});
2 changes: 1 addition & 1 deletion test/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('ReactCreditCards', () => {

it('should handle empty expiry props', () => {
wrapper.setProps({
expiry: undefined,
expiry: '',
focused: 'expiry',
});

Expand Down

0 comments on commit 71dcfef

Please sign in to comment.