diff --git a/__tests__/fixtures/tsconfigs/decls/one.d.ts b/__tests__/fixtures/tsconfigs/decls/one.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/tsconfigs/decls/tsconfig.json b/__tests__/fixtures/tsconfigs/decls/tsconfig.json new file mode 100644 index 0000000..1ab6580 --- /dev/null +++ b/__tests__/fixtures/tsconfigs/decls/tsconfig.json @@ -0,0 +1,3 @@ +{ + "include": ["./**/*.*"] +} diff --git a/__tests__/fixtures/tsconfigs/decls/two.d.ts b/__tests__/fixtures/tsconfigs/decls/two.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/tsconfigs/extends/extends.ts b/__tests__/fixtures/tsconfigs/extends/extends.ts new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/tsconfigs/extends/tsconfig.json b/__tests__/fixtures/tsconfigs/extends/tsconfig.json new file mode 100644 index 0000000..3b5fde2 --- /dev/null +++ b/__tests__/fixtures/tsconfigs/extends/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../project/tsconfig.json", + "include": ["./**/*.*"] +} diff --git a/__tests__/fixtures/tsconfigs/glob/glob.ts b/__tests__/fixtures/tsconfigs/glob/glob.ts new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/tsconfigs/glob/tsconfig.json b/__tests__/fixtures/tsconfigs/glob/tsconfig.json new file mode 100644 index 0000000..10ec1eb --- /dev/null +++ b/__tests__/fixtures/tsconfigs/glob/tsconfig.json @@ -0,0 +1,3 @@ +{ + "include": ["../decls/*.d.ts", "./**/*.*"] +} diff --git a/__tests__/fixtures/tsconfigs/project/nested/nested.ts b/__tests__/fixtures/tsconfigs/project/nested/nested.ts new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/tsconfigs/project/project.ts b/__tests__/fixtures/tsconfigs/project/project.ts new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/tsconfigs/project/tsconfig.json b/__tests__/fixtures/tsconfigs/project/tsconfig.json new file mode 100644 index 0000000..4aee49e --- /dev/null +++ b/__tests__/fixtures/tsconfigs/project/tsconfig.json @@ -0,0 +1,3 @@ +{ + "include": ["../decls/one.d.ts", "./**/*.*"] +} diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index d1b3e63..2b824ed 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -499,4 +499,33 @@ describe('dependencyTree', () => { ).rejects.toThrowErrorMatchingSnapshot(); }); }); + + describe('tsconfig', () => { + beforeEach(() => { + dependencyTree = new DependencyTree([fixture('tsconfigs')]); + }); + + it('adds files in `include` from nearest tsconfig.json', async () => { + expect.hasAssertions(); + const result = await dependencyTree.gather(); + const decl1 = fixture('tsconfigs', 'decls', 'one.d.ts'); + const decl2 = fixture('tsconfigs', 'decls', 'two.d.ts'); + expect(result).toStrictEqual({ + missing: new Map(), + resolved: new Map([ + [fixture('tsconfigs', 'project', 'project.ts'), new Set([decl1])], + [ + fixture('tsconfigs', 'project', 'nested', 'nested.ts'), + new Set([decl1]), + ], + [fixture('tsconfigs', 'glob', 'glob.ts'), new Set([decl1, decl2])], + // "includes" is overwritten in the child config + [fixture('tsconfigs', 'extends', 'extends.ts'), new Set([])], + // decls in the same dir that includes './**.*.*' depend on one another + [fixture('tsconfigs', 'decls', 'one.d.ts'), new Set([decl2])], + [fixture('tsconfigs', 'decls', 'two.d.ts'), new Set([decl1])], + ]), + }); + }); + }); });