Skip to content

Commit

Permalink
Merge pull request #285 from happo/more-logging
Browse files Browse the repository at this point in the history
More logging
  • Loading branch information
trotzig authored Jun 25, 2024
2 parents 5fd8016 + 68f8f45 commit f19781e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bin/happo-ci
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ echo "HAPPO_GIT_COMMAND: ${HAPPO_GIT_COMMAND}"
echo "HAPPO_COMMAND: ${HAPPO_COMMAND}"
echo "HAPPO_FALLBACK_SHAS_COUNT: ${HAPPO_FALLBACK_SHAS_COUNT}"

echo "Using Node version: $(node -v)"

set +e
HAPPO_VERSION=$("$HAPPO_COMMAND" version)
if [ $? -eq 0 ]; then
echo "Using happo CLI version: ${HAPPO_VERSION}"
else
echo "Failed to execute ${HAPPO_COMMAND}. Are you running from a subdirectory in the repository perhaps? To resolve this, you could either run from the repository root or set the environment variable HAPPO_COMMAND to override where Happo looks for the the cli.js script." >&2
exit 1
fi
set -e


NPM_CLIENT="npm"
NPM_CLIENT_FLAGS="--no-save"
CHECK_FOR_HAPPO="npm ls happo.io"
Expand Down
5 changes: 5 additions & 0 deletions test/cli-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ if (/compare no-report bar/.test(cmd)) {
if (/compare fail bar/.test(cmd)) {
process.exit(1);
}

if (/version/.test(cmd)) {
console.log('v0.0.999');
process.exit(0);
}
18 changes: 18 additions & 0 deletions test/happo-ci-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ describe('when CURRENT_SHA is missing', () => {
});
});

describe('when HAPPO_COMMAND is pointing to a non-existant file', () => {
beforeEach(() => {
env.HAPPO_COMMAND = './foo/bar.js';
});

it('fails with a message', () => {
expect(subject).toThrow(/Failed to execute \.\/foo\/bar\.js/);
});
});

describe('when CHANGE_URL is missing', () => {
beforeEach(() => {
delete env.CHANGE_URL;
Expand All @@ -84,6 +94,7 @@ describe('when CURRENT_SHA and PREVIOUS_SHA is the same', () => {
it('runs a single report', () => {
subject();
expect(getCliLog()).toEqual([
'version',
'run bar --link http://foo.bar/ --message Commit message',
]);
expect(getGitLog()).toEqual([
Expand All @@ -99,6 +110,7 @@ describe('when there is a report for PREVIOUS_SHA', () => {
it('runs the right happo commands', () => {
subject();
expect(getCliLog()).toEqual([
'version',
'start-job foo bar --link http://foo.bar/ --message Commit message',
'run bar --link http://foo.bar/ --message Commit message',
'compare foo bar --link http://foo.bar/ --message Commit message --author Tom Dooner <tom@dooner.com>',
Expand All @@ -121,6 +133,7 @@ describe('when there is a report for PREVIOUS_SHA', () => {
it('runs the right happo commands', () => {
subject();
expect(getCliLog()).toEqual([
'version',
'start-job foo bar --link http://foo.bar/ --message Commit message',
'run bar --link http://foo.bar/ --message Commit message',
'has-report foo',
Expand All @@ -146,6 +159,7 @@ describe('when there is a report for PREVIOUS_SHA', () => {
it('runs the right happo commands', () => {
subject();
expect(getCliLog()).toEqual([
'version',
'run bar --link http://foo.bar/ --message Commit message',
'compare foo bar --link http://foo.bar/ --message Commit message --author Tom Dooner <tom@dooner.com>',
]);
Expand Down Expand Up @@ -220,6 +234,7 @@ describe('when there is no report for PREVIOUS_SHA', () => {
it('does not checkout anything, runs a single report', () => {
subject();
expect(getCliLog()).toEqual([
'version',
'start-job no-report bar --link http://foo.bar/ --message Commit message',
'run bar --link http://foo.bar/ --message Commit message',
'compare no-report bar --link http://foo.bar/ --message Commit message --author Tom Dooner <tom@dooner.com>',
Expand All @@ -241,6 +256,7 @@ describe('when there is no report for PREVIOUS_SHA', () => {
it('runs the right happo commands', () => {
subject();
expect(getCliLog()).toEqual([
'version',
'start-job no-report bar --link http://foo.bar/ --message Commit message',
'run bar --link http://foo.bar/ --message Commit message',
'has-report no-report',
Expand Down Expand Up @@ -272,6 +288,7 @@ describe('when the compare call fails', () => {
it('fails the script', () => {
expect(subject).toThrow();
expect(getCliLog()).toEqual([
'version',
'start-job fail bar --link http://foo.bar/ --message Commit message',
'run bar --link http://foo.bar/ --message Commit message',
'compare fail bar --link http://foo.bar/ --message Commit message --author Tom Dooner <tom@dooner.com>',
Expand All @@ -296,6 +313,7 @@ describe('when happo.io is not installed for the PREVIOUS_SHA and HAPPO_IS_ASYNC
it('runs the right happo commands', () => {
subject();
expect(getCliLog()).toEqual([
'version',
'start-job no-happo bar --link http://foo.bar/ --message Commit message',
'run bar --link http://foo.bar/ --message Commit message',
'has-report no-happo',
Expand Down

0 comments on commit f19781e

Please sign in to comment.