Skip to content

Instantly share code, notes, and snippets.

@drazisil
Last active May 30, 2024 15:40
Show Gist options
  • Save drazisil/e2352cd4e3dad9ea8b3121f15e1462a5 to your computer and use it in GitHub Desktop.
Save drazisil/e2352cd4e3dad9ea8b3121f15e1462a5 to your computer and use it in GitHub Desktop.
[email protected] test
> vitest run
RUN v1.6.0 /home/drazisil/projects/probable-spoon
❯ test/connections.spec.js (1) 5009ms
❯ TCPServer (1) 5008ms
× should return an error if the port is in use 5008ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL test/connections.spec.js > TCPServer > should return an error if the port is in use
Error: Test timed out in 5000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Uncaught Exception ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: listen EACCES: permission denied 0.0.0.0:80
❯ Server.setupListenHandle [as _listen2] node:net:1880:21
❯ listenInCluster node:net:1945:12
❯ Server.listen node:net:2037:7
❯ TCPServer.listen src/index.js:87:17
85|
86| listen() {
87| this.server.listen(this.port);
| ^
88| }
89| }
❯ test/connections.spec.js:17:7
❯ test/connections.spec.js:6:60
❯ node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:135:14
❯ node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:60:26
❯ runTest node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:781:17
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'EACCES', errno: -13, syscall: 'listen', address: '0.0.0.0', port: 80 }
This error originated in "test/connections.spec.js" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "should return an error if the port is in use". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Test Files 1 failed (1)
Tests 1 failed (1)
Errors 1 error
Start at 11:38:52
Duration 5.27s (transform 19ms, setup 0ms, collect 12ms, tests 5.01s, environment 0ms, prepare 68ms)
import { describe, expect, it, vi } from "vitest";
import { TCPServer } from "../src/index.js";
describe("TCPServer", () => {
it("should return an error if the port is in use", () => new Promise(done => {
const onListening = vi.fn();
const onConnection = vi.fn();
const onServerError = vi.fn().mockImplementation((err) => {
expect(err).toMatch(/EADDRINUSE/);
done;
});
console.error = vi.fn();
const s = new TCPServer(80, onListening, onConnection, onServerError);
s.listen();
}));
});
export class TCPServer {
/**
*
* @param {number} port
* @param {function(net.Server): void} onListening
* @param {function(net.Socket): void} onConnection
* @param {function(Error): void} onServerError
*/
constructor(port, onListening, onConnection, onServerError) {
this.port = port;
this.server = net.createServer(onConnection);
// this.server.on("error", onServerError);
this.server.on("listening", onListening);
}
listen() {
this.server.listen(this.port);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment