webpack/test/configCases/externals/import-attributes/index.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-06-10 22:40:11 +08:00
import * as staticPkg from "./static-package.json" with { type: "json" };
import * as staticPkgStr from "./static-package-str.json" with { "type": "json" };
2024-08-05 23:13:57 +08:00
import * as staticPkgModuleImport from "./static-package-module-import.json" with { "type": "json" };
2024-03-28 20:45:53 +08:00
2024-03-16 00:03:28 +08:00
it("should allow async externals", async () => {
expect(staticPkg.default.foo).toBe("static");
expect(staticPkgStr.default.foo).toBe("static-str");
2024-08-05 23:13:57 +08:00
expect(staticPkgModuleImport.default.foo).toBe("static");
2024-03-16 00:03:28 +08:00
const dynamicPkg = await import("./dynamic-package.json", {
2024-03-28 20:45:53 +08:00
with: { type: "json" }
})
2024-06-10 22:40:11 +08:00
expect(dynamicPkg.default.foo).toBe("dynamic");
2024-03-28 20:45:53 +08:00
2024-06-10 22:40:11 +08:00
const dynamicPkgStr = await import("./dynamic-package-str.json", {
"with": { "type": "json" }
2024-03-16 00:03:28 +08:00
})
expect(dynamicPkgStr.default.foo).toBe("dynamic-str");
2024-03-16 00:59:30 +08:00
const eagerPkg = await import(/* webpackMode: "eager" */ "./eager.json", {
2024-06-10 22:40:11 +08:00
with: { type: "json" }
2024-03-16 00:59:30 +08:00
});
expect(eagerPkg.default.foo).toBe("eager");
await import("./weak.json", {
2024-06-10 22:40:11 +08:00
with: { type: "json" }
2024-03-16 00:59:30 +08:00
});
const weakPkg = await import(/* webpackMode: "weak" */ "./weak.json", {
2024-06-10 22:40:11 +08:00
with: { type: "json" }
2024-03-16 00:59:30 +08:00
});
expect(weakPkg.default.foo).toBe("weak");
const pkg = "pkg.json";
const nested = await import(`./nested/${pkg}`, {
2024-06-10 22:40:11 +08:00
with: { type: "json" }
2024-03-16 00:59:30 +08:00
});
expect(nested.default.foo).toBe("context-dependency");
const reExportPkg = await import("./re-export.js");
expect(reExportPkg.foo).toBe("re-export");
2024-08-05 16:47:45 +08:00
const dynamicPkgModuleImport = await import("./dynamic-package-module-import.json", {
with: { type: "json" }
})
expect(dynamicPkgModuleImport.default.foo).toBe("dynamic");
2024-03-16 00:03:28 +08:00
});
2024-03-28 21:23:31 +08:00
2024-06-10 22:40:11 +08:00
export * from "./re-export-directly.json" with { type: "json" }