Path: blob/main/extensions/copilot/test/testVisualizationRunnerSTest.ts
13383 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import { enableHotReload, hotRequire } from '@hediet/node-reload';5import path from 'path';6import { IDebugValueEditorGlobals, IPlaygroundRunnerGlobals } from '../src/util/common/debugValueEditorGlobals';78enableHotReload({ loggingEnabled: true });91011/** See {@link file://./../.vscode/extensions/visualization-runner/README.md}, this is for stests and jsx tree visualization */1213function run(args: { fileName: string; path: string }) {14console.log('> Running test: ' + args.path);15setTestFile(args.fileName);16setTest(args.path);17runCurrentTest();18}1920const g = globalThis as unknown as IDebugValueEditorGlobals & IPlaygroundRunnerGlobals;21g.$$playgroundRunner_data = { currentPath: [] };222324g.$$debugValueEditor_run = (...args) => { setTimeout(() => run(...args), 0); };25(g.$$debugValueEditor_debugChannels ?? (g.$$debugValueEditor_debugChannels = {}))['run'] = host => ({26handleRequest: (args) => { setTimeout(() => run(args as any), 0); }27});2829let runnerFn: (typeof import('./testVisualizationRunnerSTestRunner'))['run'] | undefined = undefined;3031let hotRequireDisposable: any;32let currentFileName: string | undefined = undefined;33function setTestFile(fileName: string) {34if (currentFileName === fileName) {35return;36}37currentFileName = fileName;38if (hotRequireDisposable) { hotRequireDisposable.dispose(); }39let isFirst = true;40hotRequireDisposable = hotRequire(module, './testVisualizationRunnerSTestRunner.ts', (cur: typeof import('./testVisualizationRunnerSTestRunner')) => {41runnerFn = cur.run;4243if (isFirst) {44console.log('> Loading tests');45isFirst = false;46} else {47console.log('> Running test: ' + currentFullName);48runCurrentTest();49}50});51}525354let currentFullName: string = '';55function setTest(path: string) {56currentFullName = path;57g.$$playgroundRunner_data.currentPath = [path];58}59setTest('');6061async function runCurrentTest() {62const normalizedFileName = path.join(__dirname, path.relative(__dirname, currentFileName!));63if (!runnerFn) {64console.error('Runner not loaded yet');65} else {66runnerFn(normalizedFileName, currentFullName);67}68}6970console.log('> Playground runner ready.');717273