Skip to content

Commit 1f61e06

Browse files
weswighamsandersn
authored andcommitted
External runner fixes (#24115)
* Add missing @types/node dep to so many projects, rename parent node_modules dirs so they dont participate in tests, sort errors * Accept new baselines * Satisfy linter
1 parent 2f019ca commit 1f61e06

File tree

34 files changed

+1219
-1019
lines changed

34 files changed

+1219
-1019
lines changed

src/harness/externalCompileRunner.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// <reference path="runnerbase.ts" />
33
const fs = require("fs");
44
const path = require("path");
5+
const del = require("del");
56

67
interface ExecResult {
78
stdout: Buffer;
@@ -27,9 +28,32 @@ abstract class ExternalCompileRunnerBase extends RunnerBase {
2728
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
2829

2930
describe(`${this.kind()} code samples`, () => {
31+
const cwd = path.join(Harness.IO.getWorkspaceRoot(), this.testDir);
32+
const placeholderName = ".node_modules";
33+
const moduleDirName = "node_modules";
34+
before(() => {
35+
ts.forEachAncestorDirectory(cwd, dir => {
36+
try {
37+
fs.renameSync(path.join(dir, moduleDirName), path.join(dir, placeholderName));
38+
}
39+
catch {
40+
// empty
41+
}
42+
});
43+
});
3044
for (const test of testList) {
3145
this.runTest(typeof test === "string" ? test : test.file);
3246
}
47+
after(() => {
48+
ts.forEachAncestorDirectory(cwd, dir => {
49+
try {
50+
fs.renameSync(path.join(dir, placeholderName), path.join(dir, moduleDirName));
51+
}
52+
catch {
53+
// empty
54+
}
55+
});
56+
});
3357
});
3458
}
3559
private runTest(directoryName: string) {
@@ -42,6 +66,7 @@ abstract class ExternalCompileRunnerBase extends RunnerBase {
4266

4367
it("should build successfully", () => {
4468
let cwd = path.join(Harness.IO.getWorkspaceRoot(), cls.testDir, directoryName);
69+
const originalCwd = cwd;
4570
const stdio = isWorker ? "pipe" : "inherit";
4671
let types: string[];
4772
if (fs.existsSync(path.join(cwd, "test.json"))) {
@@ -64,14 +89,17 @@ abstract class ExternalCompileRunnerBase extends RunnerBase {
6489
fs.unlinkSync(path.join(cwd, "package-lock.json"));
6590
}
6691
if (fs.existsSync(path.join(cwd, "node_modules"))) {
67-
require("del").sync(path.join(cwd, "node_modules"), { force: true });
92+
del.sync(path.join(cwd, "node_modules"), { force: true });
6893
}
6994
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
7095
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed: ${install.stderr.toString()}`);
7196
}
7297
const args = [path.join(Harness.IO.getWorkspaceRoot(), "built/local/tsc.js")];
7398
if (types) {
7499
args.push("--types", types.join(","));
100+
// Also actually install those types (for, eg, the js projects which need node)
101+
const install = cp.spawnSync(`npm`, ["i", ...types.map(t => `@types/${t}`), "--no-save", "--ignore-scripts"], { cwd: originalCwd, 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
102+
if (install.status !== 0) throw new Error(`NPM Install types for ${directoryName} failed: ${install.stderr.toString()}`);
75103
}
76104
args.push("--noEmit");
77105
Harness.Baseline.runBaseline(`${cls.kind()}/${directoryName}.log`, () => {
@@ -91,7 +119,7 @@ class UserCodeRunner extends ExternalCompileRunnerBase {
91119
// tslint:disable-next-line:no-null-keyword
92120
return result.status === 0 && !result.stdout.length && !result.stderr.length ? null : `Exit Code: ${result.status}
93121
Standard output:
94-
${stripAbsoluteImportPaths(result.stdout.toString().replace(/\r\n/g, "\n"))}
122+
${sortErrors(stripAbsoluteImportPaths(result.stdout.toString().replace(/\r\n/g, "\n")))}
95123
96124
97125
Standard error:
@@ -109,6 +137,29 @@ function stripAbsoluteImportPaths(result: string) {
109137
.replace(/Module '".*?\/tests\/cases\/user\//g, `Module '"/`);
110138
}
111139

140+
function sortErrors(result: string) {
141+
return ts.flatten(splitBy(result.split("\n"), s => /^\S+/.test(s)).sort(compareErrorStrings)).join("\n");
142+
}
143+
144+
const errorRegexp = /^(.+\.[tj]sx?)\((\d+),(\d+)\): error TS/;
145+
function compareErrorStrings(a: string[], b: string[]) {
146+
ts.Debug.assertGreaterThanOrEqual(a.length, 1);
147+
ts.Debug.assertGreaterThanOrEqual(b.length, 1);
148+
const matchA = a[0].match(errorRegexp);
149+
if (!matchA) {
150+
return -1;
151+
}
152+
const matchB = b[0].match(errorRegexp);
153+
if (!matchB) {
154+
return 1;
155+
}
156+
const [, errorFileA, lineNumberStringA, columnNumberStringA] = matchA;
157+
const [, errorFileB, lineNumberStringB, columnNumberStringB] = matchB;
158+
return ts.comparePathsCaseSensitive(errorFileA, errorFileB) ||
159+
ts.compareValues(parseInt(lineNumberStringA), parseInt(lineNumberStringB)) ||
160+
ts.compareValues(parseInt(columnNumberStringA), parseInt(columnNumberStringB));
161+
}
162+
112163
class DefinitelyTypedRunner extends ExternalCompileRunnerBase {
113164
readonly testDir = "../DefinitelyTyped/types/";
114165
workingDirectory = this.testDir;

tests/baselines/reference/user/adonis-framework.log

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ node_modules/adonis-framework/src/Session/Drivers/File/index.js(79,15): error TS
146146
node_modules/adonis-framework/src/Session/Drivers/Redis/index.js(23,14): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
147147
node_modules/adonis-framework/src/Session/Drivers/Redis/index.js(59,15): error TS2322: Type 'IterableIterator<any>' is not assignable to type 'boolean'.
148148
node_modules/adonis-framework/src/Session/Drivers/Redis/index.js(72,15): error TS2322: Type 'IterableIterator<any>' is not assignable to type 'boolean'.
149+
node_modules/adonis-framework/src/Session/SessionManager.js(13,21): error TS2307: Cannot find module 'adonis-fold'.
150+
node_modules/adonis-framework/src/Session/SessionManager.js(69,22): error TS2339: Property 'drivers' does not exist on type 'Function'.
151+
node_modules/adonis-framework/src/Session/SessionManager.js(69,49): error TS2339: Property 'drivers' does not exist on type 'Function'.
152+
node_modules/adonis-framework/src/Session/SessionManager.js(71,76): error TS2339: Property 'drivers' does not exist on type 'Function'.
153+
node_modules/adonis-framework/src/Session/Store.js(28,13): error TS2304: Cannot find name 'Mixed'.
154+
node_modules/adonis-framework/src/Session/Store.js(80,13): error TS2304: Cannot find name 'Mixed'.
149155
node_modules/adonis-framework/src/Session/index.js(10,14): error TS2304: Cannot find name 'SessionDriver'.
150156
node_modules/adonis-framework/src/Session/index.js(11,2): error TS1003: Identifier expected.
151157
node_modules/adonis-framework/src/Session/index.js(11,11): error TS2304: Cannot find name 'Class'.
@@ -173,12 +179,6 @@ node_modules/adonis-framework/src/Session/index.js(249,15): error TS2304: Cannot
173179
node_modules/adonis-framework/src/Session/index.js(267,15): error TS2304: Cannot find name 'Mixed'.
174180
node_modules/adonis-framework/src/Session/index.js(287,15): error TS2322: Type 'IterableIterator<any>' is not assignable to type 'boolean'.
175181
node_modules/adonis-framework/src/Session/index.js(293,12): error TS2532: Object is possibly 'undefined'.
176-
node_modules/adonis-framework/src/Session/SessionManager.js(13,21): error TS2307: Cannot find module 'adonis-fold'.
177-
node_modules/adonis-framework/src/Session/SessionManager.js(69,22): error TS2339: Property 'drivers' does not exist on type 'Function'.
178-
node_modules/adonis-framework/src/Session/SessionManager.js(69,49): error TS2339: Property 'drivers' does not exist on type 'Function'.
179-
node_modules/adonis-framework/src/Session/SessionManager.js(71,76): error TS2339: Property 'drivers' does not exist on type 'Function'.
180-
node_modules/adonis-framework/src/Session/Store.js(28,13): error TS2304: Cannot find name 'Mixed'.
181-
node_modules/adonis-framework/src/Session/Store.js(80,13): error TS2304: Cannot find name 'Mixed'.
182182
node_modules/adonis-framework/src/View/Form/index.js(75,11): error TS2532: Object is possibly 'undefined'.
183183
node_modules/adonis-framework/src/View/Form/index.js(115,15): error TS2304: Cannot find name 'Mixed'.
184184
node_modules/adonis-framework/src/View/Form/index.js(147,63): error TS2345: Argument of type 'string | any[]' is not assignable to parameter of type 'any[]'.

tests/baselines/reference/user/async.log

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ node_modules/async/auto.js(159,18): error TS2695: Left side of comma operator is
4343
node_modules/async/auto.js(159,50): error TS2695: Left side of comma operator is unused and has no side effects.
4444
node_modules/async/autoInject.js(44,17): error TS2695: Left side of comma operator is unused and has no side effects.
4545
node_modules/async/autoInject.js(134,6): error TS2695: Left side of comma operator is unused and has no side effects.
46-
node_modules/async/autoInject.js(136,25): error TS2532: Object is possibly 'undefined'.
4746
node_modules/async/autoInject.js(136,25): error TS2722: Cannot invoke an object which is possibly 'undefined'.
47+
node_modules/async/autoInject.js(136,25): error TS2532: Object is possibly 'undefined'.
4848
node_modules/async/autoInject.js(136,26): error TS2695: Left side of comma operator is unused and has no side effects.
4949
node_modules/async/autoInject.js(139,14): error TS2695: Left side of comma operator is unused and has no side effects.
5050
node_modules/async/autoInject.js(160,28): error TS2695: Left side of comma operator is unused and has no side effects.
@@ -145,9 +145,9 @@ node_modules/async/dist/async.js(2963,25): error TS2722: Cannot invoke an object
145145
node_modules/async/dist/async.js(2970,25): error TS2722: Cannot invoke an object which is possibly 'undefined'.
146146
node_modules/async/dist/async.js(2971,28): error TS2722: Cannot invoke an object which is possibly 'undefined'.
147147
node_modules/async/dist/async.js(3005,25): error TS2722: Cannot invoke an object which is possibly 'undefined'.
148-
node_modules/async/dist/async.js(3008,9): error TS2532: Object is possibly 'undefined'.
149148
node_modules/async/dist/async.js(3008,9): error TS2684: The 'this' context of type 'Function | undefined' is not assignable to method's 'this' of type 'Function'.
150149
Type 'undefined' is not assignable to type 'Function'.
150+
node_modules/async/dist/async.js(3008,9): error TS2532: Object is possibly 'undefined'.
151151
node_modules/async/dist/async.js(3081,25): error TS2722: Cannot invoke an object which is possibly 'undefined'.
152152
node_modules/async/dist/async.js(3086,25): error TS2722: Cannot invoke an object which is possibly 'undefined'.
153153
node_modules/async/dist/async.js(3087,28): error TS2722: Cannot invoke an object which is possibly 'undefined'.
@@ -175,18 +175,18 @@ node_modules/async/dist/async.js(4153,14): error TS2339: Property 'unshift' does
175175
node_modules/async/dist/async.js(4367,5): error TS2322: Type 'any[] | {}' is not assignable to type 'any[]'.
176176
Type '{}' is not assignable to type 'any[]'.
177177
Property 'flatMap' is missing in type '{}'.
178-
node_modules/async/dist/async.js(4603,17): error TS2532: Object is possibly 'undefined'.
179178
node_modules/async/dist/async.js(4603,17): error TS2684: The 'this' context of type 'Function | undefined' is not assignable to method's 'this' of type 'Function'.
180179
Type 'undefined' is not assignable to type 'Function'.
180+
node_modules/async/dist/async.js(4603,17): error TS2532: Object is possibly 'undefined'.
181181
node_modules/async/dist/async.js(4917,19): error TS2339: Property 'code' does not exist on type 'Error'.
182182
node_modules/async/dist/async.js(4919,23): error TS2339: Property 'info' does not exist on type 'Error'.
183183
node_modules/async/dist/async.js(5090,9): error TS2722: Cannot invoke an object which is possibly 'undefined'.
184184
node_modules/async/dist/async.js(5146,9): error TS2722: Cannot invoke an object which is possibly 'undefined'.
185185
node_modules/async/dist/async.js(5165,20): error TS2339: Property 'unmemoized' does not exist on type 'Function'.
186186
node_modules/async/dist/async.js(5208,25): error TS2722: Cannot invoke an object which is possibly 'undefined'.
187-
node_modules/async/dist/async.js(5211,9): error TS2532: Object is possibly 'undefined'.
188187
node_modules/async/dist/async.js(5211,9): error TS2684: The 'this' context of type 'Function | undefined' is not assignable to method's 'this' of type 'Function'.
189188
Type 'undefined' is not assignable to type 'Function'.
189+
node_modules/async/dist/async.js(5211,9): error TS2532: Object is possibly 'undefined'.
190190
node_modules/async/dist/async.js(5315,20): error TS2532: Object is possibly 'undefined'.
191191
node_modules/async/dist/async.js(5315,20): error TS2684: The 'this' context of type 'Function | undefined' is not assignable to method's 'this' of type 'Function'.
192192
Type 'undefined' is not assignable to type 'Function'.
@@ -240,8 +240,8 @@ node_modules/async/eachSeries.js(28,12): error TS2304: Cannot find name 'AsyncFu
240240
node_modules/async/eachSeries.js(36,20): error TS2695: Left side of comma operator is unused and has no side effects.
241241
node_modules/async/ensureAsync.js(34,12): error TS2304: Cannot find name 'AsyncFunction'.
242242
node_modules/async/ensureAsync.js(36,14): error TS2304: Cannot find name 'AsyncFunction'.
243-
node_modules/async/ensureAsync.js(56,9): error TS2532: Object is possibly 'undefined'.
244243
node_modules/async/ensureAsync.js(56,9): error TS2722: Cannot invoke an object which is possibly 'undefined'.
244+
node_modules/async/ensureAsync.js(56,9): error TS2532: Object is possibly 'undefined'.
245245
node_modules/async/ensureAsync.js(56,10): error TS2695: Left side of comma operator is unused and has no side effects.
246246
node_modules/async/ensureAsync.js(57,13): error TS2695: Left side of comma operator is unused and has no side effects.
247247
node_modules/async/ensureAsync.js(62,18): error TS2695: Left side of comma operator is unused and has no side effects.

tests/baselines/reference/user/bcryptjs.log

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ Standard output:
33
node_modules/bcryptjs/scripts/build.js(1,26): error TS2307: Cannot find module 'metascript'.
44
node_modules/bcryptjs/scripts/build.js(32,1): error TS2322: Type '{ VERSION: any; }' is not assignable to type '{ [x: string]: any; VERSION: any; ISAAC: boolean; }'.
55
Property 'ISAAC' is missing in type '{ VERSION: any; }'.
6-
node_modules/bcryptjs/src/bcrypt.js(25,13): error TS2322: Type 'Buffer' is not assignable to type 'number[]'.
7-
Property 'flatMap' is missing in type 'Buffer'.
8-
node_modules/bcryptjs/src/bcrypt.js(94,14): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
9-
node_modules/bcryptjs/src/bcrypt.js(150,5): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
10-
Type 'undefined' is not assignable to type 'string'.
11-
node_modules/bcryptjs/src/bcrypt.js(160,14): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
12-
node_modules/bcryptjs/src/bcrypt.js(238,14): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
136
node_modules/bcryptjs/src/bcrypt/impl.js(516,22): error TS2345: Argument of type 'Int32Array | number[]' is not assignable to parameter of type 'number[]'.
147
Type 'Int32Array' is not assignable to type 'number[]'.
158
Property 'flatMap' is missing in type 'Int32Array'.
@@ -27,6 +20,13 @@ node_modules/bcryptjs/src/bcrypt/prng/accum.js(65,74): error TS2339: Property 'd
2720
node_modules/bcryptjs/src/bcrypt/prng/accum.js(66,22): error TS2339: Property 'detachEvent' does not exist on type 'Document'.
2821
node_modules/bcryptjs/src/bcrypt/prng/accum.js(67,22): error TS2339: Property 'detachEvent' does not exist on type 'Document'.
2922
node_modules/bcryptjs/src/bcrypt/util.js(20,5): error TS2304: Cannot find name 'utfx'.
23+
node_modules/bcryptjs/src/bcrypt.js(25,13): error TS2322: Type 'Buffer' is not assignable to type 'number[]'.
24+
Property 'flatMap' is missing in type 'Buffer'.
25+
node_modules/bcryptjs/src/bcrypt.js(94,14): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
26+
node_modules/bcryptjs/src/bcrypt.js(150,5): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
27+
Type 'undefined' is not assignable to type 'string'.
28+
node_modules/bcryptjs/src/bcrypt.js(160,14): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
29+
node_modules/bcryptjs/src/bcrypt.js(238,14): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
3030
node_modules/bcryptjs/src/wrap.js(37,26): error TS2304: Cannot find name 'define'.
3131
node_modules/bcryptjs/src/wrap.js(37,51): error TS2304: Cannot find name 'define'.
3232
node_modules/bcryptjs/src/wrap.js(38,9): error TS2304: Cannot find name 'define'.

0 commit comments

Comments
 (0)