mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
Fix issues with runtests-browser
This commit is contained in:
@@ -41,7 +41,7 @@ abstract class ExternalCompileRunnerBase extends RunnerBase {
|
||||
const cp = require("child_process");
|
||||
|
||||
it("should build successfully", () => {
|
||||
let cwd = path.join(__dirname, "../../", cls.testDir, directoryName);
|
||||
let cwd = path.join(Harness.IO.getWorkspaceRoot(), cls.testDir, directoryName);
|
||||
const stdio = isWorker ? "pipe" : "inherit";
|
||||
let types: string[];
|
||||
if (fs.existsSync(path.join(cwd, "test.json"))) {
|
||||
@@ -69,7 +69,7 @@ abstract class ExternalCompileRunnerBase extends RunnerBase {
|
||||
const install = cp.spawnSync(`npm`, ["i", "--ignore-scripts"], { cwd, timeout: timeout / 2, shell: true, stdio }); // NPM shouldn't take the entire timeout - if it takes a long time, it should be terminated and we should log the failure
|
||||
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed: ${install.stderr.toString()}`);
|
||||
}
|
||||
const args = [path.join(__dirname, "tsc.js")];
|
||||
const args = [path.join(Harness.IO.getWorkspaceRoot(), "built/local/tsc.js")];
|
||||
if (types) {
|
||||
args.push("--types", types.join(","));
|
||||
}
|
||||
|
||||
@@ -522,6 +522,7 @@ namespace Harness {
|
||||
log(text: string): void;
|
||||
args(): string[];
|
||||
getExecutingFilePath(): string;
|
||||
getWorkspaceRoot(): string;
|
||||
exit(exitCode?: number): void;
|
||||
readDirectory(path: string, extension?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
|
||||
getAccessibleFileSystemEntries(dirname: string): ts.FileSystemEntries;
|
||||
@@ -645,6 +646,7 @@ namespace Harness {
|
||||
log: s => console.log(s),
|
||||
args: () => ts.sys.args,
|
||||
getExecutingFilePath: () => ts.sys.getExecutingFilePath(),
|
||||
getWorkspaceRoot: () => vpath.resolve(__dirname, "../.."),
|
||||
exit: exitCode => ts.sys.exit(exitCode),
|
||||
readDirectory: (path, extension, exclude, include, depth) => ts.sys.readDirectory(path, extension, exclude, include, depth),
|
||||
getAccessibleFileSystemEntries,
|
||||
@@ -676,9 +678,9 @@ namespace Harness {
|
||||
function createBrowserIO(): IO {
|
||||
const serverRoot = new URL("http://localhost:8888/");
|
||||
|
||||
class HttpHeaders extends Map<string, string | string[]> {
|
||||
class HttpHeaders extends core.SortedMap<string, string | string[]> {
|
||||
constructor(template?: Record<string, string | string[]>) {
|
||||
super();
|
||||
super(core.compareStringsCaseInsensitive);
|
||||
if (template) {
|
||||
for (const key in template) {
|
||||
if (ts.hasProperty(template, key)) {
|
||||
@@ -854,9 +856,9 @@ namespace Harness {
|
||||
function send(request: HttpRequestMessage): HttpResponseMessage {
|
||||
const xhr = new XMLHttpRequest();
|
||||
try {
|
||||
xhr.open(request.method, request.url.toString(), /*async*/ false);
|
||||
request.writeRequestHeaders(xhr);
|
||||
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
|
||||
xhr.open(request.method, request.url.toString(), /*async*/ false);
|
||||
xhr.send(request.content && request.content.content);
|
||||
while (xhr.readyState !== 4); // block until ready
|
||||
return HttpResponseMessage.readResponseMessage(xhr);
|
||||
@@ -903,8 +905,7 @@ namespace Harness {
|
||||
|
||||
function directoryExists(path: string): boolean {
|
||||
const response = send(HttpRequestMessage.post(new URL("/api/directoryExists", serverRoot), HttpContent.text(path)));
|
||||
return HttpResponseMessage.hasSuccessStatusCode(response)
|
||||
&& (response.content && response.content.content) === "true";
|
||||
return hasJsonContent(response) && JSON.parse(response.content.content) as boolean;
|
||||
}
|
||||
|
||||
function deleteFile(path: string) {
|
||||
@@ -929,31 +930,22 @@ namespace Harness {
|
||||
}
|
||||
|
||||
const response = send(HttpRequestMessage.post(new URL("/api/listFiles", serverRoot), HttpContent.text(dirname)));
|
||||
return HttpResponseMessage.hasSuccessStatusCode(response)
|
||||
&& response.content
|
||||
&& response.content.headers.get("Content-Type") === "application/json"
|
||||
? JSON.parse(response.content.content)
|
||||
: [];
|
||||
return hasJsonContent(response) ? JSON.parse(response.content.content) : [];
|
||||
}
|
||||
|
||||
function readDirectory(path: string, extension?: string[], exclude?: string[], include?: string[], depth?: number) {
|
||||
const fs = new vfs.FileSystem(!useCaseSensitiveFileNames(), { cwd: path, files: { [path]: { } } });
|
||||
const sys = new fakes.System(fs);
|
||||
for (const file of IO.listFiles(path)) {
|
||||
fs.mkdirpSync(vpath.dirname(file));
|
||||
fs.writeFileSync(file, "");
|
||||
}
|
||||
return sys.readDirectory(path, extension, exclude, include, depth);
|
||||
return ts.matchFiles(path, extension, exclude, include, useCaseSensitiveFileNames(), "", depth, getAccessibleFileSystemEntries);
|
||||
}
|
||||
|
||||
function getAccessibleFileSystemEntries(dirname: string): ts.FileSystemEntries {
|
||||
const fs = new vfs.FileSystem(!useCaseSensitiveFileNames(), { cwd: dirname, files: { [dirname]: {} } });
|
||||
const sys = new fakes.System(fs);
|
||||
for (const file of IO.listFiles(path)) {
|
||||
fs.mkdirpSync(vpath.dirname(file));
|
||||
fs.writeFileSync(file, "");
|
||||
}
|
||||
return sys.getAccessibleFileSystemEntries(dirname);
|
||||
const response = send(HttpRequestMessage.post(new URL("/api/getAccessibleFileSystemEntries", serverRoot), HttpContent.text(dirname)));
|
||||
return hasJsonContent(response) ? JSON.parse(response.content.content) : { files: [], directories: [] };
|
||||
}
|
||||
|
||||
function hasJsonContent(response: HttpResponseMessage): response is HttpResponseMessage & { content: HttpContent } {
|
||||
return HttpResponseMessage.hasSuccessStatusCode(response)
|
||||
&& !!response.content
|
||||
&& /^application\/json(;.*)$/.test("" + response.content.headers.get("Content-Type"));
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -976,7 +968,8 @@ namespace Harness {
|
||||
getExecutingFilePath: () => "",
|
||||
exit: () => {}, // tslint:disable-line no-empty
|
||||
readDirectory,
|
||||
getAccessibleFileSystemEntries
|
||||
getAccessibleFileSystemEntries,
|
||||
getWorkspaceRoot: () => "/"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2003,7 +1996,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
const parentDirectory = IO.directoryName(dirName);
|
||||
if (parentDirectory !== "") {
|
||||
if (parentDirectory !== "" && parentDirectory !== dirName) {
|
||||
createDirectoryStructure(parentDirectory);
|
||||
}
|
||||
IO.createDirectory(dirName);
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace project {
|
||||
}
|
||||
|
||||
const fs = vfs.FileSystem.createFromFileSystem(Harness.IO, /*ignoreCase*/ false);
|
||||
fs.mountSync(vpath.resolve(__dirname, "../../tests"), vpath.combine(vfs.srcFolder, "tests"), vfs.createResolver(Harness.IO));
|
||||
fs.mountSync(vpath.resolve(Harness.IO.getWorkspaceRoot(), "tests"), vpath.combine(vfs.srcFolder, "tests"), vfs.createResolver(Harness.IO));
|
||||
fs.mkdirpSync(vpath.combine(vfs.srcFolder, testCase.projectRoot));
|
||||
fs.chdir(vpath.combine(vfs.srcFolder, testCase.projectRoot));
|
||||
fs.makeReadonly();
|
||||
|
||||
@@ -14,12 +14,11 @@ describe("Public APIs", () => {
|
||||
});
|
||||
|
||||
it("should compile", () => {
|
||||
const testFile: Harness.Compiler.TestFile = {
|
||||
unitName: builtFile,
|
||||
content: fileContent
|
||||
};
|
||||
const inputFiles = [testFile];
|
||||
const result = Harness.Compiler.compileFiles(inputFiles, [], /*harnessSettings*/ undefined, /*options*/ {}, /*currentDirectory*/ undefined);
|
||||
const fs = vfs.FileSystem.createFromFileSystem(Harness.IO, /*ignoreCase*/ false);
|
||||
fs.linkSync(`${vfs.builtFolder}/${fileName}`, `${vfs.srcFolder}/${fileName}`);
|
||||
const sys = new fakes.System(fs);
|
||||
const host = new fakes.CompilerHost(sys);
|
||||
const result = compiler.compileFiles(host, [`${vfs.srcFolder}/${fileName}`], {});
|
||||
assert(!result.diagnostics || !result.diagnostics.length, Harness.Compiler.minimalDiagnosticsToString(result.diagnostics, /*pretty*/ true));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1009,6 +1009,7 @@ namespace vfs {
|
||||
fileExists(path: string): boolean;
|
||||
getFileSize(path: string): number;
|
||||
readFile(path: string): string;
|
||||
getWorkspaceRoot(): string;
|
||||
}
|
||||
|
||||
export function createResolver(host: FileSystemResolverHost): FileSystemResolver {
|
||||
@@ -1244,10 +1245,10 @@ namespace vfs {
|
||||
// This is only to make the PR for this change easier to read. A follow-up PR will
|
||||
// revert this change and accept the new baselines.
|
||||
// See https://github.com/Microsoft/TypeScript/pull/20763#issuecomment-352553264
|
||||
function patchResolver(io: FileSystemResolverHost, resolver: FileSystemResolver): FileSystemResolver {
|
||||
const libFile = vpath.combine(__dirname, "lib.d.ts");
|
||||
const es5File = vpath.combine(__dirname, "lib.es5.d.ts");
|
||||
const stringComparer = io.useCaseSensitiveFileNames() ? vpath.compareCaseSensitive : vpath.compareCaseInsensitive;
|
||||
function patchResolver(host: FileSystemResolverHost, resolver: FileSystemResolver): FileSystemResolver {
|
||||
const libFile = vpath.combine(host.getWorkspaceRoot(), "built/local/lib.d.ts");
|
||||
const es5File = vpath.combine(host.getWorkspaceRoot(), "built/local/lib.es5.d.ts");
|
||||
const stringComparer = host.useCaseSensitiveFileNames() ? vpath.compareCaseSensitive : vpath.compareCaseInsensitive;
|
||||
return {
|
||||
readdirSync: path => resolver.readdirSync(path),
|
||||
statSync: path => resolver.statSync(fixPath(path)),
|
||||
@@ -1273,8 +1274,8 @@ namespace vfs {
|
||||
const resolver = createResolver(host);
|
||||
builtLocalCI = new FileSystem(/*ignoreCase*/ true, {
|
||||
files: {
|
||||
[builtFolder]: new Mount(__dirname, patchResolver(host, resolver)),
|
||||
[testLibFolder]: new Mount(vpath.resolve(__dirname, "../../tests/lib"), resolver),
|
||||
[builtFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "built/local"), patchResolver(host, resolver)),
|
||||
[testLibFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "tests/lib"), resolver),
|
||||
[srcFolder]: {}
|
||||
},
|
||||
cwd: srcFolder,
|
||||
|
||||
Reference in New Issue
Block a user