Skip to content

Commit 8c29c53

Browse files
slapec93Gergely Békésigithub-actions[bot]
authored
test: add e2e test for quickstart command (#699)
* test: add e2e test for quickstart command * fix: exit code * test: update test coverage --------- Co-authored-by: Gergely Békési <gergely.bekesi@ethswarm.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 6a85fe5 commit 8c29c53

5 files changed

Lines changed: 98 additions & 1 deletion

File tree

.github/workflows/tests-e2e.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Tests (End-to-end)
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
tests-e2e:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v6
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 24.x
23+
24+
- name: Install local dependencies
25+
run: npm ci
26+
27+
- name: Tests
28+
run: npm run test.e2e
29+

jest-e2e.config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
import type { Config } from '@jest/types'
6+
import { Dates } from 'cafe-utility'
7+
8+
export default (): Config.InitialOptions => {
9+
return {
10+
collectCoverage: false,
11+
forceExit: true,
12+
13+
// Run tests from one or more projects
14+
projects: [
15+
{
16+
preset: 'ts-jest',
17+
displayName: 'node',
18+
testEnvironment: 'node',
19+
testRegex: 'test/e2e/.*\\.spec\\.ts',
20+
},
21+
] as unknown[] as string[], // bad types
22+
23+
// The root directory that Jest should scan for tests and modules within
24+
rootDir: 'test',
25+
26+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
27+
testPathIgnorePatterns: ['/node_modules/'],
28+
29+
// Increase timeout since we have long running cryptographic functions
30+
testTimeout: Dates.minutes(6),
31+
}
32+
}

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default async (): Promise<Config.InitialOptions> => {
7575
rootDir: 'test',
7676

7777
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
78-
testPathIgnorePatterns: ['/node_modules/'],
78+
testPathIgnorePatterns: ['/node_modules/', '/test/e2e/'],
7979

8080
// Increase timeout since we have long running cryptographic functions
8181
testTimeout: Dates.minutes(6),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"prepare": "npm run build",
2727
"build": "rimraf dist && tsc",
2828
"test": "jest --config=jest.config.ts",
29+
"test.e2e": "jest --config=jest-e2e.config.ts",
2930
"test:coverage": "jest --config=jest.config.ts --coverage",
3031
"check": "tsc --project tsconfig.test.json",
3132
"start": "ts-node src/index.ts",

test/e2e/quickstart-e2e.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import inquirer from 'inquirer'
2+
import { mkdirSync, rmSync } from 'fs'
3+
import { describeCommand, invokeTestCli } from '../utility'
4+
import { spawn } from 'child_process'
5+
6+
describeCommand('Test Quickstart command end-to-end', ({ hasMessageContaining, getLastMessage }) => {
7+
it('should run through the quickstart flow', async () => {
8+
mkdirSync('./tmp')
9+
10+
const originalCwd = process.cwd()
11+
process.chdir('./tmp')
12+
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'ultra-light' })
13+
await invokeTestCli(['quickstart'])
14+
process.chdir(originalCwd)
15+
expect(getLastMessage()).toContain('./bee start --config=bee.yaml')
16+
17+
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms))
18+
const node = spawn('./bee', ['start', '--config=bee.yaml'], { cwd: './tmp' })
19+
try {
20+
await (async () => {
21+
for (let i = 0; i < 30; i++) {
22+
await invokeTestCli(['status'])
23+
24+
if (hasMessageContaining('[OK]')) return
25+
await sleep(1000)
26+
}
27+
throw new Error('Node did not start in time')
28+
})()
29+
} finally {
30+
node.kill('SIGINT')
31+
await new Promise(resolve => node.on('exit', resolve))
32+
rmSync('./tmp', { recursive: true, force: true })
33+
}
34+
})
35+
})

0 commit comments

Comments
 (0)