Skip to content

Commit 6cfe463

Browse files
authored
testkit-backend: Enabling skip different tests for browser and node (#819)
1 parent 227ae86 commit 6cfe463

File tree

9 files changed

+83
-31
lines changed

9 files changed

+83
-31
lines changed

packages/testkit-backend/rollup.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import commonjs from '@rollup/plugin-commonjs'
33
import polyfillNode from 'rollup-plugin-polyfill-node'
44
import injectProcessEnv from 'rollup-plugin-inject-process-env'
55

6+
function getDescriptor () {
7+
const currentDescriptor = process.env.DRIVER_DESCRIPTOR || ''
8+
return currentDescriptor + ',browser'
9+
}
10+
611
export default {
712
input: 'src/index.js',
813
output: {
@@ -22,6 +27,7 @@ export default {
2227
...process.env,
2328
TEST_ENVIRONMENT: 'LOCAL',
2429
CHANNEL_TYPE: 'WEBSOCKET',
30+
DRIVER_DESCRIPTOR: getDescriptor(),
2531
BACKEND_PORT: process.env.WEB_SERVER_PORT || 8000
2632
})
2733
]

packages/testkit-backend/src/context.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
export default class Context {
2-
constructor () {
2+
constructor (shouldRunTest) {
33
this._id = 0
44
this._drivers = {}
55
this._sessions = {}
66
this._txs = {}
77
this._resolverRequests = {}
88
this._resultObservers = {}
99
this._errors = {}
10+
this._shouldRunTest = shouldRunTest
1011
}
1112

1213
addDriver (driver) {
@@ -98,6 +99,10 @@ export default class Context {
9899
return Object.values(this._txs).filter(tx => tx.sessionId === sessionId)
99100
}
100101

102+
getShouldRunTestFunction() {
103+
return this._shouldRunTest
104+
}
105+
101106
_add (map, object) {
102107
this._id++
103108
map[this._id] = object

packages/testkit-backend/src/controller/local.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import Controller from './interface'
99
*/
1010
export default class LocalController extends Controller {
1111

12-
constructor(requestHandlers = {}) {
12+
constructor(requestHandlers = {}, shouldRunTest = () => {}) {
1313
super()
1414
this._requestHandlers = requestHandlers
15+
this._shouldRunTest = shouldRunTest
1516
this._contexts = new Map()
1617
}
1718

1819
openContext (contextId) {
19-
this._contexts.set(contextId, new Context())
20+
this._contexts.set(contextId, new Context(this._shouldRunTest))
2021
}
2122

2223
closeContext (contextId) {

packages/testkit-backend/src/index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Backend from './backend'
22
import { SocketChannel, WebSocketChannel } from './channel'
33
import { LocalController, RemoteController } from './controller'
4+
import { getShouldRunTest } from './skipped-tests'
45
import * as REQUEST_HANDLERS from './request-handlers'
56

67
/**
@@ -11,6 +12,11 @@ function main( ) {
1112
const channelType = process.env.CHANNEL_TYPE || 'SOCKET'
1213
const backendPort = process.env.BACKEND_PORT || 9876
1314
const webserverPort = process.env.WEB_SERVER_PORT || 8000
15+
const driverDescriptor = process.env.DRIVER_DESCRIPTOR || ''
16+
const driverDescriptorList = driverDescriptor
17+
.split(',').map(s => s.trim().toLowerCase())
18+
19+
const shouldRunTest = getShouldRunTest(driverDescriptorList)
1420

1521
const newChannel = () => {
1622
if ( channelType.toUpperCase() === 'WEBSOCKET' ) {
@@ -24,7 +30,7 @@ function main( ) {
2430
if ( testEnviroment.toUpperCase() === 'REMOTE' ) {
2531
return new RemoteController(webserverPort)
2632
}
27-
return new LocalController(REQUEST_HANDLERS)
33+
return new LocalController(REQUEST_HANDLERS, shouldRunTest)
2834
}
2935

3036
const backend = new Backend(newController, newChannel)
@@ -39,7 +45,10 @@ function main( ) {
3945
process.on('SIGINT', process.exit.bind(process));
4046
process.on('SIGUSR1', process.exit.bind(process));
4147
process.on('SIGUSR2', process.exit.bind(process));
42-
process.on('uncaughtException', process.exit.bind(process));
48+
process.on('uncaughtException', exception => {
49+
console.error('UncaughtException', exception)
50+
process.exit()
51+
});
4352
}
4453
}
4554

packages/testkit-backend/src/request-handlers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import neo4j from './neo4j'
22
import ResultObserver from './result-observer.js'
33
import { cypherToNative, nativeToCypher } from './cypher-native-binders.js'
4-
import { shouldRunTest } from './skipped-tests'
54
import tls from 'tls'
65

76
const SUPPORTED_TLS = (() => {
@@ -302,7 +301,8 @@ export function SessionWriteTransaction (context, data, wire) {
302301
.catch(error => wire.writeError(error))
303302
}
304303

305-
export function StartTest (_, { testName }, wire) {
304+
export function StartTest (context, { testName }, wire) {
305+
const shouldRunTest = context.getShouldRunTestFunction()
306306
shouldRunTest(testName, {
307307
onRun: () => wire.writeResponse('RunTest', null),
308308
onSkip: reason => wire.writeResponse('SkipTest', { reason })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import skip, { ifStartsWith } from './skip'
2+
const skippedTests = [
3+
skip(
4+
'Stub Tests not implemented for browser',
5+
ifStartsWith('stub')
6+
),
7+
skip(
8+
'TLS Tests not implemented for browwer',
9+
ifStartsWith('tls')
10+
)
11+
]
12+
13+
export default skippedTests

packages/testkit-backend/src/skipped-tests.js renamed to packages/testkit-backend/src/skipped-tests/common.js

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
function ifEndsWith (suffix) {
2-
return testName => testName.endsWith(suffix)
3-
}
4-
5-
function ifStartsWith (prefix) {
6-
return testName => testName.startsWith(prefix)
7-
}
8-
9-
function ifEquals (expectedName) {
10-
return testName => testName === expectedName
11-
}
12-
13-
function or () {
14-
return testName => [...arguments].find(predicate => predicate(testName))
15-
}
16-
17-
function skip (reason, ...predicate) {
18-
return { reason, predicate: or(...predicate) }
19-
}
1+
import skip, { ifEquals, ifEndsWith } from './skip'
202

213
const skippedTests = [
224
skip(
@@ -109,8 +91,4 @@ const skippedTests = [
10991
)
11092
]
11193

112-
export function shouldRunTest (testName, { onRun, onSkip }) {
113-
const { reason } =
114-
skippedTests.find(({ predicate }) => predicate(testName)) || {}
115-
!reason ? onRun() : onSkip(reason)
116-
}
94+
export default skippedTests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import commonSkippedTests from './common'
2+
import browserSkippedTests from './browser'
3+
4+
const skippedTestsByContext = new Map([
5+
['browser', browserSkippedTests]
6+
])
7+
8+
export function getShouldRunTest (contexts) {
9+
const skippedTests = contexts
10+
.filter(context => skippedTestsByContext.has(context))
11+
.map(context => skippedTestsByContext.get(context))
12+
.reduce((previous, current) => [ ...previous, ...current ], commonSkippedTests)
13+
14+
return (testName, { onRun, onSkip }) => {
15+
const { reason } =
16+
skippedTests.find(({ predicate }) => predicate(testName)) || {}
17+
!reason ? onRun() : onSkip(reason)
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export function ifEndsWith (suffix) {
2+
return testName => testName.endsWith(suffix)
3+
}
4+
5+
export function ifStartsWith (prefix) {
6+
return testName => testName.startsWith(prefix)
7+
}
8+
9+
export function ifEquals (expectedName) {
10+
return testName => testName === expectedName
11+
}
12+
13+
export function or () {
14+
return testName => [...arguments].find(predicate => predicate(testName))
15+
}
16+
17+
export function skip (reason, ...predicate) {
18+
return { reason, predicate: or(...predicate) }
19+
}
20+
21+
export default skip

0 commit comments

Comments
 (0)