diff --git a/packages/testkit-backend/src/backend.js b/packages/testkit-backend/src/backend.js index f1f8983cd..80fc63265 100644 --- a/packages/testkit-backend/src/backend.js +++ b/packages/testkit-backend/src/backend.js @@ -25,7 +25,7 @@ export default class Backend { try { this._controller.handle(contextId, request) } catch (e) { - this._channel.writeBackendError(contextId, e) + this._channel.writeBackendError(contextId, e.message) } }) } diff --git a/packages/testkit-backend/src/channel/testkit-protocol.js b/packages/testkit-backend/src/channel/testkit-protocol.js index bacc41e64..1670566a3 100644 --- a/packages/testkit-backend/src/channel/testkit-protocol.js +++ b/packages/testkit-backend/src/channel/testkit-protocol.js @@ -1,5 +1,6 @@ import readline from 'readline' import EventEmitter from 'events' +import stringify from '../stringify' export default class Protocol extends EventEmitter { constructor (stream) { @@ -61,7 +62,7 @@ export default class Protocol extends EventEmitter { serializeResponse (response) { console.log('> writing response', response) - const responseStr = this._stringify(response) + const responseStr = stringify(response) return ['#response begin', responseStr, '#response end'].join('\n') + '\n' } @@ -72,9 +73,4 @@ export default class Protocol extends EventEmitter { this.emit('request', { name, data }) } - _stringify (val) { - return JSON.stringify(val, (_, value) => - typeof value === 'bigint' ? `${value}n` : value - ) - } } diff --git a/packages/testkit-backend/src/controller/local.js b/packages/testkit-backend/src/controller/local.js index 1c59ede1b..ae2638e51 100644 --- a/packages/testkit-backend/src/controller/local.js +++ b/packages/testkit-backend/src/controller/local.js @@ -1,5 +1,6 @@ import Context from '../context' import Controller from './interface' +import stringify from '../stringify' /** diff --git a/packages/testkit-backend/src/stringify.js b/packages/testkit-backend/src/stringify.js new file mode 100644 index 000000000..996e6dad4 --- /dev/null +++ b/packages/testkit-backend/src/stringify.js @@ -0,0 +1,5 @@ +export default function stringify(json) { + return JSON.stringify(json, (_, value) => + typeof value === 'bigint' ? `${value}n` : value + ) +}