diff --git a/packages/testkit-backend/rollup.config.js b/packages/testkit-backend/rollup.config.js index ae5295236..6b9337997 100644 --- a/packages/testkit-backend/rollup.config.js +++ b/packages/testkit-backend/rollup.config.js @@ -3,6 +3,11 @@ import commonjs from '@rollup/plugin-commonjs' import polyfillNode from 'rollup-plugin-polyfill-node' import injectProcessEnv from 'rollup-plugin-inject-process-env' +function getDescriptor () { + const currentDescriptor = process.env.DRIVER_DESCRIPTOR || '' + return currentDescriptor + ',browser' +} + export default { input: 'src/index.js', output: { @@ -22,6 +27,7 @@ export default { ...process.env, TEST_ENVIRONMENT: 'LOCAL', CHANNEL_TYPE: 'WEBSOCKET', + DRIVER_DESCRIPTOR: getDescriptor(), BACKEND_PORT: process.env.WEB_SERVER_PORT || 8000 }) ] diff --git a/packages/testkit-backend/src/context.js b/packages/testkit-backend/src/context.js index e57c8649b..c13bff92e 100644 --- a/packages/testkit-backend/src/context.js +++ b/packages/testkit-backend/src/context.js @@ -1,5 +1,5 @@ export default class Context { - constructor () { + constructor (shouldRunTest) { this._id = 0 this._drivers = {} this._sessions = {} @@ -7,6 +7,7 @@ export default class Context { this._resolverRequests = {} this._resultObservers = {} this._errors = {} + this._shouldRunTest = shouldRunTest } addDriver (driver) { @@ -98,6 +99,10 @@ export default class Context { return Object.values(this._txs).filter(tx => tx.sessionId === sessionId) } + getShouldRunTestFunction() { + return this._shouldRunTest + } + _add (map, object) { this._id++ map[this._id] = object diff --git a/packages/testkit-backend/src/controller/local.js b/packages/testkit-backend/src/controller/local.js index aed4a4a80..1c59ede1b 100644 --- a/packages/testkit-backend/src/controller/local.js +++ b/packages/testkit-backend/src/controller/local.js @@ -9,14 +9,15 @@ import Controller from './interface' */ export default class LocalController extends Controller { - constructor(requestHandlers = {}) { + constructor(requestHandlers = {}, shouldRunTest = () => {}) { super() this._requestHandlers = requestHandlers + this._shouldRunTest = shouldRunTest this._contexts = new Map() } openContext (contextId) { - this._contexts.set(contextId, new Context()) + this._contexts.set(contextId, new Context(this._shouldRunTest)) } closeContext (contextId) { diff --git a/packages/testkit-backend/src/index.js b/packages/testkit-backend/src/index.js index e4f3928f7..0f2db7c53 100644 --- a/packages/testkit-backend/src/index.js +++ b/packages/testkit-backend/src/index.js @@ -1,6 +1,7 @@ import Backend from './backend' import { SocketChannel, WebSocketChannel } from './channel' import { LocalController, RemoteController } from './controller' +import { getShouldRunTest } from './skipped-tests' import * as REQUEST_HANDLERS from './request-handlers' /** @@ -11,6 +12,11 @@ function main( ) { const channelType = process.env.CHANNEL_TYPE || 'SOCKET' const backendPort = process.env.BACKEND_PORT || 9876 const webserverPort = process.env.WEB_SERVER_PORT || 8000 + const driverDescriptor = process.env.DRIVER_DESCRIPTOR || '' + const driverDescriptorList = driverDescriptor + .split(',').map(s => s.trim().toLowerCase()) + + const shouldRunTest = getShouldRunTest(driverDescriptorList) const newChannel = () => { if ( channelType.toUpperCase() === 'WEBSOCKET' ) { @@ -24,7 +30,7 @@ function main( ) { if ( testEnviroment.toUpperCase() === 'REMOTE' ) { return new RemoteController(webserverPort) } - return new LocalController(REQUEST_HANDLERS) + return new LocalController(REQUEST_HANDLERS, shouldRunTest) } const backend = new Backend(newController, newChannel) @@ -39,7 +45,10 @@ function main( ) { process.on('SIGINT', process.exit.bind(process)); process.on('SIGUSR1', process.exit.bind(process)); process.on('SIGUSR2', process.exit.bind(process)); - process.on('uncaughtException', process.exit.bind(process)); + process.on('uncaughtException', exception => { + console.error('UncaughtException', exception) + process.exit() + }); } } diff --git a/packages/testkit-backend/src/request-handlers.js b/packages/testkit-backend/src/request-handlers.js index 5587eb5b5..1d1fd43d5 100644 --- a/packages/testkit-backend/src/request-handlers.js +++ b/packages/testkit-backend/src/request-handlers.js @@ -1,7 +1,6 @@ import neo4j from './neo4j' import ResultObserver from './result-observer.js' import { cypherToNative, nativeToCypher } from './cypher-native-binders.js' -import { shouldRunTest } from './skipped-tests' import tls from 'tls' const SUPPORTED_TLS = (() => { @@ -302,7 +301,8 @@ export function SessionWriteTransaction (context, data, wire) { .catch(error => wire.writeError(error)) } -export function StartTest (_, { testName }, wire) { +export function StartTest (context, { testName }, wire) { + const shouldRunTest = context.getShouldRunTestFunction() shouldRunTest(testName, { onRun: () => wire.writeResponse('RunTest', null), onSkip: reason => wire.writeResponse('SkipTest', { reason }) diff --git a/packages/testkit-backend/src/skipped-tests/browser.js b/packages/testkit-backend/src/skipped-tests/browser.js new file mode 100644 index 000000000..036029007 --- /dev/null +++ b/packages/testkit-backend/src/skipped-tests/browser.js @@ -0,0 +1,13 @@ +import skip, { ifStartsWith } from './skip' +const skippedTests = [ + skip( + 'Stub Tests not implemented for browser', + ifStartsWith('stub') + ), + skip( + 'TLS Tests not implemented for browwer', + ifStartsWith('tls') + ) +] + +export default skippedTests diff --git a/packages/testkit-backend/src/skipped-tests.js b/packages/testkit-backend/src/skipped-tests/common.js similarity index 83% rename from packages/testkit-backend/src/skipped-tests.js rename to packages/testkit-backend/src/skipped-tests/common.js index 778acf6c3..2e888e054 100644 --- a/packages/testkit-backend/src/skipped-tests.js +++ b/packages/testkit-backend/src/skipped-tests/common.js @@ -1,22 +1,4 @@ -function ifEndsWith (suffix) { - return testName => testName.endsWith(suffix) -} - -function ifStartsWith (prefix) { - return testName => testName.startsWith(prefix) -} - -function ifEquals (expectedName) { - return testName => testName === expectedName -} - -function or () { - return testName => [...arguments].find(predicate => predicate(testName)) -} - -function skip (reason, ...predicate) { - return { reason, predicate: or(...predicate) } -} +import skip, { ifEquals, ifEndsWith } from './skip' const skippedTests = [ skip( @@ -109,8 +91,4 @@ const skippedTests = [ ) ] -export function shouldRunTest (testName, { onRun, onSkip }) { - const { reason } = - skippedTests.find(({ predicate }) => predicate(testName)) || {} - !reason ? onRun() : onSkip(reason) -} +export default skippedTests diff --git a/packages/testkit-backend/src/skipped-tests/index.js b/packages/testkit-backend/src/skipped-tests/index.js new file mode 100644 index 000000000..946f114ba --- /dev/null +++ b/packages/testkit-backend/src/skipped-tests/index.js @@ -0,0 +1,19 @@ +import commonSkippedTests from './common' +import browserSkippedTests from './browser' + +const skippedTestsByContext = new Map([ + ['browser', browserSkippedTests] +]) + +export function getShouldRunTest (contexts) { + const skippedTests = contexts + .filter(context => skippedTestsByContext.has(context)) + .map(context => skippedTestsByContext.get(context)) + .reduce((previous, current) => [ ...previous, ...current ], commonSkippedTests) + + return (testName, { onRun, onSkip }) => { + const { reason } = + skippedTests.find(({ predicate }) => predicate(testName)) || {} + !reason ? onRun() : onSkip(reason) + } +} diff --git a/packages/testkit-backend/src/skipped-tests/skip.js b/packages/testkit-backend/src/skipped-tests/skip.js new file mode 100644 index 000000000..adb997a97 --- /dev/null +++ b/packages/testkit-backend/src/skipped-tests/skip.js @@ -0,0 +1,21 @@ +export function ifEndsWith (suffix) { + return testName => testName.endsWith(suffix) +} + +export function ifStartsWith (prefix) { + return testName => testName.startsWith(prefix) +} + +export function ifEquals (expectedName) { + return testName => testName === expectedName +} + +export function or () { + return testName => [...arguments].find(predicate => predicate(testName)) +} + +export function skip (reason, ...predicate) { + return { reason, predicate: or(...predicate) } +} + +export default skip