Skip to content

Commit

Permalink
Fix nits in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christoffer committed Jun 13, 2018
1 parent 3101688 commit 6792de2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
9 changes: 2 additions & 7 deletions test/match-path-async-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,15 @@ describe("match-path-async", () => {
["missing", "browser", "main"]
);
const mainFilePath = join("/root", "location", "mylib", "kalle.ts");
const browserFilePath = join(
"/root",
"location",
"mylib",
"christoffer.ts"
);
const browserFilePath = join("/root", "location", "mylib", "browser.ts");
const existingFiles = [mainFilePath, browserFilePath];

matchPath(
"lib/mylib",
(_path, callback) =>
callback(undefined, {
main: "./kalle.ts",
browser: "./christoffer.ts"
browser: "./browser.ts"
}),
(path, callback) =>
callback(undefined, existingFiles.indexOf(path) !== -1),
Expand Down
40 changes: 19 additions & 21 deletions test/match-path-sync-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ describe("match-path-sync", () => {

it("should resolve from main field in package.json and correctly remove file extension", () => {
const matchPath = createMatchPath("/root/", { "lib/*": ["location/*"] });
const existingPath = join("/root", "location", "mylibjs", "kallejs");
const existingPath = join("/root", "location", "mylibjs", "kalle.js");
// Make sure we escape the "."
const result = matchPath(
"lib/mylibjs",
(_: string) => ({ main: "./kallejs" }),
(_: string) => ({ main: "./kalle.js" }),
(name: string) => name === existingPath,
[".ts", ".js"]
);

assert.equal(result, existingPath);
assert.equal(result, removeExtension(existingPath));
});

it("should resolve from list of fields by priority in package.json", () => {
Expand All @@ -136,64 +136,62 @@ describe("match-path-sync", () => {
"browser",
"main"
]);
const mainFilePath = join("/root", "location", "mylibjs", "kallejs");
const browserFilePath = join(
"/root",
"location",
"mylibjs",
"christofferjs"
);
const mainFilePath = join("/root", "location", "mylibjs", "main.js");
const browserFilePath = join("/root", "location", "mylibjs", "browser.js");
const existingPaths = [mainFilePath, browserFilePath];

// Make sure we escape the "."
const result = matchPath(
"lib/mylibjs",
(_: string) => ({ main: "./kallejs", browser: "./christofferjs" }),
(_: string) => ({ main: "./main.js", browser: "./browser.js" }),
(name: string) => existingPaths.indexOf(name) !== -1,
[".ts", ".js"]
);

assert.equal(result, browserFilePath);
assert.equal(result, removeExtension(browserFilePath));
});

it("should ignore field mappings to missing files in package.json", () => {
const matchPath = createMatchPath("/root/", { "lib/*": ["location/*"] }, [
"browser",
"main"
]);
const existingPath = join("/root", "location", "mylibjs", "kallejs");
const existingPath = join("/root", "location", "mylibjs", "kalle.js");
// Make sure we escape the "."
const result = matchPath(
"lib/mylibjs",
(_: string) => ({
main: "./kallejs",
browser: "./missing-file"
main: "./kalle.js",
browser: "./nope.js"
}),
(name: string) => name === existingPath,
[".ts", ".js"]
);

assert.equal(result, existingPath);
assert.equal(result, removeExtension(existingPath));
});

it("should ignore advanced field mappings in package.json", () => {
const matchPath = createMatchPath("/root/", { "lib/*": ["location/*"] }, [
"browser",
"main"
]);
const existingPath = join("/root", "location", "mylibjs", "kallejs");
const mainFilePath = join("/root", "location", "mylibjs", "kalle.js");
const browserFilePath = join("/root", "location", "mylibjs", "browser.js");
const existingPaths = [mainFilePath, browserFilePath];

// Make sure we escape the "."
const result = matchPath(
"lib/mylibjs",
(_: string) => ({
main: "./kallejs",
browser: { kallejs: "./christofferjs" }
main: "./kalle.js",
browser: { mylibjs: "./browser.js", "./kalle.js": "./browser.js" }
}),
(name: string) => name === existingPath,
(name: string) => existingPaths.indexOf(name) !== -1,
[".ts", ".js"]
);

assert.equal(result, existingPath);
assert.equal(result, removeExtension(mainFilePath));
});

it("should resolve to with the help of baseUrl when not explicitly set", () => {
Expand Down

0 comments on commit 6792de2

Please sign in to comment.