-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(perf) simple performance tests (#819)
part of #676
- Loading branch information
1 parent
c3468e3
commit fe74fc9
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/language-server/test/plugins/typescript/testfiles/performance.svelte
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,30 @@ | ||
<script lang="ts"> | ||
function aFunction(param: string) { | ||
param += 1; // should error | ||
const foo = subFunction(); | ||
function subFunction() { | ||
return param ? 1 : 2; | ||
} | ||
} | ||
function action(node: HTMLElement) { | ||
aFunction(true); // should error | ||
const foo = 'bar'; | ||
} | ||
</script> | ||
|
||
<div use:action> | ||
<p>lorem ipsum</p> | ||
<slot /> | ||
</div> | ||
|
||
<NonExistentComponent | ||
propA={1} | ||
on:event={(evt) => { | ||
const result = evt.detail ? aFunction(false) : aFunction('right'); | ||
result; | ||
}} | ||
> | ||
<p>Inner Content</p> | ||
</NonExistentComponent> |
46 changes: 46 additions & 0 deletions
46
packages/language-server/test/plugins/typescript/typescript-performance.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,46 @@ | ||
import * as path from 'path'; | ||
import { performance } from 'perf_hooks'; | ||
import ts from 'typescript'; | ||
import { Position, Range } from 'vscode-languageserver'; | ||
import { Document, DocumentManager } from '../../../src/lib/documents'; | ||
import { LSConfigManager } from '../../../src/ls-config'; | ||
import { TypeScriptPlugin } from '../../../src/plugins'; | ||
import { pathToUrl } from '../../../src/utils'; | ||
|
||
describe('TypeScript Plugin Performance Tests', () => { | ||
function setup(filename: string) { | ||
const docManager = new DocumentManager(() => document); | ||
const testDir = path.join(__dirname, 'testfiles'); | ||
const filePath = path.join(testDir, filename); | ||
const uri = pathToUrl(filePath); | ||
const document = new Document(uri, ts.sys.readFile(filePath) || ''); | ||
const pluginManager = new LSConfigManager(); | ||
const plugin = new TypeScriptPlugin(docManager, pluginManager, [pathToUrl(testDir)]); | ||
docManager.openDocument({ uri, text: document.getText() }); | ||
const updateDocument = (newText: string) => | ||
docManager.updateDocument({ uri, version: 1 }, [ | ||
{ range: Range.create(Position.create(9, 0), Position.create(9, 0)), text: newText } | ||
]); | ||
return { plugin, document, updateDocument }; | ||
} | ||
|
||
it('should be fast enough', async () => { | ||
const { document, plugin, updateDocument } = setup('performance'); | ||
|
||
const start = performance.now(); | ||
for (let i = 0; i < 1000; i++) { | ||
await plugin.doHover(document, Position.create(1, 15)); | ||
await plugin.getDiagnostics(document); | ||
await plugin.findReferences(document, Position.create(1, 15), { | ||
includeDeclaration: true | ||
}); | ||
await plugin.getDocumentSymbols(document); | ||
await plugin.getSemanticTokens(document); | ||
await plugin.prepareRename(document, Position.create(1, 15)); | ||
updateDocument('function asd() {}\n'); | ||
} | ||
const end = performance.now(); | ||
|
||
console.log(`Performance test took ${end - start}ms`); | ||
}).timeout(10000); | ||
}); |