Skip to content

Commit

Permalink
Working basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewosh committed Sep 10, 2024
1 parent 490d991 commit 80869b6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build Status
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
strategy:
matrix:
node-version: [lts/*]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
4 changes: 2 additions & 2 deletions lib/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function generateCode (hyperswitch) {
str += ` return this._handler${handler.id}(resolveStruct(${s(handler.requestType)}).decode(state))\n`
}
str += ' default:\n'
str += ' throw new Error(\'Handler not found for ID:\' + message.id)\n'
str += ' throw new Error(\'Handler not found for ID:\' + id)\n'
str += ' }\n'
str += ' }\n'
str += '}\n'
Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports = function generateCode (hyperswitch) {
str += ' }\n'
}
str += ' default:\n'
str += ' throw new Error(\'Handler not found for name:\' + name)\n'
str += ' throw new Error(\'Handler not found for name: \' + name)\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 @@ -22,7 +22,8 @@
"homepage": "https://github.com/holepunchto/hyperswitch#readme",
"devDependencies": {
"brittle": "^3.7.0",
"standard": "^17.1.0"
"standard": "^17.1.0",
"test-tmp": "^1.3.0"
},
"dependencies": {
"b4a": "^1.6.6",
Expand Down
52 changes: 52 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const test = require('brittle')

const { createTestSchema } = require('./helpers')

test('basic sync switch', async t => {
t.plan(4)

const hs = await createTestSchema(t)
hs.rebuild({
schema: schema => {
const ns = schema.namespace('test')
ns.register({
name: 'request',
fields: [
{
name: 'id',
type: 'uint'
},
{
name: 'str',
type: 'string'
}
]
})
},
switch: hyperswitch => {
const ns = hyperswitch.namespace('test')
ns.register({
name: 'test-request-1',
requestType: '@test/request'
})
ns.register({
name: 'test-request-2',
requestType: '@test/request'
})
}
})
const { dispatch, Router } = hs.module

const r = new Router()
r.add('@test/test-request-1', req => {
t.is(req.id, 10)
t.is(req.str, 'hello')
})
r.add('@test/test-request-2', req => {
t.is(req.id, 20)
t.is(req.str, 'world')
})

r.dispatch(dispatch('@test/test-request-1', { id: 10, str: 'hello' }))
r.dispatch(dispatch('@test/test-request-2', { id: 20, str: 'world' }))
})
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This runner is auto-generated by Brittle

runTests()

async function runTests () {
const test = (await import('brittle')).default

test.pause()

await import('./basic.js')

test.resume()
}

0 comments on commit 80869b6

Please sign in to comment.