Skip to content

Commit b58aa0b

Browse files
committed
integration tests: testing infrastructure
Add the initial infrastructure for integration tests, following the pattern set with end-to-end tests in [1]. This includes Cucumber configuration, basic support classes, bundle server and web server classes, and a command runner. The bundle/web server classes are currently set up to use the command runner to run the web-server command, which will be used for daemon testing in the next patch in this series. 1: bc8df92 Signed-off-by: Lessley Dennington <[email protected]>
1 parent 4ba9ca2 commit b58aa0b

File tree

10 files changed

+1422
-2
lines changed

10 files changed

+1422
-2
lines changed

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040

4141
// Cucumber settings
4242
"cucumber.features": [
43-
"test/e2e/features/**/*.feature",
43+
"test/**/features/**/*.feature",
4444
],
4545
"cucumber.glue": [
46-
"test/e2e/features/**/*.ts"
46+
"test/**/features/**/*.ts",
4747
],
4848
}

test/integration/cucumber.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
default: {
3+
requireModule: ['ts-node/register'],
4+
require: ['features/**/*.ts'],
5+
publishQuiet: true,
6+
format: ['progress'],
7+
formatOptions: {
8+
snippetInterface: 'async-await'
9+
},
10+
worldParameters: {
11+
bundleServerCommand: '../../bin/git-bundle-server',
12+
}
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { WebServer } from './webServer'
2+
3+
export class BundleServer {
4+
private bundleServerCommand: string
5+
6+
webServer: WebServer
7+
8+
constructor(bundleServerCommand: string) {
9+
this.bundleServerCommand = bundleServerCommand
10+
this.webServer = new WebServer(bundleServerCommand)
11+
}
12+
13+
run_command(args: string[]): void {
14+
var subcommand = args[0]
15+
16+
switch (subcommand) {
17+
case 'web-server':
18+
this.webServer.run_command(args)
19+
break
20+
default:
21+
throw new Error('Unknown subcommand')
22+
}
23+
}
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as child_process from 'child_process'
2+
3+
export class CommandRunner {
4+
run(command: string, args: string[] = [""]): child_process.SpawnSyncReturns<Buffer> {
5+
return child_process.spawnSync(command, args)
6+
}
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { CommandRunner } from './commandRunner'
2+
3+
export class WebServer {
4+
private bundleServerCommand: string
5+
private commandRunner: CommandRunner
6+
7+
constructor(bundleServerCommand: string) {
8+
this.bundleServerCommand = bundleServerCommand
9+
this.commandRunner = new CommandRunner()
10+
}
11+
12+
run_command(args: string[]): void {
13+
var subcommand = args[1]
14+
15+
switch(subcommand) {
16+
case 'start':
17+
this.commandRunner.run(this.bundleServerCommand, ['web-server', 'start'])
18+
break
19+
case 'stop':
20+
this.commandRunner.run(this.bundleServerCommand, ['web-server', 'stop'])
21+
break
22+
default:
23+
throw new Error("Unknown subcommand")
24+
}
25+
}
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as path from 'path'
2+
3+
export function absPath(pathParam: string): string {
4+
// Convert a given path (either relative to 'test/integration/' or absolute) to an
5+
// absolute path
6+
if (!path.isAbsolute(pathParam)) {
7+
return path.resolve(__dirname, "../..", pathParam)
8+
} else {
9+
return pathParam
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { setWorldConstructor, World, IWorldOptions } from '@cucumber/cucumber'
2+
import { BundleServer } from '../classes/bundleServer'
3+
4+
interface BundleServerParameters {
5+
bundleServerCommand: string
6+
}
7+
8+
export class BundleServerWorld extends World<BundleServerParameters> {
9+
bundleServer: BundleServer
10+
11+
constructor(options: IWorldOptions<BundleServerParameters>) {
12+
super(options)
13+
this.bundleServer = new BundleServer(this.parameters.bundleServerCommand)
14+
}
15+
16+
run_command(args: string[]): void {
17+
// Remove name of the command in order to use the relative path in the
18+
// bundleServerCommand param.
19+
args.shift()
20+
this.bundleServer.run_command(args)
21+
}
22+
}
23+
24+
setWorldConstructor(BundleServerWorld)

0 commit comments

Comments
 (0)