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/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 4cc6a17..dc13d30 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,5 +1,9 @@ +const { spawn } = require('child_process') +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') @@ -273,3 +277,56 @@ test('cannot change the offset', async t => { t.pass('rebuilding with different offset should throw') } }) + +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') + + 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()}`) + }) +})