remove unneccessary try/catch
MODIFY
bin-src/main.test.ts
bin-src/main.test.ts
@@ -81,6 +81,7 @@ jest.mock('node-fetch', () =>
billingUrl: 'https://foo.bar',
exceededThreshold: false,
paymentRequired: false,
+ setupUrl: 'https://setup.com',
},
},
tests: [
@@ -140,6 +141,16 @@ jest.mock('node-fetch', () =>
};
}
+ if (query.match('AppyByCodeQuery')) {
+ return {
+ data: {
+ appByCode: {
+ isOnboarding: true,
+ },
+ },
+ };
+ }
+
throw new Error(`Unknown Query: ${query}`);
},
}))

MODIFY
bin-src/tasks/auth.test.ts
bin-src/tasks/auth.test.ts
-import { setAuthorizationToken } from './auth';
+import { getAppInfo, setAuthorizationToken } from './auth';
describe('setAuthorizationToken', () => {
it('updates the GraphQL client with an app token from the index', async () => {
@@ -9,3 +9,19 @@ describe('setAuthorizationToken', () => {
expect(client.setAuthorization).toHaveBeenCalledWith('token');
});
});
+
+describe('getAppInfo', () => {
+ it('retreives onboarding info using project token', async () => {
+ const client = { runQuery: jest.fn(), setAuthorization: jest.fn() };
+ client.runQuery.mockReturnValue({ appByCode: { isOnboarding: true } });
+
+ const ctx = {
+ client,
+ options: { projectToken: 'test' },
+ isOnboarding: false,
+ };
+
+ await getAppInfo(ctx as any);
+ expect(ctx.isOnboarding).toBeTruthy();
+ });
+});

MODIFY
bin-src/tasks/auth.ts
bin-src/tasks/auth.ts
@@ -9,9 +9,9 @@ const CreateAppTokenMutation = `
}
`;
-const AppByCodeQuery = `
- query AppyByCodeQuery($code: String!) {
- appByCode(code: $code) {
+const AppQuery = `
+ query AppQuery {
+ app {
isOnboarding
}
}
@@ -19,8 +19,8 @@ const AppByCodeQuery = `
interface CreateAppTokenMutationResult {
createAppToken: string;
}
-interface AppyByCodeQueryResult {
- appByCode: {
+interface AppQueryResult {
+ app: {
isOnboarding: boolean;
};
}
@@ -35,10 +35,6 @@ export const setAuthorizationToken = async (ctx: Context) => {
variables
);
client.setAuthorization(appToken);
- const { appByCode: app } = await ctx.client.runQuery<AppyByCodeQueryResult>(AppByCodeQuery, {
- code: ctx.options.projectToken,
- });
- ctx.isOnboarding = app.isOnboarding;
} catch (errors) {
if (errors[0] && errors[0].message && errors[0].message.match('No app with code')) {
throw new Error(invalidProjectToken(variables));
@@ -47,7 +43,20 @@ export const setAuthorizationToken = async (ctx: Context) => {
}
};
+export const getAppInfo = async (ctx: Context) => {
+ const { client, options } = ctx;
+ const variables = { code: options.projectToken };
+
+ const { app } = await client.runQuery<AppQueryResult>(AppQuery, variables);
+ ctx.isOnboarding = app.isOnboarding;
+};
+
export default createTask({
title: initial.title,
- steps: [transitionTo(authenticating), setAuthorizationToken, transitionTo(authenticated, true)],
+ steps: [
+ transitionTo(authenticating),
+ setAuthorizationToken,
+ getAppInfo,
+ transitionTo(authenticated, true),
+ ],
});

MODIFY
bin-src/tasks/gitInfo.ts
bin-src/tasks/gitInfo.ts
@@ -94,6 +94,9 @@ export const setGitInfo = async (ctx: Context, task: Task) => {
ctx.git.parentCommits = parentCommits;
ctx.log.debug(`Found parentCommits: ${parentCommits.join(', ')}`);
+ if (ctx.isOnboarding) {
+ ctx.options.forceRebuild = true;
+ }
// If we're running against the same commit as the sole parent, then this is likely a rebuild (rerun of CI job).
// If the MRA is all green, there's no need to rerun the build, we just want the CLI to exit 0 so the CI job succeeds.
// This is especially relevant for (unlinked) projects that don't use --exit-zero-on-changes.
@@ -164,10 +167,6 @@ export const setGitInfo = async (ctx: Context, task: Task) => {
ctx.log.debug(e);
}
- if (ctx.isOnboarding && ctx.git.changedFiles && ctx.git.changedFiles.length) {
- ctx.options.forceRebuild = true;
- }
-
if (ctx.options.externals && ctx.git.changedFiles && ctx.git.changedFiles.length) {
// eslint-disable-next-line no-restricted-syntax
for (const glob of ctx.options.externals) {

MODIFY
bin-src/types.ts
bin-src/types.ts
@@ -136,7 +136,7 @@ export interface Context {
stopApp?: () => void;
closeTunnel?: () => void;
isPublishOnly?: boolean;
- isOnboarding?: boolean;
+ isOnboarding: boolean;
http: {
fetch: (url: string, options?: RequestInit, opts?: any) => Promise<Response>;

MODIFY
bin-src/ui/messages/errors/buildHasChanges.stories.ts
bin-src/ui/messages/errors/buildHasChanges.stories.ts
@@ -4,12 +4,20 @@ export default {
title: 'CLI/Messages/Errors',
};
-export const BuildHasChanges = () =>
- buildHasChanges({
+const context = {
build: {
number: 42,
changeCount: 2,
webUrl: 'https://www.chromatic.com/build?appId=59c59bd0183bd100364e1d57&number=42',
+ app: {
+ setupUrl: 'https://www.chromatic.com/setup?appId=59c59bd0183bd100364e1d57',
+ },
},
exitCode: 1,
- });
+ isOnboarding: false,
+};
+
+export const BuildHasChangesNotOnboarding = () => buildHasChanges(context);
+
+export const BuildHasChangesIsOnboarding = () =>
+ buildHasChanges({ ...context, isOnboarding: true });

MODIFY
bin-src/ui/messages/errors/buildHasChanges.ts
bin-src/ui/messages/errors/buildHasChanges.ts
@@ -5,10 +5,12 @@ import { dedent } from 'ts-dedent';
import { error, info } from '../../components/icons';
import link from '../../components/link';
-export default ({ build, exitCode }) => {
+export default ({ build, exitCode, isOnboarding }) => {
const changes = pluralize('visual changes', build.changeCount, true);
return dedent(chalk`
- ${error} {bold Found ${changes}}: Review the changes at ${link(build.webUrl)}
+ ${error} {bold Found ${changes}}: Review the changes at ${link(
+ isOnboarding ? build.app.setupUrl : build.webUrl
+ )}
${info} For CI/CD use cases, this command failed with exit code ${exitCode}
Pass {bold --exit-zero-on-changes} to succeed this command regardless of changes.

MODIFY
bin-src/ui/workflows/uploadBuild.stories.ts
bin-src/ui/workflows/uploadBuild.stories.ts
import task from '../components/task';
-import { BuildHasChanges } from '../messages/errors/buildHasChanges.stories';
+import { BuildHasChangesNotOnboarding } from '../messages/errors/buildHasChanges.stories';
import { BuildPassed, FirstBuildPassed } from '../messages/info/buildPassed.stories';
import { Intro } from '../messages/info/intro.stories';
import { StorybookPublished } from '../messages/info/storybookPublished.stories';
@@ -147,7 +147,7 @@ export const ChangesFound = () => [
verify.Published,
snapshot.BuildComplete
),
- BuildHasChanges(),
+ BuildHasChangesNotOnboarding(),
];
export const FirstBuild = () => [

remove unneccessary try/catch