diff --git a/src/commands/repl.ts b/src/commands/repl.ts index 342a4ce..c0d4000 100644 --- a/src/commands/repl.ts +++ b/src/commands/repl.ts @@ -34,7 +34,10 @@ export default async function (autoImportPath: string | undefined, options: Opti logger.info(`Initializing Wollok REPL ${autoImportPath ? `for file ${valueDescription(autoImportPath)} ` : ''}on ${valueDescription(options.project)}`) let interpreter = await initializeInterpreter(autoImportPath, options) - const io: Server | undefined = options.noDiagram ? undefined : await initializeClient(options) + const _ = options.noDiagram ? undefined : await initializeClient(options) + + const io = _?.io + const server = _?.server const commandHandler = defineCommands(autoImportPath, options, () => { io?.emit('updateDiagram', getDataDiagram(interpreter)) @@ -67,10 +70,11 @@ export default async function (autoImportPath: string | undefined, options: Opti repl.prompt() }) - io?.on('connection', _socket => { + server?.addListener('listening', () => { logger.info(successDescription('Dynamic diagram available at: ' + bold(`http://localhost:${options.port}`))) repl.prompt() }) + io?.on('connection', socket => { socket.emit('initDiagram', options) socket.emit('updateDiagram', getDataDiagram(interpreter)) @@ -238,7 +242,7 @@ async function initializeClient(options: Options) { express.static(publicPath('diagram'), { maxAge: '1d' }), ) server.listen(parseInt(options.port), 'localhost') - return io + return { server, io } } function newImport(importNode: Import, environment: Environment) { diff --git a/test/test.test.ts b/test/test.test.ts index beac864..fa0b2e8 100644 --- a/test/test.test.ts +++ b/test/test.test.ts @@ -282,6 +282,7 @@ describe('Test', () => { expect(processExitSpy.callCount).to.equal(0) expect(spyCalledWithSubstring(loggerInfoSpy, 'Running 2 tests')).to.be.true expect(spyCalledWithSubstring(loggerInfoSpy, '2 passing')).to.be.true + expect(spyCalledWithSubstring(loggerInfoSpy, '0 failing')).to.be.false // old version }) it('returns exit code 2 if one or more tests fail', async () => {