Skip to content

Commit

Permalink
test: add test for components/index.ts dts behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 1, 2024
1 parent 1ca855a commit eb495b0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/fixture/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// JSX
export * as jsx from "./jsx.jsx";
export * as tsx from "./tsx.tsx";

// Vue
export * as blank from "./blank.vue";
export * as scriptSetupTS from "./script-setup-ts.vue";
export * as scriptMultiBlock from "./script-multi-block.vue";
export * as ts from "./ts.vue";
49 changes: 49 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe("mkdist", () => {
"dist/types.d.ts",
"dist/star/index.mjs",
"dist/star/other.mjs",
"dist/components/index.mjs",
"dist/components/blank.vue",
"dist/components/js.vue",
"dist/components/script-multi-block.vue",
Expand All @@ -59,6 +60,7 @@ describe("mkdist", () => {
});
expect(writtenFiles.sort()).toEqual(
[
"dist/components/index.mjs",
"dist/components/blank.vue",
"dist/components/js.vue",
"dist/components/script-multi-block.vue",
Expand All @@ -80,6 +82,7 @@ describe("mkdist", () => {
});
expect(writtenFiles.sort()).toEqual(
[
"dist/components/index.mjs",
"dist/components/blank.vue",
"dist/components/script-multi-block.vue",
"dist/components/script-setup-ts.vue",
Expand Down Expand Up @@ -116,6 +119,8 @@ describe("mkdist", () => {
"dist/star/other.mjs",
"dist/star/other.d.ts",
"dist/types.d.ts",
"dist/components/index.mjs",
"dist/components/index.d.ts",
"dist/components/blank.vue",
"dist/components/js.vue",
"dist/components/js.vue.d.ts",
Expand Down Expand Up @@ -151,15 +156,30 @@ describe("mkdist", () => {
export type { Other } from "./other.js";
"
`);

expect(await readFile(resolve(rootDir, "dist/dir-export.d.ts"), "utf8"))
.toMatchInlineSnapshot(`
"export { default as bar } from "./bar.js";
export * from "./star/index.js";
"
`);

expect(
await readFile(resolve(rootDir, "dist/bar/esm.d.mts"), "utf8"),
).toMatch("declare");

expect(
await readFile(resolve(rootDir, "dist/components/index.d.ts"), "utf8"),
).toMatchInlineSnapshot(`
"export * as jsx from "./jsx.jsx.js";
export * as tsx from "./tsx.tsx.js";
export * as blank from "./blank.vue.js";
export * as scriptSetupTS from "./script-setup-ts.vue.js";
export * as scriptMultiBlock from "./script-multi-block.vue.js";
export * as ts from "./ts.vue.js";
"
`);

expect(
await readFile(resolve(rootDir, "dist/components/ts.vue.d.ts"), "utf8"),
).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -221,6 +241,7 @@ describe("mkdist", () => {
"dist/types.d.ts",
"dist/star/index.mjs",
"dist/star/other.mjs",
"dist/components/index.mjs",
"dist/components/blank.vue",
"dist/components/js.vue",
"dist/components/script-multi-block.vue",
Expand Down Expand Up @@ -468,6 +489,8 @@ describe("mkdist with vue-tsc v1", () => {
"dist/star/other.mjs",
"dist/star/other.d.ts",
"dist/types.d.ts",
"dist/components/index.mjs",
"dist/components/index.d.ts",
"dist/components/blank.vue",
"dist/components/js.vue",
"dist/components/js.vue.d.ts",
Expand Down Expand Up @@ -507,6 +530,18 @@ describe("mkdist with vue-tsc v1", () => {
await readFile(resolve(rootDir, "dist/bar/esm.d.mts"), "utf8"),
).toMatch("declare");

expect(
await readFile(resolve(rootDir, "dist/components/index.d.ts"), "utf8"),
).toMatchInlineSnapshot(`
"export * as jsx from "./jsx.jsx.js";
export * as tsx from "./tsx.tsx.js";
export * as blank from "./blank.vue.js";
export * as scriptSetupTS from "./script-setup-ts.vue.js";
export * as scriptMultiBlock from "./script-multi-block.vue.js";
export * as ts from "./ts.vue.js";
"
`);

expect(
await readFile(resolve(rootDir, "dist/components/ts.vue.d.ts"), "utf8"),
).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -585,6 +620,8 @@ describe("mkdist with vue-tsc ~v2.0.21", () => {
"dist/star/other.mjs",
"dist/star/other.d.ts",
"dist/types.d.ts",
"dist/components/index.mjs",
"dist/components/index.d.ts",
"dist/components/blank.vue",
"dist/components/js.vue",
"dist/components/js.vue.d.ts",
Expand Down Expand Up @@ -624,6 +661,18 @@ describe("mkdist with vue-tsc ~v2.0.21", () => {
await readFile(resolve(rootDir, "dist/bar/esm.d.mts"), "utf8"),
).toMatch("declare");

expect(
await readFile(resolve(rootDir, "dist/components/index.d.ts"), "utf8"),
).toMatchInlineSnapshot(`
"export * as jsx from "./jsx.jsx.js";
export * as tsx from "./tsx.tsx.js";
export * as blank from "./blank.vue.js";
export * as scriptSetupTS from "./script-setup-ts.vue.js";
export * as scriptMultiBlock from "./script-multi-block.vue.js";
export * as ts from "./ts.vue.js";
"
`);

expect(
await readFile(resolve(rootDir, "dist/components/ts.vue.d.ts"), "utf8"),
).toMatchInlineSnapshot(`
Expand Down

0 comments on commit eb495b0

Please sign in to comment.