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
854 changes: 17 additions & 837 deletions src/microsoft-trydotnet/package-lock.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/microsoft-trydotnet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"devDependencies": {
"@rollup/plugin-commonjs": "29.0.3",
"@rollup/plugin-node-resolve": "16.0.3",
"@types/chai": "5.0.1",
"@types/chai": "5.2.3",
"@types/chai-as-promised": "^8.0.2",
"@types/chai-subset": "^1.3.6",
"@types/jsdom": "^30.0.0",
"@types/mocha": "^10.0.10",
"@types/node": "^26.2.0",
Expand All @@ -31,7 +30,6 @@
"requirejs": "^2.3.8",
"rollup": "4.62.4",
"rollup-plugin-typescript2": "0.37.0",
"source-map-loader": "5.0.0",
"source-map-support": "0.5.21",
"ts-mocha": "11.1.0",
"ts-node": "10.9.2",
Expand Down
16 changes: 7 additions & 9 deletions src/microsoft-trydotnet/test/internals/document.specs.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import * as chai from "chai";
import { expect } from "chai";
import { DocumentId } from "../../src/documentId";
import { Document } from "../../src/internals/document";
import { FakeMonacoTextEditor } from "../fakes/fakeMonacoTextEditor";

chai.should();


describe("a document", () => {

it("is not marked as modified at creation", () => {
let document = new Document(DocumentId.parse("program.cs"), "content");
document.isModified.should.be.false;
expect(document.isModified).to.be.false;
});

it("is not marked as modified when the content is changed from editor", async () => {
let document = new Document(DocumentId.parse("program.cs"), "content");
let editor = new FakeMonacoTextEditor("0");
await document.bindToEditor(editor);
editor.raiseTextEvent("other content");
document.isModified.should.be.false;
document.getContent().should.be.equal("other content");
expect(document.isModified).to.be.false;
expect(document.getContent()).to.equal("other content");
});

it("is active if bound to an editor", async () => {
let document = new Document(DocumentId.parse("program.cs"), "content");
let editor = new FakeMonacoTextEditor("0");
document.isActiveInEditor().should.be.false;
expect(document.isActiveInEditor()).to.be.false;
await document.bindToEditor(editor);
document.isActiveInEditor().should.be.true;
expect(document.isActiveInEditor()).to.be.true;
});

it("is marked as modified when the content is changed via setContent", async () => {
let document = new Document(DocumentId.parse("program.cs"), "content");
await document.setContent("modified content");
document.isModified.should.be.true;
expect(document.isModified).to.be.true;
});

});
34 changes: 17 additions & 17 deletions src/microsoft-trydotnet/test/internals/monacoEditor.specs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import * as chai from "chai";

import { expect } from "chai";
import { MonacoTextEditor } from "../../src/internals/monacoTextEditor";
import { FakeMessageBus } from "../fakes/fakeMessageBus";
import { FakeIdGenerator } from "../fakes/fakeIdGenerator";
import * as newContract from "../../src/newContract";

chai.should();

describe("a monaco editor", () => {

Expand All @@ -25,8 +25,8 @@ describe("a monaco editor", () => {
let messages: { type: string, requestId?: string }[] = [];
bus.requests.subscribe({ next: m => messages.push(m) });
editor.setTheme("different theme");
messages.should.not.be.empty;
messages[0].type.should.equal(newContract.ConfigureMonacoEditorType);
expect(messages).to.not.be.empty;
expect(messages[0].type).to.equal(newContract.ConfigureMonacoEditorType);
});

it("can set the theme as object", () => {
Expand All @@ -44,9 +44,9 @@ describe("a monaco editor", () => {
}]
}
});
messages.should.not.be.empty;
messages[0].type.should.equal(newContract.DefineMonacoEditorThemesType);
(messages[0] as any).themes.should.deep.equal({
expect(messages).to.not.be.empty;
expect(messages[0].type).to.equal(newContract.DefineMonacoEditorThemesType);
expect((messages[0] as any).themes).to.deep.equal({
"different theme": {
base: 'vs-dark',
inherit: true,
Expand All @@ -57,7 +57,7 @@ describe("a monaco editor", () => {
}]
}
});
messages[1].type.should.equal(newContract.ConfigureMonacoEditorType);
expect(messages[1].type).to.equal(newContract.ConfigureMonacoEditorType);
});

it("can set the editor options", () => {
Expand All @@ -68,10 +68,10 @@ describe("a monaco editor", () => {
enabled: false
}
});
messages.should.not.be.empty;
messages[0].type.should.equal(newContract.ConfigureMonacoEditorType);
messages[0].type.should.equal(newContract.ConfigureMonacoEditorType);
(messages[0] as any).editorOptions.minimap.should.deep.equal(
expect(messages).to.not.be.empty;
expect(messages[0].type).to.equal(newContract.ConfigureMonacoEditorType);
expect(messages[0].type).to.equal(newContract.ConfigureMonacoEditorType);
expect((messages[0] as any).editorOptions.minimap).to.deep.equal(
{
enabled: false
});
Expand All @@ -88,14 +88,14 @@ describe("a monaco editor", () => {
}
}
});
messages.should.not.be.empty;
messages[0].type.should.equal(newContract.ConfigureMonacoEditorType);
(messages[0] as any).editorOptions.minimap.should.deep.equal(
expect(messages).to.not.be.empty;
expect(messages[0].type).to.equal(newContract.ConfigureMonacoEditorType);
expect((messages[0] as any).editorOptions.minimap).to.deep.equal(
{
enabled: false
});
messages[1].type.should.equal(newContract.ConfigureMonacoEditorType);
(messages[1] as any).theme.should.equal("different theme");
expect(messages[1].type).to.equal(newContract.ConfigureMonacoEditorType);
expect((messages[1] as any).theme).to.equal("different theme");
});

});
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import * as chai from "chai";
import { expect } from "chai";
import { buildSimpleIFrameDom } from "../domUtilities";
import * as trydotnet from "../../src/index";
import { IFrameMessageBus } from "../../src/internals/messageBus";
import { configureEmbeddableEditorIFrame } from "../../src/htmlDomHelpers";
import { RequestIdGenerator } from "../../src/internals/requestIdGenerator";

chai.should();

describe("a request id generator", () => {

const defaultConfiguration: trydotnet.Configuration = { hostOrigin: "https://learn.microsoft.com" };
Expand All @@ -26,6 +24,6 @@ describe("a request id generator", () => {

let opId = await generator.getNewRequestId();

opId.should.contain("trydotnetjs.session");
expect(opId).to.contain("trydotnetjs.session");
});
});
28 changes: 13 additions & 15 deletions src/microsoft-trydotnet/test/internals/workspace.specs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import * as chai from "chai";
import { Workspace } from "../../src/internals/workspace";
import { createProject } from "../../src";
import { FakeMonacoTextEditor } from "../fakes/fakeMonacoTextEditor";
Expand All @@ -10,13 +9,12 @@ import { expect } from "chai";
import { RequestIdGenerator } from "../../src/internals/requestIdGenerator";
import * as polyglotNotebooks from "@microsoft/polyglot-notebooks";
import * as newContract from "../../src/newContract";
chai.should();

describe("a workspace", () => {

it("is not marked as modified at creation", () => {
let ws = new Workspace(new FakeMessageBus("0"), new RequestIdGenerator());
ws.isModified().should.be.false;
expect(ws.isModified()).to.be.false;
});

it("is not marked as modified when propulated from a project", async () => {
Expand Down Expand Up @@ -53,7 +51,7 @@ describe("a workspace", () => {

let project = await createProject({ packageName: "console", files: [{ name: "program.cs", content: "the program" }, { name: "otherFile.cs", content: "other file content" }] });
await ws.fromProject(project);
ws.isModified().should.be.false;
expect(ws.isModified()).to.be.false;
});


Expand Down Expand Up @@ -103,7 +101,7 @@ describe("a workspace", () => {
let project = await createProject({ packageName: "console", files: [{ name: "program.cs", content: "the program" }, { name: "otherFile.cs", content: "other file content" }] });
await ws.fromProject(project);
await ws.openDocument({ fileName: "program.cs" });
ws.isModified().should.be.false;
expect(ws.isModified()).to.be.false;
});

it("is not marked as modified when a document is opened again", async () => {
Expand Down Expand Up @@ -152,7 +150,7 @@ describe("a workspace", () => {
await ws.fromProject(project);
let doc = await ws.openDocument({ fileName: "program.cs" });
ws.toOpenProjectRequests();
ws.isModified().should.be.false;
expect(ws.isModified()).to.be.false;
doc = await ws.openDocument({ fileName: "program.cs" });
});

Expand Down Expand Up @@ -203,7 +201,7 @@ describe("a workspace", () => {
await ws.fromProject(project);
let doc = await ws.openDocument({ fileName: "program.cs" });
doc.setContent("modified content");
ws.isModified().should.be.true;
expect(ws.isModified()).to.be.true;
});

it("generates openProject request object", async () => {
Expand Down Expand Up @@ -253,9 +251,9 @@ describe("a workspace", () => {
let doc = await ws.openDocument({ fileName: "program.cs" });
doc.setContent("modified content");
let opr = ws.toOpenProjectRequests();
opr.should.not.be.null;
opr.project.should.not.be.null;
opr.project.files[0].should.not.be.null;
expect(opr).not.to.be.null;
expect(opr.project).not.to.be.null;
expect(opr.project.files[0]).not.to.be.null;
});

it("can open a document and set its content", async () => {
Expand Down Expand Up @@ -312,7 +310,7 @@ describe("a workspace", () => {
await ws.fromProject(project);
let doc = await ws.openDocument({ fileName: "program.cs", content: "content override" });
expect(doc).not.to.be.null;
doc.getContent().should.be.equal("content override");
expect(doc.getContent()).to.equal("content override");
});

it("can open a document in the editor and set its content", async () => {
Expand Down Expand Up @@ -370,9 +368,9 @@ describe("a workspace", () => {
await ws.fromProject(project);
let doc = await ws.openDocument({ fileName: "program.cs", textEditor: editorZero, content: "content override" });
expect(doc).not.to.be.null;
doc.getContent().should.be.equal("content override");
doc.currentEditor().should.not.be.null;
doc.currentEditor().id().should.be.equal("0");
editorZero.content.should.be.equal(doc.getContent());
expect(doc.getContent()).to.equal("content override");
expect(doc.currentEditor()).not.to.be.null;
expect(doc.currentEditor().id()).to.equal("0");
expect(editorZero.content).to.equal(doc.getContent());
});
});
16 changes: 8 additions & 8 deletions src/microsoft-trydotnet/test/session.creationapi.specs.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import * as chai from "chai";
import * as chaiAsPromised from "chai-as-promised";

import { expect, use } from "chai";
import chaiAsPromised from "chai-as-promised";
import { Configuration, createSessionWithProjectAndOpenDocument } from "../src/index";
import { buildSimpleIFrameDom, getEditorIFrame } from "./domUtilities";
import { notifyEditorReady, registerForOpeDocument, registerForOpenProject } from "./messagingMocks";
import * as polyglotNotebooks from "@microsoft/polyglot-notebooks";
import { areSameFile } from "../src/documentId";

chai.use(chaiAsPromised);
chai.should();
use(chaiAsPromised);

describe("a user", () => {
let configuration: Configuration;
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("a user", () => {
"program.cs");

const iframeUrl = new URL(editorIFrame.getAttribute("src")!);
iframeUrl.searchParams.get("correlationContext").should.equal("0123456789abcdef0123456789abcdef");
expect(iframeUrl.searchParams.get("correlationContext")).to.equal("0123456789abcdef0123456789abcdef");

registerForOpenProject(configuration, editorIFrame, dom.window, (files) => {
return files.map(f => {
Expand All @@ -60,7 +60,7 @@ describe("a user", () => {

notifyEditorReady(configuration, dom.window);
const session = await awaitableSession;
session.should.not.be.null;
expect(session).not.to.be.null;
});

it("can create a session with initial project", async () => {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe("a user", () => {

notifyEditorReady(configuration, dom.window);
let session = await awaitableSession;
session.should.not.be.null;
expect(session).not.to.be.null;
});

it("can create a session with initial project with regions", async () => {
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("a user", () => {
notifyEditorReady(configuration, dom.window);

let session = await awaitableSession;
session.should.not.be.null;
expect(session).not.to.be.null;
});
});

Expand Down
Loading