Skip to content

Commit 9226580

Browse files
committed
delete test
1 parent 0e7555a commit 9226580

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

test/integration/features/command.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ Feature: Bundle server command tests
1313
Given a bundle server repository is created at route 'integration/asset-hash' for the remote
1414
When I run the bundle server CLI command 'list'
1515
Then the routes and remotes are listed
16+
17+
Scenario: The delete command removes route configuration and repository data
18+
Given a remote repository exists at url 'https://github.com/vdye/asset-hash.git'
19+
Given a bundle server repository is created at route 'integration/asset-hash' for the remote
20+
When I run the bundle server CLI command 'delete integration/asset-hash'
21+
Then the route configuration and repository data at 'integration/asset-hash' are removed
22+
23+
Scenario: The update command fetches the latest remote content and updates the bundle list
24+
Given no bundle server repository exists at route 'integration/bundle'
25+
Given a new remote repository with main branch 'main'
26+
Given the remote is cloned
27+
Given 5 commits are pushed to the remote branch 'main'
28+
Given a bundle server repository is created at route 'integration/bundle' for the remote
29+
Given 2 commits are pushed to the remote branch 'main'
30+
When I run the bundle server CLI command 'update integration/bundle'
31+
Then the bundle list is updated

test/integration/features/step_definitions/bundleServer.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as assert from 'assert'
22
import { BundleServerWorld, } from '../support/world'
33
import { Given, Then } from '@cucumber/cucumber'
4+
import * as local_utils from '../support/utils'
5+
import * as fs from 'fs'
46

57
Given('the bundle web server was started at port {int}', async function (this: BundleServerWorld, port: number) {
68
this.runCommand(`web-server start --port ${port}`)
@@ -10,3 +12,21 @@ Then('the routes and remotes are listed', async function (this: BundleServerWorl
1012
assert.strictEqual(this.commandResult?.stdout.toString()
1113
.includes(`${this.route} \t${this.remote?.remoteUri}`), true)
1214
})
15+
16+
Then('the route configuration and repository data at {string} are removed', async function (this: BundleServerWorld, route: string) {
17+
var repoRoot = local_utils.repoRoot(route)
18+
var routeData = fs.readFileSync(local_utils.routesPath())
19+
20+
assert.equal(fs.existsSync(repoRoot), false)
21+
assert.equal(routeData.includes(route), false)
22+
23+
// Reset route to be ignored in cleanup
24+
this.route = undefined
25+
})
26+
27+
Then('the bundle list is updated', async function (this: BundleServerWorld) {
28+
assert.strictEqual(this.commandResult?.stdout.toString()
29+
.includes('Updating bundle list\n' +
30+
'Writing updated bundle list\n' +
31+
'Update complete'), true)
32+
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
import { Given } from "@cucumber/cucumber"
22
import { RemoteRepo } from "../../../shared/classes/remote"
33
import { BundleServerWorld } from "../support/world"
4+
import * as path from "path"
5+
import * as shared_utils from "../../../shared/support/utils"
6+
import { randomBytes } from "crypto"
47

58
Given('a remote repository exists at url {string}', async function (this: BundleServerWorld, url: string) {
69
this.remote = new RemoteRepo(false, url)
710
})
11+
Given('a new remote repository with main branch {string}', async function (this: BundleServerWorld, mainBranch: string) {
12+
this.remote = new RemoteRepo(true, path.join(this.trashDirectory, "server"), mainBranch)
13+
})
14+
15+
Given('the remote is cloned', async function (this: BundleServerWorld) {
16+
this.cloneRepository()
17+
})
18+
19+
Given('{int} commits are pushed to the remote branch {string}', async function (this: BundleServerWorld, commitNum: number, branch: string) {
20+
if (this.local) {
21+
for (let i = 0; i < commitNum; i++) {
22+
shared_utils.assertStatus(0, this.runShell(`echo ${randomBytes(16).toString('hex')} >${this.local.root}/README.md`))
23+
shared_utils.assertStatus(0, shared_utils.runGit("-C", this.local.root, "add", "README.md"))
24+
shared_utils.assertStatus(0, shared_utils.runGit("-C", this.local.root, "commit", "-m", `test ${i + 1}`))
25+
}
26+
} else {
27+
throw new Error("Local repo not initialized")
28+
}
29+
30+
if (this.remote) {
31+
shared_utils.assertStatus(0, shared_utils.runGit("-C", this.local.root, "push", "origin", branch))
32+
} else {
33+
throw new Error("Remote repo not initialized")
34+
}
35+
})

test/integration/features/support/world.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@ import * as child_process from 'child_process'
33
import { RemoteRepo } from '../../../shared/classes/remote'
44
import * as local_utils from './utils'
55
import * as fs from 'fs'
6+
import { ClonedRepository } from '../../../shared/classes/repository'
7+
import { randomUUID } from 'crypto'
8+
import * as path from 'path'
69

710
interface BundleServerParameters {
811
bundleServerCommand: string
12+
trashDirectoryBase: string
913
}
1014

1115
export class BundleServerWorld extends World<BundleServerParameters> {
1216
route: string | undefined
17+
trashDirectory: string
1318

1419
remote: RemoteRepo | undefined
20+
local: ClonedRepository | undefined
1521
commandResult: child_process.SpawnSyncReturns<Buffer> | undefined
1622

23+
constructor(options: IWorldOptions<BundleServerParameters>) {
24+
super(options)
25+
this.route = ""
26+
27+
// Set up the trash directory
28+
this.trashDirectory = path.join(local_utils.absPath(this.parameters.trashDirectoryBase), randomUUID())
29+
fs.mkdirSync(this.trashDirectory, { recursive: true });
30+
}
31+
1732
init(route: string): void {
1833
if (!this.remote) {
1934
throw new Error("Remote repository is not initialized")
@@ -33,6 +48,19 @@ export class BundleServerWorld extends World<BundleServerParameters> {
3348
this.commandResult = child_process.spawnSync(`${this.parameters.bundleServerCommand} ${commandArgs}`, [], { shell: true })
3449
}
3550

51+
runShell(command: string, ...args: string[]): child_process.SpawnSyncReturns<Buffer> {
52+
return child_process.spawnSync(command, args, { shell: true })
53+
}
54+
55+
cloneRepository(): void {
56+
if (!this.remote) {
57+
throw new Error("Remote repository is not initialized")
58+
}
59+
60+
const repoRoot = `${this.trashDirectory}/client`
61+
this.local = new ClonedRepository(this.remote, repoRoot)
62+
}
63+
3664
cleanup(): void {
3765
if (this.route) {
3866
child_process.spawnSync(`delete ${this.route}`)

test/shared/classes/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as shared_utils from '../support/utils'
44

55
export class ClonedRepository {
66
private initialized: boolean
7-
private root: string
87
private remote: RemoteRepo | undefined
98

9+
root: string
1010
cloneResult: child_process.SpawnSyncReturns<Buffer>
1111
cloneTimeMs: number
1212

0 commit comments

Comments
 (0)