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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/definitions-parser/src/lib/definition-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,15 @@ function checkFilesFromTsConfig(packageName: string, tsconfig: TsConfig, directo
if (file.startsWith("./")) {
throw new Error(`In ${tsconfigPath}: Unnecessary "./" at the start of ${file}`);
}
if (!isRelativePath(file)) {
if (!isRelativePath(file.replace(/^(?:\.\.\/)+/, ""))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn’t this allow tests from anywhere? Or is there something else that would prevent types/react-dom/tsconfig.json from listing ../react/react-tests.d.ts?

throw new Error(`In ${tsconfigPath}: A path segment is empty or all dots ${file}`);
}
if (file.endsWith(".d.ts") && file !== "index.d.ts") {
throw new Error(`${packageName}: Only index.d.ts may be listed explicitly in tsconfig's "files" entry.
Other d.ts files must either be referenced through index.d.ts, tests, or added to OTHER_FILES.txt.`);
}

if (!file.endsWith(".d.ts") && !file.startsWith("test/")) {
if (!file.endsWith(".d.ts") && !file.startsWith("test/") && !file.startsWith("../")) {
const expectedName = `${packageName}-tests.ts`;
if (file !== expectedName && file !== `${expectedName}x`) {
const message =
Expand Down
22 changes: 22 additions & 0 deletions packages/definitions-parser/test/definition-parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Dir, InMemoryFS } from "@definitelytyped/utils";
import { createMockDT } from "../src/mocks";
import { getTypingInfo } from "../src/lib/definition-parser";

Expand Down Expand Up @@ -109,4 +110,25 @@ describe(getTypingInfo, () => {
const dt = createMockDT();
return expect(getTypingInfo("wordpress__plugins", dt.pkgFS("wordpress__plugins"))).resolves.toBeDefined();
});

it("allows typesVersions-parent tests in tsconfig.json", () => {
const pkg = new Dir(undefined);
pkg.set(
"index.d.ts",
`// Type definitions for mock
// Project: https://github.com/baz/foo
// Definitions by: My Self <https://github.com/me>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
`
);
pkg.set(
"tsconfig.json",
JSON.stringify({
compilerOptions: {},
files: ["index.d.ts", "../mock-tests.ts"]
})
);
const memFS = new InMemoryFS(pkg, "types/ts1.0/mock");
return expect(getTypingInfo("mock", memFS)).resolves.toBeDefined();
});
});