Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch editor on error #195

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions server/api/app/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <some text> (<file path>)
// it captures <file path> 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 "";
}
}
3 changes: 3 additions & 0 deletions ui/test-file/open-failure.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation OpenFailure($failure: String!) {
openFailure(failure: $failure)
}
13 changes: 12 additions & 1 deletion ui/test-file/test-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 (
<Container>
<Content only={only}>
<Content only={only} onClick={ () => openFailure()}>
<Label>
<TestIndicator
status={
Expand Down