From ee3fe472d7aa1bd8a5e3e07ac1c4965eeac0f25e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 22 Jan 2021 13:23:41 -0800 Subject: [PATCH] Fix broken user and docker tests (#42431) * Add --force to npm install script for user tests * Migrate prettier to docker * Fix vscode Dockerfile * Fix stack space issue in isJSLiteralType * Use --legacy-peer-deps based on npm version * Fix xterm.js Dockerfile --- src/compiler/checker.ts | 3 ++- src/testRunner/externalCompileRunner.ts | 10 +++++++--- tests/cases/docker/prettier/Dockerfile | 13 +++++++++++++ tests/cases/docker/vscode/Dockerfile | 1 + tests/cases/docker/xterm.js/Dockerfile | 4 ++-- tests/cases/user/prettier/test.json | 4 ---- tests/cases/user/prettier/tsconfig.json | 17 ----------------- 7 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 tests/cases/docker/prettier/Dockerfile delete mode 100644 tests/cases/user/prettier/test.json delete mode 100644 tests/cases/user/prettier/tsconfig.json diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index efb46b2efbd..49c45384e6d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14109,7 +14109,8 @@ namespace ts { return some((type as IntersectionType).types, isJSLiteralType); } if (type.flags & TypeFlags.Instantiable) { - return isJSLiteralType(getResolvedBaseConstraint(type)); + const constraint = getResolvedBaseConstraint(type); + return constraint !== type && isJSLiteralType(constraint); } return false; } diff --git a/src/testRunner/externalCompileRunner.ts b/src/testRunner/externalCompileRunner.ts index 4f2cd9e4770..2b3a2ef9957 100644 --- a/src/testRunner/externalCompileRunner.ts +++ b/src/testRunner/externalCompileRunner.ts @@ -68,6 +68,9 @@ namespace Harness { cwd = config.path ? path.join(cwd, config.path) : submoduleDir; } + const npmVersionText = exec("npm", ["--version"], { cwd, stdio: "pipe" })?.trim(); + const npmVersion = npmVersionText ? ts.Version.tryParse(npmVersionText.trim()) : undefined; + const isV7OrLater = !!npmVersion && npmVersion.major >= 7; if (fs.existsSync(path.join(cwd, "package.json"))) { if (fs.existsSync(path.join(cwd, "package-lock.json"))) { fs.unlinkSync(path.join(cwd, "package-lock.json")); @@ -75,24 +78,25 @@ namespace Harness { if (fs.existsSync(path.join(cwd, "node_modules"))) { del.sync(path.join(cwd, "node_modules"), { force: true }); } - exec("npm", ["i", "--ignore-scripts"], { cwd, timeout: timeout / 2 }); // NPM shouldn't take the entire timeout - if it takes a long time, it should be terminated and we should log the failure + exec("npm", ["i", "--ignore-scripts", ...(isV7OrLater ? ["--legacy-peer-deps"] : [])], { cwd, timeout: timeout / 2 }); // NPM shouldn't take the entire timeout - if it takes a long time, it should be terminated and we should log the failure } const args = [path.join(IO.getWorkspaceRoot(), "built/local/tsc.js")]; if (types) { args.push("--types", types.join(",")); // Also actually install those types (for, eg, the js projects which need node) if (types.length) { - exec("npm", ["i", ...types.map(t => `@types/${t}`), "--no-save", "--ignore-scripts"], { cwd: originalCwd, timeout: timeout / 2 }); // NPM shouldn't take the entire timeout - if it takes a long time, it should be terminated and we should log the failure + exec("npm", ["i", ...types.map(t => `@types/${t}`), "--no-save", "--ignore-scripts", ...(isV7OrLater ? ["--legacy-peer-deps"] : [])], { cwd: originalCwd, timeout: timeout / 2 }); // NPM shouldn't take the entire timeout - if it takes a long time, it should be terminated and we should log the failure } } args.push("--noEmit"); Baseline.runBaseline(`${cls.kind()}/${directoryName}.log`, cls.report(cp.spawnSync(`node`, args, { cwd, timeout, shell: true }), cwd)); - function exec(command: string, args: string[], options: { cwd: string, timeout?: number }): void { + function exec(command: string, args: string[], options: { cwd: string, timeout?: number, stdio?: import("child_process").StdioOptions }): string | undefined { const res = cp.spawnSync(isWorker ? `${command} 2>&1` : command, args, { shell: true, stdio, ...options }); if (res.status !== 0) { throw new Error(`${command} ${args.join(" ")} for ${directoryName} failed: ${res.stdout && res.stdout.toString()}`); } + return options.stdio === "pipe" ? res.stdout.toString("utf8") : undefined; } }); }); diff --git a/tests/cases/docker/prettier/Dockerfile b/tests/cases/docker/prettier/Dockerfile new file mode 100644 index 00000000000..750e5ba3b2a --- /dev/null +++ b/tests/cases/docker/prettier/Dockerfile @@ -0,0 +1,13 @@ +FROM node:current +RUN npm i -g yarn --force +RUN git clone https://github.com/prettier/prettier.git /prettier +WORKDIR /prettier +RUN git pull +COPY --from=typescript/typescript /typescript/typescript-*.tgz /typescript.tgz +RUN mkdir /typescript +RUN tar -xzvf /typescript.tgz -C /typescript +RUN yarn add typescript@/typescript.tgz +RUN yarn +ENTRYPOINT [ "yarn" ] +# Build +CMD [ "build" ] \ No newline at end of file diff --git a/tests/cases/docker/vscode/Dockerfile b/tests/cases/docker/vscode/Dockerfile index da285512031..a9f810711b4 100644 --- a/tests/cases/docker/vscode/Dockerfile +++ b/tests/cases/docker/vscode/Dockerfile @@ -10,6 +10,7 @@ COPY --from=typescript/typescript /typescript/typescript-*.tgz /typescript.tgz WORKDIR /vscode/build RUN yarn add typescript@/typescript.tgz WORKDIR /vscode/extensions +RUN yarn add rimraf RUN yarn add typescript@/typescript.tgz WORKDIR /vscode RUN yarn add typescript@/typescript.tgz diff --git a/tests/cases/docker/xterm.js/Dockerfile b/tests/cases/docker/xterm.js/Dockerfile index 179459d280e..169d49893ba 100644 --- a/tests/cases/docker/xterm.js/Dockerfile +++ b/tests/cases/docker/xterm.js/Dockerfile @@ -1,5 +1,5 @@ -# node-pty doesn't build on node 12 right now, so we lock to 8 - the version xterm itself tests against :( -FROM node:8 +# node-pty doesn't build on node 12 right now, so we lock to 10 +FROM node:10 RUN git clone https://github.com/xtermjs/xterm.js.git /xtermjs WORKDIR /xtermjs RUN git pull diff --git a/tests/cases/user/prettier/test.json b/tests/cases/user/prettier/test.json deleted file mode 100644 index 7b041238424..00000000000 --- a/tests/cases/user/prettier/test.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "cloneUrl": "https://github.com/prettier/prettier.git", - "types": ["node"] -} diff --git a/tests/cases/user/prettier/tsconfig.json b/tests/cases/user/prettier/tsconfig.json deleted file mode 100644 index d3b1f270dbc..00000000000 --- a/tests/cases/user/prettier/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compilerOptions": { - "noImplicitAny": false, - "noImplicitThis": false, - "maxNodeModuleJsDepth": 0, - "strict": true, - "noEmit": true, - "allowJs": true, - "checkJs": true, - "types": ["node"], - "lib": ["esnext", "dom"], - "target": "esnext", - "module": "commonjs", - "pretty": false, - }, - "include": ["prettier/src"] -}