-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add full file evaluation mode (#61)
- Loading branch information
1 parent
e224a88
commit 9b72080
Showing
26 changed files
with
596 additions
and
104 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
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
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
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
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
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,70 @@ | ||
/** | ||
* Copyright (C) Daniel Kuschny (Danielku15) and contributors. | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import type { Event, LogLevel, LogOutputChannel, ViewColumn } from 'vscode'; | ||
|
||
export class ConsoleOuputChannel implements LogOutputChannel { | ||
constructor(private inner: LogOutputChannel) {} | ||
|
||
get logLevel(): LogLevel { | ||
return this.inner.logLevel; | ||
} | ||
|
||
get onDidChangeLogLevel(): Event<LogLevel> { | ||
return this.inner.onDidChangeLogLevel; | ||
} | ||
trace(message: string, ...args: any[]): void { | ||
this.inner.trace(message, ...args); | ||
console.trace(`[Mocha VS Code] ${message}`, ...args); | ||
} | ||
debug(message: string, ...args: any[]): void { | ||
this.inner.debug(message, ...args); | ||
console.debug(`[Mocha VS Code] ${message}`, ...args); | ||
} | ||
info(message: string, ...args: any[]): void { | ||
this.inner.info(message, ...args); | ||
console.info(`[Mocha VS Code] ${message}`, ...args); | ||
} | ||
warn(message: string, ...args: any[]): void { | ||
this.inner.warn(message, ...args); | ||
console.warn(`[Mocha VS Code] ${message}`, ...args); | ||
} | ||
error(error: string | Error, ...args: any[]): void { | ||
this.inner.error(error, ...args); | ||
console.error(`[Mocha VS Code] ${error}`, ...args); | ||
} | ||
get name(): string { | ||
return this.inner.name; | ||
} | ||
append(value: string): void { | ||
this.inner.append(value); | ||
} | ||
appendLine(value: string): void { | ||
this.inner.appendLine(value); | ||
} | ||
replace(value: string): void { | ||
this.inner.replace(value); | ||
} | ||
clear(): void { | ||
this.inner.clear(); | ||
} | ||
show(columnOrPreserveFocus?: ViewColumn | boolean, preserveFocus?: boolean): void { | ||
if (typeof columnOrPreserveFocus === 'boolean') { | ||
this.inner.show(columnOrPreserveFocus); | ||
} else { | ||
this.inner.show(columnOrPreserveFocus, preserveFocus); | ||
} | ||
} | ||
hide(): void { | ||
this.inner.hide(); | ||
} | ||
dispose(): void { | ||
this.inner.dispose(); | ||
} | ||
} |
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
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
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,72 @@ | ||
/** | ||
* Copyright (C) Daniel Kuschny (Danielku15) and contributors. | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import { TraceMap } from '@jridgewell/trace-mapping'; | ||
import { build as esbuildBuild } from 'esbuild'; | ||
import { createRequire } from 'module'; | ||
import * as vm from 'vm'; | ||
import * as vscode from 'vscode'; | ||
import { ConfigValue } from '../configValue'; | ||
import { isEsm, isTypeScript } from '../constants'; | ||
import { TsConfigStore } from '../tsconfig-store'; | ||
import { EvaluationTestDiscoverer } from './evaluate'; | ||
import { IExtensionSettings } from './types'; | ||
|
||
export class FullEvaluationTestDiscoverer extends EvaluationTestDiscoverer { | ||
constructor( | ||
logChannel: vscode.LogOutputChannel | undefined, | ||
settings: ConfigValue<IExtensionSettings>, | ||
tsconfigStore: TsConfigStore, | ||
) { | ||
super(logChannel, settings, tsconfigStore); | ||
} | ||
|
||
protected evaluate(contextObj: vm.Context, filePath: string, code: string) { | ||
contextObj['require'] = createRequire(filePath); | ||
return super.evaluate(contextObj, filePath, code); | ||
} | ||
|
||
override async transpileCode( | ||
filePath: string, | ||
code: string, | ||
): Promise<[string, TraceMap | undefined]> { | ||
let sourceMap: TraceMap | undefined; | ||
const needsTranspile = isTypeScript(filePath) || isEsm(filePath, code); | ||
|
||
if (needsTranspile) { | ||
const result = await esbuildBuild({ | ||
...this.esbuildCommonOptions(filePath), | ||
entryPoints: [filePath], | ||
bundle: true, | ||
sourcemap: 'external', // need source map for correct test positions | ||
write: false, | ||
outfile: 'tests.js', | ||
}); | ||
|
||
const jsFile = result.outputFiles.find((f) => f.path.endsWith('.js')); | ||
const mapFile = result.outputFiles.find((f) => f.path.endsWith('.js.map')); | ||
|
||
if (jsFile && mapFile) { | ||
code = jsFile.text; | ||
try { | ||
sourceMap = new TraceMap(mapFile.text, filePath); | ||
} catch (e) { | ||
this.logChannel?.error('Error parsing source map of TypeScript output', e); | ||
} | ||
} | ||
} | ||
|
||
return [code, sourceMap]; | ||
} | ||
|
||
protected buildDynamicModules(): Map<string, Set<string>> { | ||
// no dynamic modules, only real ones. | ||
return new Map<string, Set<string>>(); | ||
} | ||
} |
Oops, something went wrong.