Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor tests to reduce runtime
- Loading branch information
Showing
2 changed files
with
41 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,50 @@ | ||
import { deepStrictEqual as equal, ok } from "assert"; | ||
import * as Path from "path"; | ||
import { Application } from "../lib/application"; | ||
import { readFileSync } from "fs"; | ||
import { join } from "path"; | ||
import { Logger, normalizePath } from "../lib/utils"; | ||
import { | ||
expandPackages, | ||
getTsEntryPointForPackage, | ||
} from "../lib/utils/package-manifest"; | ||
|
||
// TODO: These tests don't really need to go through the whole process. They could | ||
// instead just test the package expansion feature. Making this change should cut down on test time by ~50%. | ||
describe("Packages support", () => { | ||
it("handles monorepos", () => { | ||
const base = Path.join(__dirname, "packages", "multi-package"); | ||
const app = new Application(); | ||
app.bootstrap({ | ||
packages: [base], | ||
}); | ||
const project = app.convert(); | ||
const base = join(__dirname, "packages", "multi-package"); | ||
const logger = new Logger(); | ||
const packages = expandPackages(logger, ".", [base]); | ||
|
||
equal( | ||
project?.children?.map((r) => r.name), | ||
packages, | ||
[ | ||
"typedoc-multi-package-bar", | ||
"typedoc-multi-package-baz", | ||
"typedoc-multi-package-foo", | ||
] | ||
join(base, "packages/bar"), | ||
join(base, "packages/baz"), | ||
join(base, "packages/foo"), | ||
].map(normalizePath) | ||
); | ||
|
||
const entries = packages.map((p) => { | ||
const packageJson = join(p, "package.json"); | ||
return getTsEntryPointForPackage( | ||
logger, | ||
packageJson, | ||
JSON.parse(readFileSync(packageJson, "utf-8")) | ||
); | ||
}); | ||
|
||
equal(entries, [ | ||
join(base, "packages/bar/index.d.ts"), | ||
join(base, "packages/baz/index.ts"), | ||
join(base, "packages/foo/index.ts"), | ||
]); | ||
|
||
ok(!logger.hasErrors() && !logger.hasWarnings()); | ||
}); | ||
|
||
it("handles single packages", () => { | ||
const base = Path.join(__dirname, "packages", "single-package"); | ||
const app = new Application(); | ||
app.bootstrap({ | ||
packages: [base], | ||
}); | ||
const project = app.convert(); | ||
ok(project, "Failed to convert project"); | ||
equal( | ||
project.children?.map((r) => r.name), | ||
["helloWorld"] | ||
); | ||
const base = join(__dirname, "packages", "single-package"); | ||
const logger = new Logger(); | ||
const packages = expandPackages(logger, ".", [base]); | ||
|
||
equal(packages, [normalizePath(base)]); | ||
}); | ||
}); |