Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
57 changes: 57 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -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()}`)
})
})
Loading