Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/testVisualizationRunnerSTest.ts
13383 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import { enableHotReload, hotRequire } from '@hediet/node-reload';
6
import path from 'path';
7
import { IDebugValueEditorGlobals, IPlaygroundRunnerGlobals } from '../src/util/common/debugValueEditorGlobals';
8
9
enableHotReload({ loggingEnabled: true });
10
11
12
/** See {@link file://./../.vscode/extensions/visualization-runner/README.md}, this is for stests and jsx tree visualization */
13
14
function run(args: { fileName: string; path: string }) {
15
console.log('> Running test: ' + args.path);
16
setTestFile(args.fileName);
17
setTest(args.path);
18
runCurrentTest();
19
}
20
21
const g = globalThis as unknown as IDebugValueEditorGlobals & IPlaygroundRunnerGlobals;
22
g.$$playgroundRunner_data = { currentPath: [] };
23
24
25
g.$$debugValueEditor_run = (...args) => { setTimeout(() => run(...args), 0); };
26
(g.$$debugValueEditor_debugChannels ?? (g.$$debugValueEditor_debugChannels = {}))['run'] = host => ({
27
handleRequest: (args) => { setTimeout(() => run(args as any), 0); }
28
});
29
30
let runnerFn: (typeof import('./testVisualizationRunnerSTestRunner'))['run'] | undefined = undefined;
31
32
let hotRequireDisposable: any;
33
let currentFileName: string | undefined = undefined;
34
function setTestFile(fileName: string) {
35
if (currentFileName === fileName) {
36
return;
37
}
38
currentFileName = fileName;
39
if (hotRequireDisposable) { hotRequireDisposable.dispose(); }
40
let isFirst = true;
41
hotRequireDisposable = hotRequire(module, './testVisualizationRunnerSTestRunner.ts', (cur: typeof import('./testVisualizationRunnerSTestRunner')) => {
42
runnerFn = cur.run;
43
44
if (isFirst) {
45
console.log('> Loading tests');
46
isFirst = false;
47
} else {
48
console.log('> Running test: ' + currentFullName);
49
runCurrentTest();
50
}
51
});
52
}
53
54
55
let currentFullName: string = '';
56
function setTest(path: string) {
57
currentFullName = path;
58
g.$$playgroundRunner_data.currentPath = [path];
59
}
60
setTest('');
61
62
async function runCurrentTest() {
63
const normalizedFileName = path.join(__dirname, path.relative(__dirname, currentFileName!));
64
if (!runnerFn) {
65
console.error('Runner not loaded yet');
66
} else {
67
runnerFn(normalizedFileName, currentFullName);
68
}
69
}
70
71
console.log('> Playground runner ready.');
72
73