Skip to content

Commit 0e7555a

Browse files
committed
init and list tests
1 parent 46d7596 commit 0e7555a

File tree

7 files changed

+115
-2
lines changed

7 files changed

+115
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Bundle server command tests
2+
3+
Background: The bundle web server is running
4+
Given the bundle web server was started at port 8080
5+
6+
Scenario: The init command initializes a bundle server repository
7+
Given no bundle server repository exists at route 'integration/asset-hash'
8+
When I run the bundle server CLI command 'init https://github.com/vdye/asset-hash.git integration/asset-hash'
9+
Then a bundle server repository exists at route 'integration/asset-hash'
10+
11+
Scenario: The list command lists route and remote
12+
Given a remote repository exists at url 'https://github.com/vdye/asset-hash.git'
13+
Given a bundle server repository is created at route 'integration/asset-hash' for the remote
14+
When I run the bundle server CLI command 'list'
15+
Then the routes and remotes are listed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as assert from 'assert'
2+
import { BundleServerWorld, } from '../support/world'
3+
import { Given, Then } from '@cucumber/cucumber'
4+
5+
Given('the bundle web server was started at port {int}', async function (this: BundleServerWorld, port: number) {
6+
this.runCommand(`web-server start --port ${port}`)
7+
})
8+
9+
Then('the routes and remotes are listed', async function (this: BundleServerWorld) {
10+
assert.strictEqual(this.commandResult?.stdout.toString()
11+
.includes(`${this.route} \t${this.remote?.remoteUri}`), true)
12+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { When } from "@cucumber/cucumber"
2+
import { BundleServerWorld } from "../support/world"
3+
4+
When('I run the bundle server CLI command {string}', async function (this: BundleServerWorld, command: string) {
5+
this.runCommand(command)
6+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Given } from "@cucumber/cucumber"
2+
import { RemoteRepo } from "../../../shared/classes/remote"
3+
import { BundleServerWorld } from "../support/world"
4+
5+
Given('a remote repository exists at url {string}', async function (this: BundleServerWorld, url: string) {
6+
this.remote = new RemoteRepo(false, url)
7+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Given, Then } from "@cucumber/cucumber"
2+
import * as local_utils from '../support/utils'
3+
import { BundleServerWorld } from "../support/world"
4+
import * as fs from 'fs'
5+
import * as assert from 'assert'
6+
7+
Given('a bundle server repository is created at route {string} for the remote', async function (this: BundleServerWorld, route: string) {
8+
this.init(route)
9+
})
10+
11+
Given('no bundle server repository exists at route {string}', async function (this: BundleServerWorld, route: string) {
12+
var repoPath = local_utils.repoRoot(route)
13+
if (fs.existsSync(repoPath)) {
14+
throw new Error(`Repo already exists at ${repoPath}`)
15+
}
16+
})
17+
18+
Then('a bundle server repository exists at route {string}', async function (this: BundleServerWorld, route: string) {
19+
var repoRoot = local_utils.repoRoot(route)
20+
assert.equal(fs.existsSync(repoRoot), true)
21+
assert.equal(fs.existsSync(`${repoRoot}/.git`), false)
22+
assert.equal(fs.existsSync(`${repoRoot}/bundle-list.json`), true)
23+
24+
// Set route for cleanup
25+
this.route = route
26+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { BundleServerWorld } from '../support/world'
2+
import { After } from '@cucumber/cucumber'
3+
4+
/**
5+
* Steps handling operations that are common across tests.
6+
*/
7+
8+
After(function (this: BundleServerWorld) {
9+
this.cleanup()
10+
});

test/integration/features/support/world.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
11
import { setWorldConstructor, World, IWorldOptions } from '@cucumber/cucumber'
22
import * as child_process from 'child_process'
3+
import { RemoteRepo } from '../../../shared/classes/remote'
4+
import * as local_utils from './utils'
5+
import * as fs from 'fs'
36

47
interface BundleServerParameters {
58
bundleServerCommand: string
69
}
710

811
export class BundleServerWorld extends World<BundleServerParameters> {
9-
runCommand(commandArgs: string): child_process.SpawnSyncReturns<Buffer> {
10-
return child_process.spawnSync(`${this.parameters.bundleServerCommand} ${commandArgs}`, [], { shell: true })
12+
route: string | undefined
13+
14+
remote: RemoteRepo | undefined
15+
commandResult: child_process.SpawnSyncReturns<Buffer> | undefined
16+
17+
init(route: string): void {
18+
if (!this.remote) {
19+
throw new Error("Remote repository is not initialized")
20+
}
21+
22+
var repoPath = local_utils.repoRoot(route)
23+
if (!fs.existsSync(repoPath)) {
24+
this.runCommand(`init ${this.remote?.remoteUri} ${route}`)
25+
} else {
26+
throw new Error("Repository already exists")
27+
}
28+
29+
this.route = route
30+
}
31+
32+
runCommand(commandArgs: string): void {
33+
this.commandResult = child_process.spawnSync(`${this.parameters.bundleServerCommand} ${commandArgs}`, [], { shell: true })
34+
}
35+
36+
cleanup(): void {
37+
if (this.route) {
38+
child_process.spawnSync(`delete ${this.route}`)
39+
fs.rmSync(local_utils.repoRoot(this.route), { recursive: true })
40+
41+
var routesPath = local_utils.routesPath()
42+
var data = fs.readFileSync(routesPath, 'utf-8');
43+
44+
var newValue = data.replace(this.route, '');
45+
46+
fs.writeFileSync(routesPath, newValue);
47+
}
1148
}
1249
}
1350

0 commit comments

Comments
 (0)