diff --git a/server/api/app/resolver.ts b/server/api/app/resolver.ts index ee847d2..9d28050 100644 --- a/server/api/app/resolver.ts +++ b/server/api/app/resolver.ts @@ -3,6 +3,7 @@ import * as launch from "launch-editor"; import { App } from "./app"; import FileWatcher, { WatcherEvents } from "../../services/file-watcher"; import { pubsub } from "../../event-emitter"; +import { dirname, basename } from "path"; @Resolver(App) export default class AppResolver { @@ -45,7 +46,20 @@ export default class AppResolver { return ""; } + @Mutation(returns => String) + openSnapInEditor(@Arg("path") path: string) { + var dir = dirname(path) + var file = basename(path); + + var snap = dir + '/__snapshots__/' + file + '.snap' + console.log("opening the snapshot:", snap); + this.openInEditor(snap); + + return ""; + } + @Mutation(returns => String) + openFailure(@Arg("failure") failure: string) { // The following regex matches the first line of the form: \w at () // it captures and returns that in the second position of the match array diff --git a/ui/test-file/index.tsx b/ui/test-file/index.tsx index df6cc59..eafb9d0 100644 --- a/ui/test-file/index.tsx +++ b/ui/test-file/index.tsx @@ -95,14 +95,6 @@ function TestFile({ selectedFilePath, isRunning, projectRoot, onStop }: Props) { const isUpdating = isRunning && (result === null ||(result.numPassingTests === 0 && result.numFailingTests === 0)); - const haveSnapshotFailures = ((result && result.testResults) || []).some( - testResult => { - return (testResult.failureMessages || []).some(failureMessage => - failureMessage.includes("toMatchSnapshot") - ); - } - ); - const roots = (fileItemResult.items || []).filter( item => item.parent === null ); @@ -123,7 +115,6 @@ function TestFile({ selectedFilePath, isRunning, projectRoot, onStop }: Props) { isRunning={isRunning} isUpdating={isUpdating} isLoadingResult={loading} - haveSnapshotFailures={haveSnapshotFailures} onRun={() => { runFile(); }} diff --git a/ui/test-file/summary/index.tsx b/ui/test-file/summary/index.tsx index 3badfa3..fb85828 100644 --- a/ui/test-file/summary/index.tsx +++ b/ui/test-file/summary/index.tsx @@ -11,10 +11,12 @@ import { CheckCircle, Frown, ZapOff, - Circle + Circle, + Eye } from "react-feather"; import Button from "../../components/button"; import OPEN_IN_EDITOR from "./open-in-editor.gql"; +import OPEN_SNAP_IN_EDITOR from "./open-snap-in-editor.gql"; import { Tooltip } from "react-tippy"; import { useMutation } from "react-apollo-hooks"; @@ -130,7 +132,6 @@ export default function FileSummary({ onRun, onStop, onSnapshotUpdate, - haveSnapshotFailures }: Props) { const Icon = isRunning ? StopCircle : Play; @@ -140,6 +141,12 @@ export default function FileSummary({ } }); + const openSnapshotInEditor = useMutation(OPEN_SNAP_IN_EDITOR, { + variables: { + path + } + }); + return ( {( isUpdating || isLoadingResult) && } @@ -191,9 +198,8 @@ export default function FileSummary({ }} /> - {haveSnapshotFailures && ( @@ -207,7 +213,15 @@ export default function FileSummary({ Update Snapshot - )} + +