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

e2e fixes #1151

Merged
merged 3 commits into from
Mar 11, 2024
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
"eject": "craco eject",
"serve": "npx serve --no-clipboard -l 3000 -- build/",
"typecheck": "tsc --noEmit",
"test:all": "craco test --testTimeout 15000",
"test:e2e": "cross-env E2E_HEADLESS=0 craco test --testPathPattern e2e -w 1 --testTimeout 15000",
"test:e2e:headless": "cross-env E2E_HEADLESS=1 craco test --testPathPattern e2e -w 1 --testTimeout 15000",
"test:all": "craco test --testTimeout 30000",
"test:e2e": "cross-env E2E_HEADLESS=0 craco test --testPathPattern e2e -w 1 --testTimeout 30000",
"test:e2e:headless": "cross-env E2E_HEADLESS=1 craco test --testPathPattern e2e -w 1 --testTimeout 30000",
"theme": "chakra-cli tokens src/deployment/default/theme.ts",
"theme:watch": "chakra-cli tokens src/deployment/default/theme.ts --watch",
"ci:update-version": "update-ci-version",
Expand Down
7 changes: 3 additions & 4 deletions src/e2e/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,9 @@ export class App {
await page.close({
runBeforeUnload: true,
});
// A delay is required to give us a chance to handle the dialog event.
// If this proves fragile we could wait for the success condition below
// and give up on testing the absence of a dialog.
await page.waitForTimeout(50);
await waitFor(() => {
expect(page.isClosed()).toEqual(true);
}, defaultWaitForOptions);
return this.dialogs.length === 1 && this.dialogs[0] === "beforeunload";
}

Expand Down
8 changes: 8 additions & 0 deletions src/e2e/documentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ describe("documentaion", () => {
});

it("Copy code and paste in editor", async () => {
if (process.platform === "darwin") {
// pasteToolkitCode doesn't work on Mac
return;
}
const tab = "Reference";
await app.selectAllInEditor();
await app.typeInEditor("# Initial document");
Expand All @@ -33,6 +37,10 @@ describe("documentaion", () => {
});

it("Copy code after dropdown choice and paste in editor", async () => {
if (process.platform === "darwin") {
// pasteToolkitCode doesn't work on Mac
return;
}
const tab = "Reference";
await app.selectAllInEditor();
await app.typeInEditor("# Initial document");
Expand Down
4 changes: 2 additions & 2 deletions src/editor/codemirror/language-server/autocompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
CompletionItemKind,
CompletionResolveRequest,
CompletionTriggerKind,
ConnectionError,
} from "vscode-languageserver-protocol";
import { ApiReferenceMap } from "../../../documentation/mapping/content";
import { LanguageServerClient } from "../../../language-server/client";
import { isErrorDueToDispose } from "../../../language-server/error-util";
import { Logging } from "../../../logging/logging";
import { clientFacet, uriFacet } from "./common";
import {
Expand Down Expand Up @@ -156,7 +156,7 @@ const createDocumentationResolver =
);
documentation = resolved.documentation;
} catch (e) {
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
throw e;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/editor/codemirror/language-server/signatureHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import {
Command,
EditorView,
KeyBinding,
keymap,
logException,
PluginValue,
showTooltip,
ViewPlugin,
ViewUpdate,
keymap,
logException,
showTooltip,
} from "@codemirror/view";
import { IntlShape } from "react-intl";
import {
ConnectionError,
MarkupContent,
SignatureHelp,
SignatureHelpParams,
SignatureHelpRequest,
} from "vscode-languageserver-protocol";
import { ApiReferenceMap } from "../../../documentation/mapping/content";
import { isErrorDueToDispose } from "../../../language-server/error-util";
import { BaseLanguageServerView, clientFacet, uriFacet } from "./common";
import {
DocSections,
Expand Down Expand Up @@ -104,7 +104,7 @@ const triggerSignatureHelpRequest = async (
effects: [setSignatureHelpResult.of(result)],
});
} catch (e) {
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
logException(state, e, "signature-help");
}
view.dispatch({
Expand Down
13 changes: 5 additions & 8 deletions src/language-server/apidocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
*
* SPDX-License-Identifier: MIT
*/
import {
ConnectionError,
ProtocolRequestType,
} from "vscode-languageserver-protocol";
import { ProtocolRequestType } from "vscode-languageserver-protocol";
import { MarkupKind } from "vscode-languageserver-types";
import { LanguageServerClient } from "./client";
import { isErrorDueToDispose } from "./error-util";

// This duplicates the types we added to Pyright.

Expand Down Expand Up @@ -88,10 +86,9 @@ export const apiDocs = async (
});
return result;
} catch (e) {
if (!(e instanceof ConnectionError)) {
throw e;
if (isErrorDueToDispose(e)) {
return {};
}
// We'll requery when the client is recreated.
return {};
throw e;
}
};
14 changes: 5 additions & 9 deletions src/language-server/client-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
*
* SPDX-License-Identifier: MIT
*/
import {
ConnectionError,
CreateFile,
DeleteFile,
} from "vscode-languageserver-protocol";
import { diff, EVENT_PROJECT_UPDATED, FileSystem, Project } from "../fs/fs";
import { CreateFile, DeleteFile } from "vscode-languageserver-protocol";
import { EVENT_PROJECT_UPDATED, FileSystem, Project, diff } from "../fs/fs";
import { isPythonFile } from "../project/project-utils";
import { createUri, LanguageServerClient } from "./client";
import { LanguageServerClient, createUri } from "./client";
import { isErrorDueToDispose } from "./error-util";

export type FsChangesListener = (current: Project) => any;

Expand Down Expand Up @@ -84,8 +81,7 @@ export const trackFsChanges = (
}
}
} catch (e) {
// A new listener will be initialized for a replacement connection.
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
throw e;
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/language-server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
CompletionList,
CompletionParams,
CompletionRequest,
ConnectionError,
ConnectionErrors,
Diagnostic,
DiagnosticSeverity,
DiagnosticTag,
Expand All @@ -32,6 +30,7 @@ import {
} from "vscode-languageserver-protocol";
import { retryAsyncLoad } from "../common/chunk-util";
import { microPythonConfig } from "../micropython/micropython";
import { isErrorDueToDispose } from "./error-util";

/**
* Create a URI for a source document under the default root of file:///src/.
Expand Down Expand Up @@ -174,10 +173,7 @@ export class LanguageServerClient extends EventEmitter {
this.capabilities = capabilities;
this.connection.sendNotification(InitializedNotification.type, {});
} catch (e) {
if (
e instanceof ConnectionError &&
e.code === ConnectionErrors.Disposed
) {
if (isErrorDueToDispose(e)) {
// We've intentionally disposed the connection because we're recreating the client.
// This mostly happens due to React 18 strict mode but could happen due to language changes.
return false;
Expand Down Expand Up @@ -242,8 +238,7 @@ export class LanguageServerClient extends EventEmitter {
params
);
} catch (e) {
// Client being recreated, give no results.
if (!(e instanceof ConnectionError)) {
if (!isErrorDueToDispose(e)) {
throw e;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/language-server/error-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ConnectionError, ErrorCodes, ResponseError } from "vscode-jsonrpc";

// The language server gets disposed/recreated which can cause errors for
// initialization or in-flight requests. We ignore these when they occur.
export const isErrorDueToDispose = (e: unknown): boolean =>
(e instanceof ResponseError &&
e.code === ErrorCodes.PendingResponseRejected) ||
e instanceof ConnectionError;
Loading