소스 검색

Merge pull request #2770 from microsoft/expose_ts

Expose the TypeScript object inside the ts worker
Alexandru Dima 3 년 전
부모
커밋
d06ca7bfec
3개의 변경된 파일20개의 추가작업 그리고 4개의 파일을 삭제
  1. 3 0
      src/typescript/tsWorker.ts
  2. 3 0
      test/smoke/runner.js
  3. 14 4
      test/smoke/smoke.test.js

+ 3 - 0
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 */
+globalThis.ts = ts;

+ 3 - 0
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');

+ 14 - 4
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');
 	});
 });