|
1 | 1 | import assert from "node:assert";
|
| 2 | +import {normalizeConfig} from "../src/config.js"; |
2 | 3 | import {parseMarkdown} from "../src/markdown.js";
|
3 | 4 | import {getResolvers} from "../src/resolvers.js";
|
4 | 5 |
|
5 |
| -describe("getResolvers(page, {root, path})", () => { |
| 6 | +describe("getResolvers(page, {root, path})", async () => { |
| 7 | + const {md} = await normalizeConfig(); |
6 | 8 | const builtins = ["npm:@observablehq/runtime", "npm:@observablehq/stdlib", "observablehq:client"];
|
7 | 9 | it("resolves directly-attached files", async () => {
|
8 |
| - const options = {root: "test/input", path: "attached.md"}; |
| 10 | + const options = {root: "test/input", path: "attached.md", md}; |
9 | 11 | const page = parseMarkdown("${FileAttachment('foo.csv')}", options);
|
10 | 12 | const resolvers = await getResolvers(page, options);
|
11 | 13 | assert.deepStrictEqual(resolvers.files, new Set(["./foo.csv"]));
|
12 | 14 | });
|
13 | 15 | it("ignores files that are outside of the source root", async () => {
|
14 |
| - const options = {root: "test/input", path: "attached.md"}; |
| 16 | + const options = {root: "test/input", path: "attached.md", md}; |
15 | 17 | const page = parseMarkdown("${FileAttachment('../foo.csv')}", options);
|
16 | 18 | const resolvers = await getResolvers(page, options);
|
17 | 19 | assert.deepStrictEqual(resolvers.files, new Set([]));
|
18 | 20 | });
|
19 | 21 | it("detects file methods", async () => {
|
20 |
| - const options = {root: "test/input", path: "attached.md"}; |
| 22 | + const options = {root: "test/input", path: "attached.md", md}; |
21 | 23 | const page = parseMarkdown("${FileAttachment('foo.csv').csv}", options);
|
22 | 24 | const resolvers = await getResolvers(page, options);
|
23 | 25 | assert.deepStrictEqual(resolvers.staticImports, new Set(["npm:d3-dsv", ...builtins]));
|
24 | 26 | });
|
25 | 27 | it("detects local static imports", async () => {
|
26 |
| - const options = {root: "test/input/imports", path: "attached.md"}; |
| 28 | + const options = {root: "test/input/imports", path: "attached.md", md}; |
27 | 29 | const page = parseMarkdown("```js\nimport './bar.js';\n```", options);
|
28 | 30 | const resolvers = await getResolvers(page, options);
|
29 | 31 | assert.deepStrictEqual(resolvers.staticImports, new Set(["./bar.js", ...builtins]));
|
30 | 32 | assert.deepStrictEqual(resolvers.localImports, new Set(["./bar.js"]));
|
31 | 33 | });
|
32 | 34 | it("detects local transitive static imports", async () => {
|
33 |
| - const options = {root: "test/input/imports", path: "attached.md"}; |
| 35 | + const options = {root: "test/input/imports", path: "attached.md", md}; |
34 | 36 | const page = parseMarkdown("```js\nimport './other/foo.js';\n```", options);
|
35 | 37 | const resolvers = await getResolvers(page, options);
|
36 | 38 | assert.deepStrictEqual(resolvers.staticImports, new Set(["./other/foo.js", "./bar.js", ...builtins]));
|
37 | 39 | assert.deepStrictEqual(resolvers.localImports, new Set(["./other/foo.js", "./bar.js"]));
|
38 | 40 | });
|
39 | 41 | it("detects local transitive static imports (2)", async () => {
|
40 |
| - const options = {root: "test/input/imports", path: "attached.md"}; |
| 42 | + const options = {root: "test/input/imports", path: "attached.md", md}; |
41 | 43 | const page = parseMarkdown("```js\nimport './transitive-static-import.js';\n```", options);
|
42 | 44 | const resolvers = await getResolvers(page, options);
|
43 | 45 | assert.deepStrictEqual(resolvers.staticImports, new Set(["./transitive-static-import.js", "./other/foo.js", "./bar.js", ...builtins])); // prettier-ignore
|
44 | 46 | assert.deepStrictEqual(resolvers.localImports, new Set(["./transitive-static-import.js", "./other/foo.js", "./bar.js"])); // prettier-ignore
|
45 | 47 | });
|
46 | 48 | it("detects local transitive dynamic imports", async () => {
|
47 |
| - const options = {root: "test/input/imports", path: "attached.md"}; |
| 49 | + const options = {root: "test/input/imports", path: "attached.md", md}; |
48 | 50 | const page = parseMarkdown("```js\nimport './dynamic-import.js';\n```", options);
|
49 | 51 | const resolvers = await getResolvers(page, options);
|
50 | 52 | assert.deepStrictEqual(resolvers.staticImports, new Set(["./dynamic-import.js", ...builtins]));
|
51 | 53 | assert.deepStrictEqual(resolvers.localImports, new Set(["./dynamic-import.js", "./bar.js"]));
|
52 | 54 | });
|
53 | 55 | it("detects local transitive dynamic imports (2)", async () => {
|
54 |
| - const options = {root: "test/input/imports", path: "attached.md"}; |
| 56 | + const options = {root: "test/input/imports", path: "attached.md", md}; |
55 | 57 | const page = parseMarkdown("```js\nimport('./dynamic-import.js');\n```", options);
|
56 | 58 | const resolvers = await getResolvers(page, options);
|
57 | 59 | assert.deepStrictEqual(resolvers.staticImports, new Set(builtins));
|
58 | 60 | assert.deepStrictEqual(resolvers.localImports, new Set(["./dynamic-import.js", "./bar.js"]));
|
59 | 61 | });
|
60 | 62 | it("detects local transitive dynamic imports (3)", async () => {
|
61 |
| - const options = {root: "test/input/imports", path: "attached.md"}; |
| 63 | + const options = {root: "test/input/imports", path: "attached.md", md}; |
62 | 64 | const page = parseMarkdown("```js\nimport('./transitive-dynamic-import.js');\n```", options);
|
63 | 65 | const resolvers = await getResolvers(page, options);
|
64 | 66 | assert.deepStrictEqual(resolvers.staticImports, new Set(builtins));
|
65 | 67 | assert.deepStrictEqual(resolvers.localImports, new Set(["./transitive-dynamic-import.js", "./other/foo.js", "./bar.js"])); // prettier-ignore
|
66 | 68 | });
|
67 | 69 | it("detects local transitive dynamic imports (4)", async () => {
|
68 |
| - const options = {root: "test/input/imports", path: "attached.md"}; |
| 70 | + const options = {root: "test/input/imports", path: "attached.md", md}; |
69 | 71 | const page = parseMarkdown("```js\nimport('./transitive-static-import.js');\n```", options);
|
70 | 72 | const resolvers = await getResolvers(page, options);
|
71 | 73 | assert.deepStrictEqual(resolvers.staticImports, new Set(builtins));
|
72 | 74 | assert.deepStrictEqual(resolvers.localImports, new Set(["./transitive-static-import.js", "./other/foo.js", "./bar.js"])); // prettier-ignore
|
73 | 75 | });
|
74 | 76 | it("detects local dynamic imports", async () => {
|
75 |
| - const options = {root: "test/input", path: "attached.md"}; |
| 77 | + const options = {root: "test/input", path: "attached.md", md}; |
76 | 78 | const page = parseMarkdown("${import('./foo.js')}", options);
|
77 | 79 | const resolvers = await getResolvers(page, options);
|
78 | 80 | assert.deepStrictEqual(resolvers.staticImports, new Set(builtins));
|
|
0 commit comments