-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce smoke test for TS Plugin + Loose Mode (#807)
* start building out smoke test * test that basic loose mode diagnostic shows up
- Loading branch information
Showing
2 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/vscode/__tests__/ts-plugin-tests/smoketest-ember-app-loose-and-gts.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { | ||
commands, | ||
languages, | ||
ViewColumn, | ||
window, | ||
Uri, | ||
Range, | ||
Position, | ||
CodeAction, | ||
workspace, | ||
TextEditor, | ||
} from 'vscode'; | ||
import * as path from 'path'; | ||
import { describe, afterEach, test } from 'mocha'; | ||
import { expect } from 'expect'; | ||
import { waitUntil } from '../helpers/async'; | ||
|
||
describe('Smoke test: Loose Mode + GTS with TS Plugin Mode', () => { | ||
const rootDir = path.resolve(__dirname, '../../../__fixtures__/ember-app-loose-and-gts'); | ||
|
||
afterEach(async () => { | ||
while (window.activeTextEditor) { | ||
await commands.executeCommand('workbench.action.files.revert'); | ||
await commands.executeCommand('workbench.action.closeActiveEditor'); | ||
} | ||
}); | ||
|
||
describe.only('loose mode aka ts + hbs two-file components', () => { | ||
describe('diagnostics', () => { | ||
test('adds missing args from template into Args type', async () => { | ||
let scriptURI = Uri.file(`${rootDir}/app/components/colocated-layout-with-errors.hbs`); | ||
|
||
// Open the script and the template | ||
let scriptEditor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One }); | ||
|
||
// Wait for a diagnostic to appear in the template | ||
await waitUntil(() => languages.getDiagnostics(scriptURI).length); | ||
|
||
expect(languages.getDiagnostics(scriptURI)).toMatchObject([ | ||
{ | ||
message: | ||
"Property 'messageeee' does not exist on type 'ColocatedLayoutComponent'. Did you mean 'message'?", | ||
source: 'ts-plugin', | ||
code: 2551, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
* It takes a little while for the TS Plugin to fully activate, and unfortunately | ||
* VSCode won't automatically re-trigger/re-calculate diagnostics for a file after | ||
* a TS Plugin kicks in, so we need some way to know that the TS Plugin is activated | ||
* before we edit the file. | ||
* | ||
* To accomplish this, this function inserts invalid TS into the .gts file and waits | ||
* for diagnostics to show up. | ||
*/ | ||
async function hackishlyWaitForTypescriptPluginToActivate( | ||
scriptEditor: TextEditor, | ||
scriptURI: Uri, | ||
): Promise<void> { | ||
let invalidAssignment = 'let s: string = 123;'; | ||
await scriptEditor.edit((edit) => { | ||
edit.insert(new Position(0, 0), invalidAssignment); | ||
}); | ||
|
||
let numSpacesAdded = 0; | ||
const startTime = Date.now(); | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
await scriptEditor.edit((edit) => { | ||
edit.insert(new Position(0, 0), ' '); | ||
}); | ||
numSpacesAdded++; | ||
|
||
if (languages.getDiagnostics(scriptURI).length) { | ||
break; | ||
} | ||
|
||
if (Date.now() - startTime > 5000) { | ||
throw new Error( | ||
'Timed out waiting for TS Plugin to activate (i.e. waiting for diagnostics to show up)', | ||
); | ||
} | ||
|
||
// We'd love to wait for a smaller increment than 1000 but the editor | ||
// debounces before triggering diagnostics so we need a large enough time. | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
} | ||
|
||
// Remove our invalid assignment | ||
await scriptEditor.edit((edit) => { | ||
edit.replace(new Range(0, 0, 0, invalidAssignment.length + numSpacesAdded), ''); | ||
}); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
if (languages.getDiagnostics(scriptURI).length) { | ||
throw new Error('Diagnostics still showing up after removing invalid assignment'); | ||
} | ||
} |