From 79f4a4cf75aef44ab059330e69e9adf8088d3d4a Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 15 Nov 2021 22:37:42 +0000 Subject: [PATCH 1/3] Expose the TypeScript object inside the ts worker --- src/typescript/tsWorker.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/typescript/tsWorker.ts b/src/typescript/tsWorker.ts index 3cf342a6..b4b7c1c1 100644 --- a/src/typescript/tsWorker.ts +++ b/src/typescript/tsWorker.ts @@ -494,3 +494,6 @@ export function create(ctx: worker.IWorkerContext, createData: ICreateData): Typ return new TSWorkerClass(ctx, createData); } + +/** Allows for clients to have access to the same version of TypeScript that the worker uses */ +export const typescript = ts; From 892c164a7b912bc98ab180170d5e0b8db60c0bf3 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Tue, 16 Nov 2021 00:30:33 +0000 Subject: [PATCH 2/3] Update tsWorker.ts --- src/typescript/tsWorker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typescript/tsWorker.ts b/src/typescript/tsWorker.ts index b4b7c1c1..14f86b79 100644 --- a/src/typescript/tsWorker.ts +++ b/src/typescript/tsWorker.ts @@ -496,4 +496,4 @@ export function create(ctx: worker.IWorkerContext, createData: ICreateData): Typ } /** Allows for clients to have access to the same version of TypeScript that the worker uses */ -export const typescript = ts; +globalThis.ts = ts; From 8971aa0cb847eb329e7631f59fbeebd55f7fd1fe Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 16 Nov 2021 09:49:19 +0100 Subject: [PATCH 3/3] Check that `ts` is exposed as a global on the typescript worker --- test/smoke/runner.js | 3 +++ test/smoke/smoke.test.js | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/test/smoke/runner.js b/test/smoke/runner.js index 2b72d74f..bcdf713f 100644 --- a/test/smoke/runner.js +++ b/test/smoke/runner.js @@ -35,6 +35,9 @@ yaserver }); async function runTests() { + // uncomment to shortcircuit and run a specific combo + // await runTest('webpack', 'chromium'); return; + for (const type of ['amd', 'webpack']) { await runTest(type, 'chromium'); await runTest(type, 'firefox'); diff --git a/test/smoke/smoke.test.js b/test/smoke/smoke.test.js index 0dbccacf..a2f48a72 100644 --- a/test/smoke/smoke.test.js +++ b/test/smoke/smoke.test.js @@ -64,10 +64,6 @@ afterEach(async () => { }); describe(`Smoke Test '${TESTS_TYPE}'`, () => { - it('`monacoAPI` is exposed as global', async () => { - assert.strictEqual(await page.evaluate(`typeof monacoAPI`), 'object'); - }); - /** * @param {string} text * @param {string} language @@ -105,6 +101,10 @@ describe(`Smoke Test '${TESTS_TYPE}'`, () => { await page.evaluate(`window.ed.focus();`); } + it('`monacoAPI` is exposed as global', async () => { + assert.strictEqual(await page.evaluate(`typeof monacoAPI`), 'object'); + }); + it('should be able to create plaintext editor', async () => { await createEditor('hello world', 'plaintext'); @@ -162,6 +162,16 @@ describe(`Smoke Test '${TESTS_TYPE}'`, () => { // check that a suggestion item for `addEventListener` appears, which indicates that the language service is up and running await page.waitForSelector(`text=addEventListener`); + + // find the TypeScript worker + const tsWorker = page.workers().find((worker) => { + const url = worker.url(); + return /ts\.worker\.js$/.test(url) || /workerMain.js#typescript$/.test(url); + }); + assert.ok(!!tsWorker); + + // check that the TypeScript worker exposes `ts` as a global + assert.strictEqual(await tsWorker.evaluate(`typeof ts`), 'object'); }); });