Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ export const watchLocal = task({
dependencies: [localize, watchTsc, watchTsserver, watchServices, lssl, watchOtherOutputs, dts, watchSrc],
});

const runtestsDeps = [tests, generateLibs].concat(cmdLineOptions.typecheck ? [dts] : []);
const runtestsDeps = [tests, generateLibs, generateTypesMap].concat(cmdLineOptions.typecheck ? [dts] : []);

export const runTests = task({
name: "runtests",
Expand Down
86 changes: 9 additions & 77 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import * as vpath from "./_namespaces/vpath.js";
import { LoggerWithInMemoryLogs } from "./tsserverLogger.js";

import ArrayOrSingle = FourSlashInterface.ArrayOrSingle;
import {
harnessSessionLibLocation,
harnessTypingInstallerCacheLocation,
} from "./harnessLanguageService.js";
import { harnessTypingInstallerCacheLocation } from "./harnessLanguageService.js";
import { ensureWatchablePath } from "./watchUtils.js";

export const enum FourSlashTestType {
Expand Down Expand Up @@ -105,7 +102,7 @@ const enum MetadataOptionNames {
const fileMetadataNames = [MetadataOptionNames.fileName, MetadataOptionNames.emitThisFile, MetadataOptionNames.resolveReference, MetadataOptionNames.symlink];

function convertGlobalOptionsToCompilerOptions(globalOptions: Harness.TestCaseParser.CompilerSettings): ts.CompilerOptions {
const settings: ts.CompilerOptions = { target: ts.ScriptTarget.ES5, newLine: ts.NewLineKind.CarriageReturnLineFeed };
const settings: ts.CompilerOptions = { ...ts.getDefaultCompilerOptions(), jsx: undefined, newLine: ts.NewLineKind.CarriageReturnLineFeed };
Harness.Compiler.setCompilerOptionsFromHarnessSetting(globalOptions, settings);
return settings;
}
Expand Down Expand Up @@ -367,11 +364,6 @@ export class TestState {
}
}

const libName = (name: string) =>
this.testType !== FourSlashTestType.Server ?
name :
`${harnessSessionLibLocation}/${name}`;

let configParseResult: ts.ParsedCommandLine | undefined;
if (configFileName) {
const baseDir = ts.normalizePath(ts.getDirectoryPath(configFileName));
Expand Down Expand Up @@ -422,24 +414,6 @@ export class TestState {
const importedFilePath = this.basePath + "/" + importedFile.fileName;
this.addMatchedInputFile(importedFilePath, exts);
});

this.languageServiceAdapterHost.addScript(
libName(Harness.Compiler.defaultLibFileName),
Harness.Compiler.getDefaultLibrarySourceFile()!.text,
/*isRootFile*/ false,
);

compilationOptions.lib?.forEach(fileName => {
const libFile = Harness.Compiler.getDefaultLibrarySourceFile(fileName);
ts.Debug.assertIsDefined(libFile, `Could not find lib file '${fileName}'`);
if (libFile) {
this.languageServiceAdapterHost.addScript(
libName(fileName),
libFile.text,
/*isRootFile*/ false,
);
}
});
}
else {
// resolveReference file-option is not specified then do not resolve any files and include all inputFiles
Expand All @@ -452,24 +426,6 @@ export class TestState {
this.languageServiceAdapterHost.addScript(fileName, file, isRootFile);
}
});

if (!compilationOptions.noLib) {
const seen = new Set<string>();
const addSourceFile = (fileName: string) => {
if (seen.has(fileName)) return;
seen.add(fileName);
const libFile = Harness.Compiler.getDefaultLibrarySourceFile(fileName);
ts.Debug.assertIsDefined(libFile, `Could not find lib file '${fileName}'`);
this.languageServiceAdapterHost.addScript(libName(fileName), libFile.text, /*isRootFile*/ false);
if (!ts.some(libFile.libReferenceDirectives)) return;
for (const directive of libFile.libReferenceDirectives) {
addSourceFile(`lib.${directive.fileName}.d.ts`);
}
};

addSourceFile(Harness.Compiler.defaultLibFileName);
compilationOptions.lib?.forEach(addSourceFile);
}
}

for (const file of testData.files) {
Expand Down Expand Up @@ -557,7 +513,13 @@ export class TestState {
}
private tryGetFileContent(fileName: string): string | undefined {
const script = this.languageServiceAdapterHost.getScriptInfo(fileName);
return script && script.content;
if (script) return script.content;
try {
return this.languageServiceAdapterHost.vfs.readFileSync(fileName, "utf8");
}
catch {
return undefined;
}
}

// Entry points from fourslash.ts
Expand Down Expand Up @@ -4870,18 +4832,6 @@ function parseTestData(basePath: string, contents: string, fileName: string): Fo
}
}

// @Filename is the only directive that can be used in a test that contains tsconfig.json file.
const config = ts.find(files, isConfig);
if (config) {
let directive = getNonFileNameOptionInFileList(files);
if (!directive) {
directive = getNonFileNameOptionInObject(globalOptions);
}
if (directive) {
throw Error(`It is not allowed to use ${config.fileName} along with directive '${directive}'`);
}
}

return {
markerPositions,
markers,
Expand All @@ -4896,24 +4846,6 @@ function isConfig(file: FourSlashFile): boolean {
return Harness.getConfigNameFromFileName(file.fileName) !== undefined;
}

function getNonFileNameOptionInFileList(files: FourSlashFile[]): string | undefined {
return ts.forEach(files, f => getNonFileNameOptionInObject(f.fileOptions));
}

function getNonFileNameOptionInObject(optionObject: { [s: string]: string; }): string | undefined {
for (const option in optionObject) {
switch (option) {
case MetadataOptionNames.fileName:
case MetadataOptionNames.baselineFile:
case MetadataOptionNames.emitThisFile:
break;
default:
return option;
}
}
return undefined;
}

const enum State {
none,
inSlashStarMarker,
Expand Down
54 changes: 0 additions & 54 deletions src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,48 +229,6 @@ export namespace Compiler {
return result;
}

export const defaultLibFileName = "lib.d.ts";
export const es2015DefaultLibFileName = "lib.es2015.d.ts";

// Cache of lib files from "built/local"
export let libFileNameSourceFileMap: Map<string, { file: ts.SourceFile; stringified: string; }> | undefined;

export function getDefaultLibrarySourceFile(fileName: string = defaultLibFileName): ts.SourceFile | undefined {
if (!isDefaultLibraryFile(fileName)) {
return undefined;
}

if (!libFileNameSourceFileMap) {
const file = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts")!, /*languageVersion*/ ts.ScriptTarget.Latest);
libFileNameSourceFileMap = new Map(Object.entries({
[defaultLibFileName]: { file, stringified: JSON.stringify(file.text) },
}));
}

let sourceFile = libFileNameSourceFileMap.get(fileName);
if (!sourceFile) {
const file = createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName)!, ts.ScriptTarget.Latest);
sourceFile = { file, stringified: JSON.stringify(file.text) };
libFileNameSourceFileMap.set(fileName, sourceFile);
}
return sourceFile.file;
}

export function getDefaultLibFileName(options: ts.CompilerOptions): string {
switch (ts.getEmitScriptTarget(options)) {
case ts.ScriptTarget.ESNext:
case ts.ScriptTarget.ES2017:
return "lib.es2017.d.ts";
case ts.ScriptTarget.ES2016:
return "lib.es2016.d.ts";
case ts.ScriptTarget.ES2015:
return es2015DefaultLibFileName;

default:
return defaultLibFileName;
}
}

// Cache these between executions so we don't have to re-parse them for every test
export const fourslashFileName = "fourslash.ts";
export let fourslashSourceFile: ts.SourceFile;
Expand All @@ -281,7 +239,6 @@ export namespace Compiler {

interface HarnessOptions {
useCaseSensitiveFileNames?: boolean;
includeBuiltFile?: string;
baselineFile?: string;
libFiles?: string;
noTypesAndSymbols?: boolean;
Expand All @@ -293,7 +250,6 @@ export namespace Compiler {
{ name: "allowNonTsExtensions", type: "boolean", defaultValueDescription: false },
{ name: "useCaseSensitiveFileNames", type: "boolean", defaultValueDescription: false },
{ name: "baselineFile", type: "string" },
{ name: "includeBuiltFile", type: "string" },
{ name: "fileName", type: "string" },
{ name: "libFiles", type: "string" },
{ name: "noErrorTruncation", type: "boolean", defaultValueDescription: false },
Expand Down Expand Up @@ -412,19 +368,9 @@ export namespace Compiler {
.map(file => options.configFile ? ts.getNormalizedAbsolutePath(file.unitName, currentDirectory) : file.unitName)
.filter(fileName => !ts.fileExtensionIs(fileName, ts.Extension.Json));

// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
// Treat them as library files, so include them in build, but not in baselines.
if (options.includeBuiltFile) {
programFileNames.push(vpath.combine(vfs.builtFolder, options.includeBuiltFile));
}

// Files from tests\lib that are requested by "@libFiles"
if (options.libFiles) {
for (const fileName of options.libFiles.split(",")) {
if (fileName === "lib.d.ts" && !options.noLib) {
// Hack from Corsa.
continue;
}
programFileNames.push(vpath.combine(vfs.testLibFolder, fileName));
}
}
Expand Down
Loading
Loading