Skip to content

Commit

Permalink
added ability to click on an error and open the offending file in VSCode
Browse files Browse the repository at this point in the history
This adds the ability to quickly jump to the error in the source file on a failing test.
This fixes issue Raathigesh#186
  • Loading branch information
Greg Veres committed Apr 17, 2020
1 parent 8e67b5c commit 9fe44e4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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 @@ -6,6 +6,8 @@ import TestIndicator from "./test-indicator";
import { color, space } from "styled-system";
import * as Convert from "ansi-to-html";
import { CollapseStore } from "./collapseStore";
import OPEN_FAILURE from "./open-failure.gql";
import { useMutation } from "react-apollo-hooks";

const convert = new Convert({
colors: {
Expand Down Expand Up @@ -119,10 +121,19 @@ export default function Test({
const newState = !hideChildren;
setHideChildren(newState);
CollapseStore.setState(id, newState);
if (children && children.length > 0) {
}
}

const openFailure = useMutation(OPEN_FAILURE, {
variables: {
failure: testResult && testResult.failureMessages ? testResult.failureMessages[0] : ''
}
});

return (
<Container>
<Content only={only} onClick={() => toggleShowChildern()}>
<Content only={only} onClick={() => (children && children.length > 0) ? toggleShowChildern() : openFailure()}>
<Label>
{ children && children.length > 0 && (
<ViewToggle>
Expand Down

0 comments on commit 9fe44e4

Please sign in to comment.