Skip to content

Commit

Permalink
chore: Refactor tests to reduce runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jun 13, 2021
1 parent ec18bb0 commit 858b231
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/lib/utils/package-manifest.ts
@@ -1,4 +1,4 @@
// Utilities to support the inspection of node package "manifests" (package.json's)
// Utilities to support the inspection of node package "manifests"

import glob = require("glob");
import { dirname, join, resolve } from "path";
Expand Down Expand Up @@ -81,7 +81,7 @@ export function expandPackages(
packageJsonDir: string,
workspaces: string[]
): string[] {
// Technnically npm and Yarn workspaces don't support recursive nesting,
// Technically npm and Yarn workspaces don't support recursive nesting,
// however we support the passing of paths to either packages or
// to the root of a workspace tree in our params and so we could here
// be dealing with either a root or a leaf. So let's do this recursively,
Expand All @@ -99,7 +99,7 @@ export function expandPackages(
// Assume this is a single package repo
return [dirname(packageJsonPath)];
}
// This is a workpace root package, recurse
// This is a workspace root package, recurse
return expandPackages(
logger,
dirname(packageJsonPath),
Expand Down
64 changes: 38 additions & 26 deletions src/test/packages.test.ts
@@ -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)]);
});
});

0 comments on commit 858b231

Please sign in to comment.