diff --git a/llrt_core/src/modules/js/@llrt/test/index.ts b/llrt_core/src/modules/js/@llrt/test/index.ts index 0e093aa983..deb121c81a 100644 --- a/llrt_core/src/modules/js/@llrt/test/index.ts +++ b/llrt_core/src/modules/js/@llrt/test/index.ts @@ -179,6 +179,20 @@ class TestServer { socket.on("error", (error) => { const workerId = this.workerIdBySocket.get(socket); if (!workerId || !this.workerData[workerId].completed) { + if (workerId) { + const workerData = this.workerData[workerId]; + const stdErr = workerData.stdErrBuffer.getContent().toString(); + const stdOut = workerData.stdOutBuffer.getContent().toString(); + let errorOutput = Color.RED_BACKGROUND(Color.BOLD("Worker Error:\n")); + + if (stdErr) { + errorOutput += Color.RED(`\nStd Err:\n${stdErr}`); + } + if (stdOut) { + errorOutput += Color.RED(`\nStd Out:\n${stdOut}`); + } + console.error(errorOutput); + } this.handleError(TestServer.ERROR_CODE_SOCKET_ERROR, error, { socket, }); diff --git a/tests/unit/dns.test.ts b/tests/unit/dns.test.ts index 816e8207dd..1a367ecc84 100644 --- a/tests/unit/dns.test.ts +++ b/tests/unit/dns.test.ts @@ -1,54 +1,51 @@ -const dns = require("dns"); +import dns from "dns"; -describe("lookup", () => { - it("localhost name resolution should be possible (optionless)", (done) => { - dns.lookup("localhost", (err, address, family) => { - expect(err).toBeNull(); - expect(address === "::1" || address === "127.0.0.1").toBeTruthy(); - expect(family === 4 || family === 6).toBeTruthy(); - done(); +// Promise wrapper for dns.lookup +const dnsLookupAsync = ( + hostname: string, + options?: number | dns.LookupOptions +) => + new Promise((resolve, reject) => { + dns.lookup(hostname, options as any, (err, address, family) => { + if (err) reject(err); + else resolve({ address, family }); }); }); - it("Name resolution for localhost2 should result in an error (optionless)", () => { - dns.lookup("localhost2", (err, address, family) => { - expect(err.message).toEqual( - "failed to lookup address information: nodename nor servname provided, or not known" - ); - }); +describe("lookup", () => { + it("localhost name resolution should be possible (optionless)", async () => { + const { address, family } = await dnsLookupAsync("localhost"); + expect(address === "::1" || address === "127.0.0.1").toBeTruthy(); + expect(family === 4 || family === 6).toBeTruthy(); }); - it("localhost name resolution should be possible (integer option)", (done) => { - dns.lookup("localhost", 4, (err, address, family) => { - expect(err).toBeNull(); - expect(address).toEqual("127.0.0.1"); - expect(family).toEqual(4); - done(); - }); + it("localhost name resolution should be possible (integer option)", async () => { + const { address, family } = await dnsLookupAsync("localhost", 4); + expect(address).toEqual("127.0.0.1"); + expect(family).toEqual(4); }); - it("Name resolution for localhost2 should result in an error (integer option)", () => { - dns.lookup("localhost2", 4, (err, address, family) => { - expect(err.message).toEqual( - "failed to lookup address information: nodename nor servname provided, or not known" - ); + it("localhost name resolution should be possible (record option)", async () => { + const { address, family } = await dnsLookupAsync("localhost", { + family: 4, }); + expect(address).toEqual("127.0.0.1"); + expect(family).toEqual(4); }); - it("localhost name resolution should be possible (record option)", (done) => { - dns.lookup("localhost", { family: 4 }, (err, address, family) => { - expect(err).toBeNull(); - expect(address).toEqual("127.0.0.1"); - expect(family).toEqual(4); - done(); + if (process.platform !== "linux") { + it("Name resolution for localhost2 should result in an error (integer option)", async () => { + await expect(dnsLookupAsync("localhost2", 4)).rejects.toThrow("known"); }); - }); - it("Name resolution for localhost2 should result in an error (record option)", () => { - dns.lookup("localhost2", { family: 4 }, (err, address, family) => { - expect(err.message).toEqual( - "failed to lookup address information: nodename nor servname provided, or not known" + it("Name resolution for localhost2 should result in an error (optionless)", async () => { + await expect(dnsLookupAsync("localhost2")).rejects.toThrow("known"); + }); + + it("Name resolution for localhost2 should result in an error (record option)", async () => { + await expect(dnsLookupAsync("localhost2", { family: 4 })).rejects.toThrow( + "known" ); }); - }); + } });