Skip to content

Commit

Permalink
click on error to open VSCode to error
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 May 15, 2020
1 parent 2296cf6 commit d71317b
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 @@ -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

0 comments on commit d71317b

Please sign in to comment.