diff options
Diffstat (limited to 'test/bun.js/third-party/body-parser-test')
| -rwxr-xr-x | test/bun.js/third-party/body-parser-test/bun.lockb | bin | 0 -> 20925 bytes | |||
| -rw-r--r-- | test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts | 61 | ||||
| -rw-r--r-- | test/bun.js/third-party/body-parser-test/package.json | 9 |
3 files changed, 70 insertions, 0 deletions
diff --git a/test/bun.js/third-party/body-parser-test/bun.lockb b/test/bun.js/third-party/body-parser-test/bun.lockb Binary files differnew file mode 100755 index 000000000..6fdd6d093 --- /dev/null +++ b/test/bun.js/third-party/body-parser-test/bun.lockb diff --git a/test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts b/test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts new file mode 100644 index 000000000..905cc4ce2 --- /dev/null +++ b/test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts @@ -0,0 +1,61 @@ +import { test, expect } from "bun:test"; +import express, { Application, Request, Response } from "express"; +import { json } from "body-parser"; + +// Express uses iconv-lite +test("iconv works", () => { + var iconv = require("iconv-lite"); + + // Convert from an encoded buffer to a js string. + var str = iconv.decode( + Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f]), + "win1251", + ); + + // Convert from a js string to an encoded buffer. + var buf = iconv.encode("Sample input string", "win1251"); + expect(str).toBe("hello"); + expect(iconv.decode(buf, "win1251")).toBe("Sample input string"); + + // Check if encoding is supported + expect(iconv.encodingExists("us-ascii")).toBe(true); +}); + +// https://github.com/oven-sh/bun/issues/1913 +test("httpServer", async (done) => { + // Constants + const PORT = 8412; + + // App handlers + const app: Application = express(); + const httpServer = require("http").createServer(app); + + app.on("error", (err) => { + done(err); + }); + app.use(json()); + + var reached = false; + // This throws a TypeError since it uses body-parser.json + app.post("/ping", (request: Request, response: Response) => { + expect(request.body).toEqual({ hello: "world" }); + reached = true; + response.status(200).send("POST - pong"); + httpServer.close(); + done(); + }); + + httpServer.listen(PORT); + const resp = await fetch(`http://localhost:${PORT}/ping`, { + method: "POST", + body: JSON.stringify({ hello: "world" }), + headers: { + "Content-Type": "application/json", + }, + }); + + expect(resp.status).toBe(200); + expect(await resp.text()).toBe("POST - pong"); + expect(reached).toBe(true); + done(); +}); diff --git a/test/bun.js/third-party/body-parser-test/package.json b/test/bun.js/third-party/body-parser-test/package.json new file mode 100644 index 000000000..0dfa98c59 --- /dev/null +++ b/test/bun.js/third-party/body-parser-test/package.json @@ -0,0 +1,9 @@ +{ + "name": "body-parser-test", + "version": "1.0.0", + "dependencies": { + "express": "4.18.2", + "body-parser": "1.20.1", + "iconv-lite": "0.6.3" + } +} |
