-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test-dist-not-imported-from-src] Add a regression test for TypeScrip…
…t autocompletions from dist. This is a workaround to prevent a regression for microsoft/TypeScript#47184 If microsoft/TypeScript#35395 (Exclude specific files from auto import suggestions) is implemented, we should just use that instead.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { exit, stderr } from "process"; | ||
import { execPromise } from "../../../lib/execPromise.js"; | ||
|
||
// Test that the `dist` dir is not imported from the source (which causes unwanted autocompletion in VSCode). | ||
// In theory we could test this together with import restrictions, but `npx tsc --explainFiles` lets us test directly against the completions. | ||
|
||
await execPromise("make build"); // TODO: check for full expected build without compiling from scratch. | ||
|
||
let output; | ||
try { | ||
output = await execPromise("npx tsc --explainFiles -p ./tsconfig.json"); | ||
} catch (e) { | ||
stderr.write( | ||
"`npx tsc --explainFiles` failed. Please run `make test-tsc` to debug.", | ||
); | ||
exit(1); | ||
} | ||
const files = {}; | ||
let currentFile = null; | ||
for (const line of output.split("\n")) { | ||
if (currentFile === null || !line.startsWith(" ")) { | ||
currentFile = { | ||
path: line, | ||
from: [], | ||
}; | ||
files[line] = currentFile; | ||
} else { | ||
if (!line.includes("from file 'dist")) { | ||
// This theoretically has false positics, but it's good enough for us in practice. | ||
currentFile.anyNotImportedFromDist = true; | ||
} | ||
currentFile.from.push(line); | ||
} | ||
} | ||
|
||
for (const file of Object.values(files)) { | ||
if (file.path.startsWith(".")) { | ||
stderr.write(stderr, "Did not expect relative path:\n"); | ||
stderr.write(stderr, file); | ||
exit(1); | ||
} | ||
if (file.path.startsWith("dist/") && file.anyNotImportedFromDist) { | ||
stderr.write("Imports from the `dist` dir are not allowed:\n"); | ||
stderr.write(file.path + "\n"); | ||
stderr.write(file.from.join("\n")); | ||
exit(1); | ||
} | ||
} |