Skip to content

Commit

Permalink
test: consider extensions in resolved paths (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
katywings committed Jul 26, 2020
1 parent 3d17cea commit 2380f89
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions test/data/match-path-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { join, dirname } from "path";
import { removeExtension } from "../../src/filesystem";

export interface OneTest {
readonly name: string;
Expand Down Expand Up @@ -60,7 +59,7 @@ export const tests: ReadonlyArray<OneTest> = [
existingFiles: [join("/root", "location", "mylib.myext")],
requestedModule: "lib/mylib",
extensions: [".js", ".myext"],
expectedPath: removeExtension(join("/root", "location", "mylib.myext")),
expectedPath: join("/root", "location", "mylib.myext"),
},
{
name: "should resolve request with extension specified",
Expand All @@ -78,7 +77,7 @@ export const tests: ReadonlyArray<OneTest> = [
},
existingFiles: [join("/root", "location", "foo.ts")],
requestedModule: "lib/foo",
expectedPath: removeExtension(join("/root", "location", "foo.ts")),
expectedPath: join("/root", "location", "foo.ts"),
},
{
name: "should resolve to parent folder when filename is in subfolder",
Expand All @@ -95,9 +94,7 @@ export const tests: ReadonlyArray<OneTest> = [
existingFiles: [join("/root", "location", "mylib", "kalle.ts")],
packageJson: { main: "./kalle.ts" },
requestedModule: "lib/mylib",
expectedPath: removeExtension(
join("/root", "location", "mylib", "kalle.ts")
),
expectedPath: join("/root", "location", "mylib", "kalle.ts"),
},
{
name: "should resolve from main field in package.json (js)",
Expand All @@ -107,9 +104,7 @@ export const tests: ReadonlyArray<OneTest> = [
packageJson: { main: "./kalle.js" },
requestedModule: "lib/mylib.js",
extensions: [".ts", ".js"],
expectedPath: removeExtension(
join("/root", "location", "mylib.js", "kalle.js")
),
expectedPath: join("/root", "location", "mylib.js", "kalle.js"),
},
{
name:
Expand All @@ -120,9 +115,7 @@ export const tests: ReadonlyArray<OneTest> = [
packageJson: { main: "./kalle.js" },
extensions: [".ts", ".js"],
requestedModule: "lib/mylibjs",
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "kalle.js")
),
expectedPath: join("/root", "location", "mylibjs", "kalle.js"),
},
{
name: "should resolve from list of fields by priority in package.json",
Expand All @@ -136,9 +129,7 @@ export const tests: ReadonlyArray<OneTest> = [
],
extensions: [".ts", ".js"],
requestedModule: "lib/mylibjs",
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "browser.js")
),
expectedPath: join("/root", "location", "mylibjs", "browser.js"),
},
{
name: "should ignore field mappings to missing files in package.json",
Expand All @@ -152,9 +143,7 @@ export const tests: ReadonlyArray<OneTest> = [
browser: "./nope.js",
},
extensions: [".ts", ".js"],
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "kalle.js")
),
expectedPath: join("/root", "location", "mylibjs", "kalle.js"),
},
{
name: "should ignore advanced field mappings in package.json",
Expand All @@ -170,9 +159,7 @@ export const tests: ReadonlyArray<OneTest> = [
browser: { mylibjs: "./browser.js", "./kalle.js": "./browser.js" },
},
extensions: [".ts", ".js"],
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "kalle.js")
),
expectedPath: join("/root", "location", "mylibjs", "kalle.js"),
},
{
name: "should resolve to with the help of baseUrl when not explicitly set",
Expand Down Expand Up @@ -209,4 +196,15 @@ export const tests: ReadonlyArray<OneTest> = [
requestedModule: "lib/mylib",
expectedPath: undefined,
},
{
name: "should resolve main file with cjs file extension",
absoluteBaseUrl: "/root/",
paths: {},
existingFiles: [join("/root", "mylib", "index.cjs")],
packageJson: {
main: "./index.cjs",
},
requestedModule: "mylib",
expectedPath: join("/root", "mylib", "index.cjs"),
},
];

0 comments on commit 2380f89

Please sign in to comment.