Skip to content
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
34 changes: 34 additions & 0 deletions src/test/suite/asyncSafety.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { AsyncFunc, Context, Done } from "mocha";

/**
* if an async returns after the method times out,
* it will cause a "done() called multiple times" error.
* In the context of a running webdriver, this is potentially very bad.
* We need to be able to quit the driver gracefully under any circumstances.
* This allows methods to time out while an async is pending,
* and will avoid calling done twice in this case.
*
* From https://github.com/mochajs/mocha/issues/967#issuecomment-810484206
* @param fn The test function to run
* @returns A safely wrapped test function
*/
export default function asyncSafety(fn: AsyncFunc) {
return function (this: Context, done: Done) {
let runnable = this.runnable();

fn.bind(this)()
.then((res) => {
// for successful I think we only need timedOut? not sure though, might have side effects
// when the duration check is added it will get stuck and never complete on a second runthrough
if (!runnable.timedOut) {
done(res);
}
})
// @ts-ignore
.catch((err) => {
if (!runnable.timedOut && !runnable.duration) {
done(err);
}
});
};
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spokenForm: clear pair
languageId: typescript
command:
actionName: clearAndSetSelection
partialTargets:
- type: primitive
modifier: {type: surroundingPair, delimiter: any}
extraArgs: []
initialState:
documentContents: "const {hello} = {hello: \"world\"}"
selections:
- anchor: {line: 0, character: 23}
active: {line: 0, character: 23}
marks: {}
finalState:
documentContents: "const {hello} = "
selections:
- anchor: {line: 0, character: 16}
active: {line: 0, character: 16}
thatMark:
- anchor: {line: 0, character: 16}
active: {line: 0, character: 16}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: surroundingPair, delimiter: any}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spokenForm: clear pair
languageId: typescript
command:
actionName: clearAndSetSelection
partialTargets:
- type: primitive
modifier: {type: surroundingPair, delimiter: any}
extraArgs: []
initialState:
documentContents: "const {hello} = {hello: \"world\"}"
selections:
- anchor: {line: 0, character: 28}
active: {line: 0, character: 28}
marks: {}
finalState:
documentContents: "const {hello} = {hello: }"
selections:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
thatMark:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: surroundingPair, delimiter: any}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spokenForm: clear pair
languageId: typescript
command:
actionName: clearAndSetSelection
partialTargets:
- type: primitive
modifier: {type: surroundingPair, delimiter: any}
extraArgs: []
initialState:
documentContents: "const {hello} = {hello: \"world\"}"
selections:
- anchor: {line: 0, character: 10}
active: {line: 0, character: 10}
marks: {}
finalState:
documentContents: "const = {hello: \"world\"}"
selections:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
thatMark:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: surroundingPair, delimiter: any}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spokenForm: clear pair
languageId: typescript
command:
actionName: clearAndSetSelection
partialTargets:
- type: primitive
modifier: {type: surroundingPair, delimiter: any}
extraArgs: []
initialState:
documentContents: () => {return 0;}
selections:
- anchor: {line: 0, character: 12}
active: {line: 0, character: 12}
marks: {}
finalState:
documentContents: "() => "
selections:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
thatMark:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: surroundingPair, delimiter: any}}]
8 changes: 7 additions & 1 deletion src/test/suite/recorded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from "../../util/getExtensionApi";
import { enableDebugLog } from "../../util/debug";
import { extractTargetedMarks } from "../../testUtil/extractTargetedMarks";
import asyncSafety from "./asyncSafety";

function createPosition(position: PositionPlainObject) {
return new vscode.Position(position.line, position.character);
Expand All @@ -49,7 +50,12 @@ suite("recorded test cases", async function () {
sinon.restore();
});

files.forEach((file) => test(file.split(".")[0], () => runTest(file)));
files.forEach((file) =>
test(
file.split(".")[0],
asyncSafety(() => runTest(file))
)
);
});

async function runTest(file: string) {
Expand Down