diff --git a/server/api/app/resolver.ts b/server/api/app/resolver.ts index 83df6ab..ee847d2 100644 --- a/server/api/app/resolver.ts +++ b/server/api/app/resolver.ts @@ -44,4 +44,22 @@ export default class AppResolver { 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 + let re = new RegExp('^\\s+at.*?\\((.*?)\\)$', 'm'); + let match = failure.match(re); + if (match && match.length === 2) { + const path = match[1]; + launch(path, process.env.EDITOR || "code", (path: string, err: any) => { + console.log("Failed to open file in editor. You may need to install the code command to your PATH if you are using VSCode: ", err); + }); + } + else { + console.log("Failed to find a path to a file to load in the failure string."); + } + return ""; + } } diff --git a/ui/test-file/open-failure.gql b/ui/test-file/open-failure.gql new file mode 100644 index 0000000..2eb6b5b --- /dev/null +++ b/ui/test-file/open-failure.gql @@ -0,0 +1,3 @@ +mutation OpenFailure($failure: String!) { + openFailure(failure: $failure) +} diff --git a/ui/test-file/test-item.tsx b/ui/test-file/test-item.tsx index 1e29694..f2a6446 100644 --- a/ui/test-file/test-item.tsx +++ b/ui/test-file/test-item.tsx @@ -5,6 +5,8 @@ import { TestFileResult } from "../../server/api/workspace/test-result/file-resu import TestIndicator from "./test-indicator"; import { color, space } from "styled-system"; import * as Convert from "ansi-to-html"; +import OPEN_FAILURE from "./open-failure.gql"; +import { useMutation } from "react-apollo-hooks"; const convert = new Convert({ colors: { @@ -93,9 +95,18 @@ export default function Test({ return true; }); + if (children && children.length > 0) { + } + + const openFailure = useMutation(OPEN_FAILURE, { + variables: { + failure: testResult && testResult.failureMessages ? testResult.failureMessages[0] : '' + } + }); + return ( - + openFailure()}>