Skip to content

Commit 45026b1

Browse files
authored
Migrate tests to TS Plugin mode, remove option for old LS mode (#811)
1 parent 130d85f commit 45026b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2328
-4033
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ test-packages/ephemeral
44
.eslintcache
55
*.tsbuildinfo
66
*.js.map
7+
tsserver.log

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"nohoist:comment": "When running extension host in test-packages/ts-plugin-test-app, we need 1. to be able to use workspace TypeScript, and 2. to use a TS Plugin specified as an npm dependency, both which require typescript and the plugin to be present within the same folder's `node_modules` directory.",
1111
"nohoist": [
1212
"ts-plugin-test-app/typescript",
13-
"ts-plugin-test-app/@glint/typescript-plugin"
13+
"ts-plugin-test-app/@glint/tsserver-plugin"
1414
]
1515
},
1616
"scripts": {

packages/core/__tests__/cli/build-watch.test.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
2+
3+
test('maybe reinstate these tests');
4+
5+
/*
6+
Skipping all of this for now. Now that we've offloaded a lot of this logic to Volar
7+
this is an opportunity to rebuild the test suite to not re-test what Volar already
8+
tests.
9+
110
import * as os from 'node:os';
211
312
import { stripIndent } from 'common-tags';
413
import stripAnsi = require('strip-ansi');
5-
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
614
715
import {
816
Project,
@@ -42,7 +50,7 @@ const BUILD_WATCH_TSCONFIG = {
4250
const IS_WINDOWS = os.type() === 'Windows_NT';
4351
const PAUSE_TIME = IS_WINDOWS ? 2_500 : 1_000;
4452
45-
/** Combine `setTimeout` and a `Promise` to defer further work for some time. */
53+
// Combine `setTimeout` and a `Promise` to defer further work for some time.
4654
const pauseForTSBuffering = (): Promise<void> =>
4755
new Promise((resolve) => setTimeout(resolve, PAUSE_TIME));
4856
@@ -546,3 +554,5 @@ describe('CLI: watched build mode typechecking', () => {
546554
});
547555
});
548556
});
557+
558+
*/

packages/core/__tests__/cli/build.test.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
2+
3+
test('maybe reinstate these tests');
4+
5+
/*
6+
Skipping all of this for now. Now that we've offloaded a lot of this logic to Volar
7+
this is an opportunity to rebuild the test suite to not re-test what Volar already
8+
tests.
9+
10+
111
import { existsSync, statSync } from 'fs';
212
313
import { stripIndent } from 'common-tags';
@@ -15,7 +25,7 @@ import {
1525
setupCompositeProject,
1626
} from 'glint-monorepo-test-utils';
1727
18-
describe('CLI: single-pass build mode typechecking', () => {
28+
describe.skip('CLI: single-pass build mode typechecking', () => {
1929
describe('simple projects using `--build`', () => {
2030
let project!: Project;
2131
beforeEach(async () => {
@@ -26,7 +36,7 @@ describe('CLI: single-pass build mode typechecking', () => {
2636
await project.destroy();
2737
});
2838
29-
test('passes a valid basic project', async () => {
39+
test.only('passes a valid basic project', async () => {
3040
let code = stripIndent`
3141
import '@glint/environment-ember-template-imports';
3242
import Component from '@glimmer/component';
@@ -1681,3 +1691,4 @@ describe('CLI: --build --dry', () => {
16811691
});
16821692
});
16831693
});
1694+
*/

packages/core/__tests__/cli/watch.test.ts renamed to packages/core/__tests__/cli/check-watch.test.ts

+96
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,100 @@ describe('CLI: watched typechecking', () => {
288288

289289
await watch.terminate();
290290
});
291+
292+
test('reporting watched diagnostics', async () => {
293+
let code = 'let identifier: string = 123;';
294+
295+
project.setGlintConfig({ environment: 'ember-template-imports' });
296+
project.write('index.gts', code);
297+
298+
let watch = project.checkWatch();
299+
let output = await watch.awaitOutput('Watching for file changes.');
300+
301+
await watch.terminate();
302+
303+
let stripped = stripAnsi(output);
304+
let error = stripped.slice(
305+
stripped.indexOf('index.gts'),
306+
stripped.lastIndexOf(`~~~${os.EOL}`) + 3,
307+
);
308+
309+
expect(output).toMatch('Found 1 error.');
310+
expect(error.replace(/\r/g, '')).toMatchInlineSnapshot(`
311+
"index.gts:1:5 - error TS2322: Type 'number' is not assignable to type 'string'.
312+
313+
1 let identifier: string = 123;let identifier: string = 123;
314+
~~~~~~~~~~"
315+
`);
316+
});
317+
318+
// A number of issues with these tests:
319+
//
320+
// - `.gjs` (untyped) file not yet supported
321+
// - extension-less imports are causing issues specifically with `--watch` even though they work in non-watch mode
322+
// - Discussing/tracking here: https://discord.com/channels/1192759067815464990/1192759067815464993/1258084777618178159
323+
// - (I noticed this after changing other.gjs to other.gts)
324+
describe.skip('external file changes', () => {
325+
beforeEach(() => {
326+
project.setGlintConfig({ environment: 'ember-template-imports' });
327+
project.write(
328+
'index.gts',
329+
stripIndent`
330+
import { foo } from "./other";
331+
console.log(foo - 1);
332+
`,
333+
);
334+
});
335+
336+
test('adding a missing module', async () => {
337+
let watch = project.checkWatch();
338+
let output = await watch.awaitOutput('Watching for file changes.');
339+
340+
expect(output).toMatch('Found 1 error.');
341+
expect(output).toMatch(
342+
"Cannot find module './other' or its corresponding type declarations.",
343+
);
344+
345+
project.write('other.gjs', 'export const foo = 123;');
346+
347+
await watch.awaitOutput('Found 0 errors.');
348+
await watch.terminate();
349+
});
350+
351+
test('changing an imported module', async () => {
352+
project.write('other.gjs', 'export const foo = 123;');
353+
354+
let watch = project.checkWatch();
355+
let output = await watch.awaitOutput('Watching for file changes.');
356+
357+
expect(output).toMatch('Found 0 errors.');
358+
359+
project.write('other.gjs', 'export const foo = "hi";');
360+
output = await watch.awaitOutput('Watching for file changes.');
361+
362+
expect(output).toMatch('Found 1 error.');
363+
expect(output).toMatch('TS2362');
364+
365+
await watch.terminate();
366+
});
367+
368+
test('removing an imported module', async () => {
369+
project.write('other.gjs', 'export const foo = 123;');
370+
371+
let watch = project.checkWatch();
372+
let output = await watch.awaitOutput('Watching for file changes.');
373+
374+
expect(output).toMatch('Found 0 errors.');
375+
376+
project.remove('other.gjs');
377+
output = await watch.awaitOutput('Watching for file changes.');
378+
379+
expect(output).toMatch('Found 1 error.');
380+
expect(output).toMatch(
381+
"Cannot find module './other' or its corresponding type declarations.",
382+
);
383+
384+
await watch.terminate();
385+
});
386+
});
291387
});

packages/core/__tests__/cli/check.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,25 @@ describe('CLI: single-pass typechecking', () => {
407407
"
408408
`);
409409
});
410+
411+
test('reporting one-shot diagnostics', async () => {
412+
let code = 'let identifier: string = 123;';
413+
414+
project.setGlintConfig({ environment: 'ember-template-imports' });
415+
project.write('index.gts', code);
416+
417+
let result = await project.check({ reject: false });
418+
419+
expect(result.exitCode).not.toBe(0);
420+
expect(stripAnsi(result.stdout)).toMatchInlineSnapshot(`
421+
"index.gts:1:5 - error TS2322: Type 'number' is not assignable to type 'string'.
422+
423+
1 let identifier: string = 123;let identifier: string = 123;
424+
~~~~~~~~~~
425+
426+
427+
Found 1 error in index.gts:1
428+
"
429+
`);
430+
});
410431
});

packages/core/__tests__/cli/custom-extensions.test.ts

-135
This file was deleted.

packages/core/__tests__/cli/incremental.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
2+
3+
test('maybe reinstate these tests');
4+
5+
/*
6+
Skipping all of this for now. Now that we've offloaded a lot of this logic to Volar
7+
this is an opportunity to rebuild the test suite to not re-test what Volar already
8+
tests.
9+
110
import { existsSync, statSync, readFileSync } from 'fs';
211
312
import { stripIndent } from 'common-tags';
@@ -166,3 +175,4 @@ describe('CLI: --incremental', () => {
166175
});
167176
});
168177
});
178+
*/

packages/core/__tests__/config/load-config.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ describe('Config: loadConfig', () => {
3232
JSON.stringify({
3333
glint: {
3434
environment: 'kaboom',
35-
checkStandaloneTemplates: false,
3635
},
3736
}),
3837
);
@@ -50,7 +49,6 @@ describe('Config: loadConfig', () => {
5049

5150
expect(config.rootDir).toBe(normalizePath(`${testDir}/deeply`));
5251
expect(config.environment.getConfiguredTemplateTags()).toEqual({ test: {} });
53-
expect(config.checkStandaloneTemplates).toBe(false);
5452
});
5553

5654
test('locates config in package', () => {
@@ -77,7 +75,6 @@ describe('Config: loadConfig', () => {
7775
JSON.stringify({
7876
glint: {
7977
environment: 'kaboom',
80-
checkStandaloneTemplates: false,
8178
},
8279
}),
8380
);
@@ -95,6 +92,5 @@ describe('Config: loadConfig', () => {
9592

9693
expect(config.rootDir).toBe(normalizePath(`${directory}`));
9794
expect(config.environment.getConfiguredTemplateTags()).toEqual({ test: {} });
98-
expect(config.checkStandaloneTemplates).toBe(false);
9995
});
10096
});

0 commit comments

Comments
 (0)