From d50dc12a9141528b3d695c46f3e321efa6a333b4 Mon Sep 17 00:00:00 2001 From: HDegroote <75906619+HDegroote@users.noreply.github.com> Date: Wed, 13 Aug 2025 16:38:17 +0200 Subject: [PATCH 1/4] Fix dispatch code generation + add lint check on generated code --- lib/codegen.js | 2 +- test/basic.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/codegen.js b/lib/codegen.js index 38de11c..3040975 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -61,7 +61,7 @@ module.exports = function generateCode (hyperdispatch, { esm = false }) { str += ` return this._handler${handler.id}(op.value, context)\n` } str += ' default:\n' - str += ' throw new Error(\'Handler not found for ID:\' + id)\n' + str += ' throw new Error(\'Handler not found for ID:\' + op.id)\n' str += ' }\n' str += ' }\n' str += '}\n' diff --git a/test/basic.js b/test/basic.js index 4cc6a17..fa786d8 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,3 +1,6 @@ +const { spawn } = require('child_process') +const process = require('process') +const path = require('path') const test = require('brittle') const c = require('compact-encoding') @@ -273,3 +276,51 @@ test('cannot change the offset', async t => { t.pass('rebuilding with different offset should throw') } }) + +test('test schema passes linter', async t => { + t.plan(1) + const hd = await createTestSchema(t) + const dispatchDir = path.join(hd.dir, 'hyperdispatch') + + hd.rebuild({ + schema: schema => { + const ns = schema.namespace('test') + ns.register({ + name: 'request', + fields: [ + { + name: 'id', + type: 'uint' + }, + { + name: 'str', + type: 'string' + } + ] + }) + }, + dispatch: hyperdispatch => { + const ns = hyperdispatch.namespace('test') + ns.register({ + name: 'test-request-1', + requestType: '@test/request' + }) + ns.register({ + name: 'test-request-2', + requestType: '@test/request' + }) + } + }) + + const exProc = spawn('npx', ['standard', dispatchDir]) + exProc.on('close', (status) => { + t.is(status, 0, 'linter detected no issues') + }) + + // In case the test is aborted, we kill the standard process + process.on('exit', () => { exProc.kill('SIGKILL') }) + + exProc.stderr.on('data', d => { + console.error(`[linter error output] ${d.toString()}`) + }) +}) From db0c88f104062a9931c0637b3d4cd3bfba2d9281 Mon Sep 17 00:00:00 2001 From: HDegroote <75906619+HDegroote@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:17:54 +0200 Subject: [PATCH 2/4] Directly call binary --- test/basic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basic.js b/test/basic.js index fa786d8..4cfc288 100644 --- a/test/basic.js +++ b/test/basic.js @@ -312,7 +312,7 @@ test('test schema passes linter', async t => { } }) - const exProc = spawn('npx', ['standard', dispatchDir]) + const exProc = spawn('./node_modules/.bin/standard', [dispatchDir]) exProc.on('close', (status) => { t.is(status, 0, 'linter detected no issues') }) From 0a6c9c46235d8ee6d2535cb6e2632fd540cff7b9 Mon Sep 17 00:00:00 2001 From: HDegroote <75906619+HDegroote@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:21:55 +0200 Subject: [PATCH 3/4] Try with full path --- test/basic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basic.js b/test/basic.js index 4cfc288..dea7027 100644 --- a/test/basic.js +++ b/test/basic.js @@ -312,7 +312,7 @@ test('test schema passes linter', async t => { } }) - const exProc = spawn('./node_modules/.bin/standard', [dispatchDir]) + const exProc = spawn(path.join(path.dirname(__dirname), 'node_modules', '.bin', 'standard'), [dispatchDir]) exProc.on('close', (status) => { t.is(status, 0, 'linter detected no issues') }) From 6436b4845e76b85fcfecb76850bfdeb997fc255c Mon Sep 17 00:00:00 2001 From: HDegroote <75906619+HDegroote@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:25:46 +0200 Subject: [PATCH 4/4] Skip test for windows --- package.json | 3 ++- test/basic.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 02ad5f5..3b24667 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "devDependencies": { "brittle": "^3.7.0", "standard": "^17.1.0", - "test-tmp": "^1.3.0" + "test-tmp": "^1.3.0", + "which-runtime": "^1.3.0" }, "dependencies": { "b4a": "^1.6.7", diff --git a/test/basic.js b/test/basic.js index dea7027..dc13d30 100644 --- a/test/basic.js +++ b/test/basic.js @@ -3,6 +3,7 @@ const process = require('process') const path = require('path') const test = require('brittle') const c = require('compact-encoding') +const whichRuntime = require('which-runtime') const { createTestSchema } = require('./helpers') @@ -278,6 +279,11 @@ test('cannot change the offset', async t => { }) test('test schema passes linter', async t => { + if (whichRuntime.isWindows) { + t.comment('Skipped on windows because standard does not seem to run out of the box') + return + } + t.plan(1) const hd = await createTestSchema(t) const dispatchDir = path.join(hd.dir, 'hyperdispatch') @@ -312,7 +318,7 @@ test('test schema passes linter', async t => { } }) - const exProc = spawn(path.join(path.dirname(__dirname), 'node_modules', '.bin', 'standard'), [dispatchDir]) + const exProc = spawn('npx', ['standard', dispatchDir]) exProc.on('close', (status) => { t.is(status, 0, 'linter detected no issues') })