Skip to content

Commit ffe16cd

Browse files
committed
test(e2e): preserve result
1 parent 060ff17 commit ffe16cd

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

.github/workflows/test-and-release.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,21 @@ jobs:
8282
- name: Run End-to-End Tests
8383
run: npm run test:e2e
8484

85+
- name: Print failed End-to-End tests
86+
if: failure()
87+
run:
88+
cat e2e-test-result.json | npx tsx --no-warnings
89+
./feature-runner/console-reporter.ts --only-failed --with-timestamps
90+
91+
- uses: actions/upload-artifact@v3
92+
if: failure()
93+
with:
94+
name: e2e-test-result
95+
path: e2e-test-result.json
96+
8597
- name: Get logs
8698
if: failure()
87-
run: ./cli.sh logs
99+
run: ./cli.sh logs -f ERROR
88100

89101
- name: Save stack outputs
90102
id: stack_outputs

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ cdk.out/
99
dist/
1010
.envrc
1111
/certificates/
12-
cdk.context.json
12+
cdk.context.json
13+
e2e-test-result.json

feature-runner/console-reporter.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import {
2-
type SuiteResult,
32
consoleReporter,
3+
type SuiteResult,
44
} from '@nordicsemiconductor/bdd-markdown'
55

6+
const onlyFailed = process.argv.includes('--only-failed')
7+
const withTimestamps = process.argv.includes('--with-timestamps')
8+
69
const chunks: string[] = []
710

8-
process.stdin.on('data', (data) => {
9-
chunks.push(data.toString())
10-
})
11+
process.stdin.on('data', (chunk) => chunks.push(chunk.toString()))
12+
13+
await new Promise((resolve) => process.stdin.on('end', resolve))
1114

12-
const res = await new Promise<SuiteResult>((resolve) =>
13-
process.stdin.on('end', () => resolve(JSON.parse(chunks.join('')))),
14-
)
15+
let res: SuiteResult
16+
try {
17+
res = JSON.parse(chunks.join(''))
18+
} catch (error) {
19+
throw new Error(`Failed to parse result JSON: ${(error as Error).message}`)
20+
}
1521

16-
consoleReporter(res, console.log, { withTimestamps: true })
22+
consoleReporter(res, console.log, {
23+
onlyFailed,
24+
withTimestamps,
25+
})
1726

1827
if (!res.ok) process.exit(1)

feature-runner/run-features.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ const res = await runner.run({})
164164

165165
await Promise.all(cleaners.map(async (fn) => fn()))
166166

167-
process.stdout.write(JSON.stringify(res, null, 2))
168-
169-
if (!res.ok) {
170-
console.error(chalk.red('Tests failed'))
171-
process.exit(1)
172-
}
167+
console.error(`Writing to stdout ...`)
168+
process.stdout.write(JSON.stringify(res, null, 2), () => {
169+
console.error(`Done`, res.ok ? chalk.green('OK') : chalk.red('ERROR'))
170+
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"test": "jest",
8-
"test:e2e": "npx tsx --no-warnings ./feature-runner/run-features.ts | npx tsx --no-warnings ./feature-runner/console-reporter.ts",
8+
"test:e2e": "npx tsx --no-warnings ./feature-runner/run-features.ts > e2e-test-result.json && cat e2e-test-result.json | npx tsx --no-warnings ./feature-runner/console-reporter.ts --only-failed --with-timestamps",
99
"prepare": "husky install && check-node-version --package",
1010
"deploy": "cdk deploy",
1111
"synth": "cdk synth"

0 commit comments

Comments
 (0)