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
17 changes: 15 additions & 2 deletions packages/testkit-backend/deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import channel from "./channel.ts";
import controller from "./controller.ts";
import { RequestHandlerMap } from "./domain.ts";
import util from "node:util";

const requestHandlers: RequestHandlerMap = handlers as RequestHandlerMap;

Expand All @@ -26,11 +27,23 @@ const binder = new CypherNativeBinders(neo4j);
const descriptor = ["async", "deno"];
const shouldRunTest = getShouldRunTest(descriptor);
const getFeatures = createGetFeatures(descriptor);
const logLevel = Deno.env.get("TEST_LOG_LEVEL");
const logLevel = Deno.env.get("TEST_LOG_LEVEL") ?? "info";
const createContext = () =>
new Context(shouldRunTest, getFeatures, binder, logLevel);

configurableConsole.install(logLevel);
const logWrapper = (...args) => {
let output = args.map((arg) => {
if (typeof arg === "string") return arg;
return util.inspect(arg, { colors: Deno.stdout.isTTY });
}).join(" ") + "\n";
if (output.length > 1000 * 2 + 3) {
output = output.substring(0, 1000) + "..." +
output.substring(output.length - 1000);
}
Deno.stdout.write(new TextEncoder().encode(output));
};

configurableConsole.install(logLevel, logWrapper);
const listener = channel.listen(9876);
const handle = controller.createHandler(neo4j, createContext, requestHandlers);

Expand Down
4 changes: 3 additions & 1 deletion packages/testkit-backend/src/channel/testkit-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export default class Protocol extends EventEmitter {
}

serializeResponse (response) {
const { name, data } = response
const responseStr = stringify(response)
console.log('> writing response', responseStr)
console.log('> writing response' + name)
console.debug(data)
return ['#response begin', responseStr, '#response end'].join('\n') + '\n'
}

Expand Down
8 changes: 6 additions & 2 deletions packages/testkit-backend/src/console.configurable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ const config = {
}

export default {
install (level = 'info') {
install (level = 'info', logWrapper) {
this.setLevel(level)
// eslint-disable-next-line no-global-assign
console = new Proxy({}, {
get: (_, method) => (...args) => {
if (config.canRun(method)) {
originalConsole[method].apply(originalConsole, args)
if (logWrapper != null) {
logWrapper(...args)
} else {
originalConsole[method].apply(originalConsole, args)
}
}
}
})
Expand Down
13 changes: 12 additions & 1 deletion packages/testkit-backend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as REQUEST_HANDLERS from './request-handlers.js'
import * as RX_REQUEST_HANDLERS from './request-handlers-rx.js'
import remoteConsole from './console.remote.js'
import configurableConsole from './console.configurable.js'
import util from 'util'

const SUPPORTED_TLS = (() => {
if (tls.DEFAULT_MAX_VERSION) {
Expand Down Expand Up @@ -40,7 +41,17 @@ function main () {
const shouldRunTest = getShouldRunTest([...driverDescriptorList, sessionTypeDescriptor])
const getFeatures = createGetFeatures([sessionTypeDescriptor], SUPPORTED_TLS)

configurableConsole.install(process.env.TEST_LOG_LEVEL || 'info')
const logWrapper = (...args) => {
let output = args.map(arg => {
if (typeof arg === 'string') return arg
return util.inspect(arg, { colors: process.stdout.isTTY })
}).join(' ') + '\n'
if (output.length > 1000 * 2 + 3) {
output = output.substring(0, 1000) + '...' + output.substring(output.length - 1000)
}
process.stdout.write(output)
}
configurableConsole.install(process.env.TEST_LOG_LEVEL || 'info', logWrapper)

const newChannel = () => {
if (channelType.toUpperCase() === 'WEBSOCKET') {
Expand Down