Skip to content

Commit

Permalink
reset and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
machty committed Jan 13, 2025
1 parent a38d00e commit 463b3ff
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "template-imports-app-ts-plugin",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Component from '@glimmer/component';

export interface GreetingSignature {
Args: { target: string };
}

export default class Greeting extends Component<GreetingSignature> {
private message = 'Hello';

<template>
{{this.message}}, {{@target}}!
</template>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import '@glint/environment-ember-loose';
import '@glint/environment-ember-template-imports';

import Greeting from './Greeting';

<template>
<Greeting @target="World" />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../../../tsconfig.compileroptions.json",
"glint": {
"environment": ["ember-loose", "ember-template-imports"],
"enableTsPlugin": true
},
"compilerOptions": {
"baseUrl": ".",
"plugins": [{ "name": "@glint/typescript-plugin" }]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
import * as path from 'path';
import { describe, afterEach, test } from 'mocha';
import { expect } from 'expect';
import { waitUntil } from './helpers/async';
import { waitUntil } from '../helpers/async';

describe.skip('Smoke test: Ember', () => {
const rootDir = path.resolve(__dirname, '../../__fixtures__/ember-app');
const rootDir = path.resolve(__dirname, '../../../__fixtures__/ember-app');

afterEach(async () => {
while (window.activeTextEditor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
import * as path from 'path';
import { describe, afterEach, test } from 'mocha';
import { expect } from 'expect';
import { waitUntil } from './helpers/async';
import { waitUntil } from '../helpers/async';

describe('Smoke test: ETI Environment', () => {
const rootDir = path.resolve(__dirname, '../../__fixtures__/template-imports-app');
const rootDir = path.resolve(__dirname, '../../../__fixtures__/template-imports-app');

afterEach(async () => {
while (window.activeTextEditor) {
Expand Down
17 changes: 16 additions & 1 deletion packages/vscode/__tests__/support/launch-from-cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
const packageRoot = path.resolve(dirname, '../../..');
const emptyTempDir = path.join(os.tmpdir(), `user-data-${Math.random()}`);

const testType = process.argv[2];

let testRunner: string;
switch (testType) {
case 'language-server':
testRunner = 'vscode-runner-language-server.js';
break;
case 'ts-plugin':
testRunner = 'vscode-runner-ts-plugin.js';
break;
default:
console.error('Test type must be either "language-server" or "ts-plugin"');
process.exit(1);
}

try {
await runTests({
extensionDevelopmentPath: packageRoot,
extensionTestsPath: path.resolve(dirname, 'vscode-runner.js'),
extensionTestsPath: path.resolve(dirname, testRunner),
launchArgs: [
// Don't show the "hey do you trust this folder?" prompt
'--disable-workspace-trust',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is invoked by VSCode itself when configured to run extension
// tests via the `--extensionTestsPath` flag.

import { run as runShared } from './vscode-runner';

export function run(runner: unknown, callback: (error: unknown, failures?: number) => void): void {
runShared(runner, callback, 'language-server-tests');
}
8 changes: 6 additions & 2 deletions packages/vscode/__tests__/support/vscode-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import * as path from 'node:path';
import * as glob from 'glob';
import Mocha = require('mocha');

export function run(runner: unknown, callback: (error: unknown, failures?: number) => void): void {
export function run(
runner: unknown,
callback: (error: unknown, failures?: number) => void,
testSubfolder: 'language-server-tests' | 'ts-plugin-tests',
): void {
try {
let mocha = new Mocha({ color: true, slow: 3_000, timeout: 30_000 });
let tests = path.resolve(__dirname, '..').replace(/\\/g, '/');

for (let testFile of glob.sync(`${tests}/**/*.test.js`)) {
for (let testFile of glob.sync(`${tests}/${testSubfolder}/**/*.test.js`)) {
if (process.platform === 'win32') {
// Mocha is weird about drive letter casing under Windows
testFile = testFile[0].toLowerCase() + testFile.slice(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import {
commands,
languages,
ViewColumn,
window,
Uri,
Range,
Position,
CodeAction,
workspace,
} from 'vscode';
import * as path from 'path';
import { describe, afterEach, test } from 'mocha';
import { expect } from 'expect';
import { waitUntil } from '../helpers/async';

throw new Error('TS-PLUGIN TESTS DISABLED, WHO IS CALLING ME?');

describe('Smoke test: ETI Environment (TS Plugin Mode)', () => {
const rootDir = path.resolve(__dirname, '../../../__fixtures__/template-imports-app-ts-plugin');

afterEach(async () => {
while (window.activeTextEditor) {
await commands.executeCommand('workbench.action.files.revert');
await commands.executeCommand('workbench.action.closeActiveEditor');
}
});

describe('diagnostics for errors', () => {
test('with a custom extension', async () => {
let scriptURI = Uri.file(`${rootDir}/src/index.gts`);
let scriptEditor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One });

// Ensure we have a clean bill of health
expect(languages.getDiagnostics(scriptURI)).toEqual([]);

// Replace a string with a number
await scriptEditor.edit((edit) => {
edit.replace(new Range(6, 20, 6, 27), '{{123}}');
});

// Wait for the diagnostic to show up
await waitUntil(() => languages.getDiagnostics(scriptURI).length);

// Verify it's what we expect
expect(languages.getDiagnostics(scriptURI)).toMatchObject([
{
message: "Type 'number' is not assignable to type 'string'.",
source: 'glint',
code: 2322,
range: new Range(6, 13, 6, 19),
},
]);
});

describe('codeactions args', () => {
test('adds missing args from template into Args type', async () => {
let scriptURI = Uri.file(`${rootDir}/src/Greeting.gts`);

// Open the script and the template
let scriptEditor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One });

// Ensure neither has any diagnostic messages
expect(languages.getDiagnostics(scriptURI)).toEqual([]);

// Comment out a property in the script that's referenced in the template
await scriptEditor.edit((edit) => {
edit.insert(new Position(10, 4), '{{@undocumentedProperty}} ');
});

// Wait for a diagnostic to appear in the template
await waitUntil(() => languages.getDiagnostics(scriptURI).length);

const fixes = await commands.executeCommand<CodeAction[]>(
'vscode.executeCodeActionProvider',
scriptURI,
new Range(new Position(10, 9), new Position(10, 9)),
);

expect(fixes.length).toBe(4);

const fix = fixes.find((fix) => fix.title === "Declare property 'undocumentedProperty'");

expect(fix).toBeDefined();

// apply the missing arg fix
await workspace.applyEdit(fix!.edit!);

await waitUntil(
() =>
scriptEditor.document.getText().includes('undocumentedProperty: any') &&
languages.getDiagnostics(scriptURI).length === 0,
);
});
});

describe('codeactions locals', () => {
test('add local props to a class', async () => {
let scriptURI = Uri.file(`${rootDir}/src/Greeting.gts`);

// Open the script and the template
let scriptEditor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One });

// Ensure neither has any diagnostic messages
expect(languages.getDiagnostics(scriptURI)).toEqual([]);

await scriptEditor.edit((edit) => {
edit.insert(new Position(10, 4), '{{this.localProp}} ');
});

// Wait for a diagnostic to appear in the template
await waitUntil(() => languages.getDiagnostics(scriptURI).length);

const fixes = await commands.executeCommand<CodeAction[]>(
'vscode.executeCodeActionProvider',
scriptURI,
new Range(new Position(10, 12), new Position(10, 12)),
);

expect(fixes.length).toBe(4);

const fix = fixes.find((fix) => fix.title === "Declare property 'localProp'");

expect(fix).toBeDefined();

// select ignore
await workspace.applyEdit(fix!.edit!);

await waitUntil(
() =>
scriptEditor.document.getText().includes('localProp: any') &&
languages.getDiagnostics(scriptURI).length,
);
});
});
});
});
4 changes: 3 additions & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
],
"scripts": {
"pretest": "yarn build",
"test": "node lib/__tests__/support/launch-from-cli.mjs",
"test": "yarn test-language-server && yarn test-ts-plugin",
"test-language-server": "node lib/__tests__/support/launch-from-cli.mjs language-server",
"test-ts-plugin": "node lib/__tests__/support/launch-from-cli.mjs ts-plugin",
"test:typecheck": "echo 'no standalone typecheck within this project'",
"test:tsc": "echo 'no standalone tsc within this project'",
"build": "yarn compile && yarn bundle",
Expand Down

0 comments on commit 463b3ff

Please sign in to comment.