Skip to content

Commit 6125a0e

Browse files
committed
e2e tests: updates for integration tests
Update necessary components of existing e2e tests to prepare for new integration test suite. This includes: 1. Moving package-related files (package-lock.json, package.json, and tsconfig.json) out of the 'e2e' directory and into 'test' and updating package.json to not be e2e-test sepcific. This will allow both suites to be combined into a single Typescript package in upcoming patches. 2. Updating the 'require' statement in the e2e tests' config to identify the correct 'features' directory with the new architecture. 3. Moving certain classes currently in the e2e 'support' and 'classes' directories that will be needed by integration tests into a new 'shared' directory. Note that while certain pieces of the current 'utils' file were moved to 'shared', the absPath function was left in the original 'utils' file given it finds paths relative to test/e2e. Utils imports have been prefixed with 'local'/'shared' to account for the two files. Signed-off-by: Lessley Dennington <[email protected]>
1 parent 4ba9ca2 commit 6125a0e

File tree

15 files changed

+1345
-71
lines changed

15 files changed

+1345
-71
lines changed

scripts/run-e2e-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ set -e
3030
cd "$TESTDIR"
3131

3232
npm install
33-
npm run test -- ${ARGS:+${ARGS[*]}}
33+
npm run e2e-test -- ${ARGS:+${ARGS[*]}}

test/e2e/cucumber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const common = {
22
requireModule: ['ts-node/register'],
3-
require: ['features/**/*.ts'],
3+
require: [`${__dirname}/features/**/*.ts`],
44
publishQuiet: true,
55
format: ['progress'],
66
formatOptions: {

test/e2e/features/step_definitions/bundleServer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as utils from '../support/utils'
1+
import * as shared_utils from '../../../shared/support/utils'
22
import { BundleServerWorld, } from '../support/world'
33
import { Given } from '@cucumber/cucumber'
44

@@ -10,9 +10,9 @@ Given('the bundle server has been initialized with the remote repo', async funct
1010
if (this.remote === undefined) {
1111
throw new Error("Remote repository is not initialized")
1212
}
13-
utils.assertStatus(0, this.bundleServer.init(this.remote))
13+
shared_utils.assertStatus(0, this.bundleServer.init(this.remote))
1414
})
1515

1616
Given('the bundle server was updated for the remote repo', async function (this: BundleServerWorld) {
17-
utils.assertStatus(0, this.bundleServer.update())
17+
shared_utils.assertStatus(0, this.bundleServer.update())
1818
})

test/e2e/features/step_definitions/remote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Given, } from '@cucumber/cucumber'
2-
import { RemoteRepo } from '../classes/remote'
2+
import { RemoteRepo } from '../../../shared/classes/remote'
33
import { BundleServerWorld } from '../support/world'
44
import * as path from 'path'
55

test/e2e/features/step_definitions/repository.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as assert from 'assert'
2-
import * as utils from '../support/utils'
2+
import * as shared_utils from '../../../shared/support/utils'
33
import { randomBytes } from 'crypto'
44
import { BundleServerWorld, User } from '../support/world'
55
import { Given, When, Then } from '@cucumber/cucumber'
@@ -14,36 +14,36 @@ Given('another user pushed {int} commits to {string}', async function (this: Bun
1414
const clonedRepo = this.getRepoAtBranch(User.Another, branch)
1515

1616
for (let i = 0; i < commitNum; i++) {
17-
utils.assertStatus(0, clonedRepo.runShell(`echo ${randomBytes(16).toString('hex')} >README.md`))
18-
utils.assertStatus(0, clonedRepo.runGit("add", "README.md"))
19-
utils.assertStatus(0, clonedRepo.runGit("commit", "-m", `test ${i + 1}`))
17+
shared_utils.assertStatus(0, clonedRepo.runShell(`echo ${randomBytes(16).toString('hex')} >README.md`))
18+
shared_utils.assertStatus(0, clonedRepo.runGit("add", "README.md"))
19+
shared_utils.assertStatus(0, clonedRepo.runGit("commit", "-m", `test ${i + 1}`))
2020
}
21-
utils.assertStatus(0, clonedRepo.runGit("push", "origin", branch))
21+
shared_utils.assertStatus(0, clonedRepo.runGit("push", "origin", branch))
2222
})
2323

2424
Given('another user removed {int} commits and added {int} commits to {string}',
2525
async function (this: BundleServerWorld, removeCommits: number, addCommits: number, branch: string) {
2626
const clonedRepo = this.getRepoAtBranch(User.Another, branch)
2727

2828
// First, reset
29-
utils.assertStatus(0, clonedRepo.runGit("reset", "--hard", `HEAD~${removeCommits}`))
29+
shared_utils.assertStatus(0, clonedRepo.runGit("reset", "--hard", `HEAD~${removeCommits}`))
3030

3131
// Then, add new commits
3232
for (let i = 0; i < addCommits; i++) {
33-
utils.assertStatus(0, clonedRepo.runShell(`echo ${randomBytes(16).toString('hex')} >README.md`))
34-
utils.assertStatus(0, clonedRepo.runGit("add", "README.md"))
35-
utils.assertStatus(0, clonedRepo.runGit("commit", "-m", `test ${i + 1}`))
33+
shared_utils.assertStatus(0, clonedRepo.runShell(`echo ${randomBytes(16).toString('hex')} >README.md`))
34+
shared_utils.assertStatus(0, clonedRepo.runGit("add", "README.md"))
35+
shared_utils.assertStatus(0, clonedRepo.runGit("commit", "-m", `test ${i + 1}`))
3636
}
3737

3838
// Finally, force push
39-
utils.assertStatus(0, clonedRepo.runGit("push", "-f", "origin", branch))
39+
shared_utils.assertStatus(0, clonedRepo.runGit("push", "-f", "origin", branch))
4040
}
4141
)
4242

4343
Given('I cloned from the remote repo with a bundle URI', async function (this: BundleServerWorld) {
4444
const user = User.Me
4545
this.cloneRepositoryFor(user, this.bundleServer.bundleUri())
46-
utils.assertStatus(0, this.getRepo(user).cloneResult)
46+
shared_utils.assertStatus(0, this.getRepo(user).cloneResult)
4747
})
4848

4949
When('I clone from the remote repo with a bundle URI', async function (this: BundleServerWorld) {
@@ -56,14 +56,14 @@ When('another developer clones from the remote repo without a bundle URI', async
5656

5757
When('I fetch from the remote', async function (this: BundleServerWorld) {
5858
const clonedRepo = this.getRepo(User.Me)
59-
utils.assertStatus(0, clonedRepo.runGit("fetch", "origin"))
59+
shared_utils.assertStatus(0, clonedRepo.runGit("fetch", "origin"))
6060
})
6161

6262
Then('bundles are downloaded and used', async function (this: BundleServerWorld) {
6363
const clonedRepo = this.getRepo(User.Me)
6464

6565
// Verify the clone executed as-expected
66-
utils.assertStatus(0, clonedRepo.cloneResult, "git clone failed")
66+
shared_utils.assertStatus(0, clonedRepo.cloneResult, "git clone failed")
6767

6868
// Ensure warning wasn't thrown
6969
clonedRepo.cloneResult.stderr.toString().split("\n").forEach(function (line) {
@@ -74,12 +74,12 @@ Then('bundles are downloaded and used', async function (this: BundleServerWorld)
7474

7575
// Make sure the config is set up properly
7676
let result = clonedRepo.runGit("config", "--get", "fetch.bundleURI")
77-
utils.assertStatus(0, result, "'fetch.bundleURI' is not set after clone")
77+
shared_utils.assertStatus(0, result, "'fetch.bundleURI' is not set after clone")
7878
const actualURI = result.stdout.toString().trim()
7979
assert.strictEqual(actualURI, this.bundleServer.bundleUri())
8080

8181
result = clonedRepo.runGit("for-each-ref", "--format=%(refname)", "refs/bundles/*")
82-
utils.assertStatus(0, result, "git for-each-ref failed")
82+
shared_utils.assertStatus(0, result, "git for-each-ref failed")
8383

8484
const bundleRefs = result.stdout.toString().split("\n").filter(function(line) {
8585
return line.trim() != ""
@@ -90,7 +90,7 @@ Then('bundles are downloaded and used', async function (this: BundleServerWorld)
9090
Then('I am up-to-date with {string}', async function (this: BundleServerWorld, branch: string) {
9191
const clonedRepo = this.getRepo(User.Me)
9292
const result = clonedRepo.runGit("rev-parse", `refs/remotes/origin/${branch}`)
93-
utils.assertStatus(0, result)
93+
shared_utils.assertStatus(0, result)
9494
const actualOid = result.stdout.toString().trim()
9595
const expectedOid = this.remote?.getBranchTipOid(branch)
9696
assert.strictEqual(actualOid, expectedOid, `branch '${branch}' is not up-to-date`)
@@ -100,7 +100,7 @@ Then('my repo\'s bundles {boolean} up-to-date with {string}',
100100
async function (this: BundleServerWorld, expectedUpToDate: boolean, branch: string) {
101101
const clonedRepo = this.getRepo(User.Me)
102102
const result = clonedRepo.runGit("rev-parse", `refs/bundles/${branch}`)
103-
utils.assertStatus(0, result)
103+
shared_utils.assertStatus(0, result)
104104
const actualOid = result.stdout.toString().trim()
105105
const expectedOid = this.remote?.getBranchTipOid(branch)
106106

@@ -117,8 +117,8 @@ Then('I compare the clone execution times', async function (this: BundleServerWo
117117
const otherClone = this.getRepo(User.Another)
118118

119119
// Verify the clones succeeded
120-
utils.assertStatus(0, myClone.cloneResult)
121-
utils.assertStatus(0, otherClone.cloneResult)
120+
shared_utils.assertStatus(0, myClone.cloneResult)
121+
shared_utils.assertStatus(0, otherClone.cloneResult)
122122

123123
console.log(`\nClone execution time for ${this.remote!.remoteUri}: ${(myClone.cloneTimeMs / 1000).toFixed(2)}s (bundle URI) vs. ${(otherClone.cloneTimeMs / 1000).toFixed(2)}s (no bundle URI)`)
124124
})

test/e2e/features/support/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
import * as path from 'path'
2-
import * as assert from 'assert'
3-
import * as child_process from 'child_process'
4-
5-
export function runGit(...args: string[]): child_process.SpawnSyncReturns<Buffer> {
6-
return child_process.spawnSync("git", args)
7-
}
82

93
export function absPath(pathParam: string): string {
104
// Convert a given path (either relative to 'test/e2e/' or absolute) to an
@@ -15,11 +9,3 @@ export function absPath(pathParam: string): string {
159
return pathParam
1610
}
1711
}
18-
19-
export function assertStatus(expectedStatusCode: number, result: child_process.SpawnSyncReturns<Buffer>, message?: string): void {
20-
if (result.error) {
21-
throw result.error
22-
}
23-
assert.strictEqual(result.status, expectedStatusCode,
24-
`${message ?? "Invalid status code"}:\n\tstdout: ${result.stdout.toString()}\n\tstderr: ${result.stderr.toString()}`)
25-
}

test/e2e/features/support/world.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { setWorldConstructor, World, IWorldOptions } from '@cucumber/cucumber'
22
import { randomUUID } from 'crypto'
3-
import { RemoteRepo } from '../classes/remote'
4-
import * as utils from './utils'
3+
import { RemoteRepo } from '../../../shared/classes/remote'
4+
import * as local_utils from './utils'
5+
import * as shared_utils from '../../../shared/support/utils'
56
import * as fs from 'fs'
67
import * as path from 'path'
7-
import { ClonedRepository } from '../classes/repository'
8-
import { BundleServer } from '../classes/bundleServer'
8+
import { ClonedRepository } from '../../../shared/classes/repository'
9+
import { BundleServer } from '../../../shared/classes/bundleServer'
910

1011
export enum User {
1112
Me = 1,
@@ -35,12 +36,12 @@ export class BundleServerWorld extends World<BundleServerParameters> {
3536
this.repoMap = new Map<User, ClonedRepository>()
3637

3738
// Set up the trash directory
38-
this.trashDirectory = path.join(utils.absPath(this.parameters.trashDirectoryBase), randomUUID())
39+
this.trashDirectory = path.join(local_utils.absPath(this.parameters.trashDirectoryBase), randomUUID())
3940
fs.mkdirSync(this.trashDirectory, { recursive: true });
4041

4142
// Set up the bundle server
42-
this.bundleServer = new BundleServer(utils.absPath(this.parameters.bundleServerCommand),
43-
utils.absPath(this.parameters.bundleWebServerCommand))
43+
this.bundleServer = new BundleServer(local_utils.absPath(this.parameters.bundleServerCommand),
44+
local_utils.absPath(this.parameters.bundleWebServerCommand))
4445
}
4546

4647
cloneRepositoryFor(user: User, bundleUri?: string): void {
@@ -68,18 +69,18 @@ export class BundleServerWorld extends World<BundleServerParameters> {
6869

6970
if (!this.repoMap.has(user)) {
7071
this.cloneRepositoryFor(user)
71-
utils.assertStatus(0, this.getRepo(user).cloneResult)
72+
shared_utils.assertStatus(0, this.getRepo(user).cloneResult)
7273
}
7374

7475
const clonedRepo = this.getRepo(user)
7576

7677
const result = clonedRepo.runGit("rev-list", "--all", "-n", "1")
7778
if (result.stdout.toString().trim() == "") {
7879
// Repo is empty, so make sure we're on the right branch
79-
utils.assertStatus(0, clonedRepo.runGit("branch", "-m", branch))
80+
shared_utils.assertStatus(0, clonedRepo.runGit("branch", "-m", branch))
8081
} else {
81-
utils.assertStatus(0, clonedRepo.runGit("switch", branch))
82-
utils.assertStatus(0, clonedRepo.runGit("pull", "origin", branch))
82+
shared_utils.assertStatus(0, clonedRepo.runGit("switch", branch))
83+
shared_utils.assertStatus(0, clonedRepo.runGit("pull", "origin", branch))
8384
}
8485

8586
return clonedRepo

test/e2e/package-lock.json

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)