Skip to content

Commit 811d3f4

Browse files
committed
test: add buffer handling test and implement getBuffer function
1 parent d5f9ed8 commit 811d3f4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/__tests__/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ describe("Raw plugin", () => {
3636
expect(generatedCodeContent2.toString("base64")).toBe(fileContent.toString("base64"));
3737
});
3838

39+
test("test buffer", async ({ expect }) => {
40+
await esbuild.build({ ...buildOptions, entryPoints: [path.resolve(__dirname, "test4.ts")] });
41+
const fileContent = fs.readFileSync(path.resolve(__dirname, "../src/index.ts"));
42+
// @ts-ignore
43+
const generatedCodeContent = (await import("./dist/test4.js")).getBuffer();
44+
// @ts-ignore
45+
expect(Buffer.from(generatedCodeContent).toString("base64")).toBe(
46+
fileContent.toString("base64"),
47+
);
48+
});
49+
3950
test("throws error if no file is found", async ({ expect }) => {
4051
let didThrow = false;
4152
try {

lib/__tests__/test4.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// test auto complete
2+
3+
import buffer from "../src?binary";
4+
5+
export const getBuffer = () => buffer;

0 commit comments

Comments
 (0)