-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: exit with non-zero if piped data is error (#119)
- Loading branch information
Showing
7 changed files
with
6,381 additions
and
9,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
npx lint-staged | ||
npm run test:unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { spawn } from 'node:child_process' | ||
import { createReadStream } from 'node:fs' | ||
import { join } from 'node:path' | ||
|
||
describe('console-reporter', () => { | ||
it('should exit with code 0 if the previous process runs successfully', (done) => { | ||
const consoleReporter = spawn( | ||
'npx', | ||
['tsx', 'features/console-reporter.ts'], | ||
{ | ||
cwd: process.cwd(), | ||
}, | ||
) | ||
|
||
const data = createReadStream( | ||
join(process.cwd(), 'features/fixtures/report-success.json'), | ||
) | ||
data | ||
.on('data', (data) => { | ||
consoleReporter.stdin.write(data) | ||
}) | ||
.on('end', () => { | ||
consoleReporter.stdin.end() | ||
}) | ||
|
||
consoleReporter.on('close', (code) => { | ||
expect(code).toBe(0) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should exit with code 1 if the previous process is failed', (done) => { | ||
const consoleReporter = spawn( | ||
'npx', | ||
['tsx', 'features/console-reporter.ts'], | ||
{ | ||
cwd: process.cwd(), | ||
}, | ||
) | ||
|
||
const data = createReadStream( | ||
join(process.cwd(), 'features/fixtures/report-fail.json'), | ||
) | ||
data | ||
.on('data', (data) => { | ||
consoleReporter.stdin.write(data) | ||
}) | ||
.on('end', () => { | ||
consoleReporter.stdin.end() | ||
}) | ||
|
||
consoleReporter.on('close', (code) => { | ||
expect(code).toBe(1) | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import { consoleReporter } from '@nordicsemiconductor/bdd-markdown' | ||
|
||
const chunks: string[] = [] | ||
|
||
process.stdin.on('data', (data) => { | ||
consoleReporter(JSON.parse(data.toString()), console.log) | ||
chunks.push(data.toString()) | ||
}) | ||
|
||
process.stdin.on('end', () => { | ||
const jsonData = JSON.parse(chunks.join('')) | ||
consoleReporter(jsonData, console.log) | ||
|
||
if (jsonData.ok !== true) process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"ok": false, | ||
"results": [ | ||
[ | ||
{ | ||
"root": "/", | ||
"dir": "/path/to/features", | ||
"base": "Calculator.feature.md", | ||
"ext": ".md", | ||
"name": "Calculator.feature" | ||
}, | ||
{ | ||
"ok": false, | ||
"results": [ | ||
[ | ||
{ | ||
"keyword": "Scenario", | ||
"title": "Adding", | ||
"line": 30, | ||
"steps": [ | ||
{ | ||
"keyword": "When", | ||
"title": "I add 1 and 2", | ||
"line": 32 | ||
}, | ||
{ | ||
"keyword": "Then", | ||
"title": "the result should be 3", | ||
"line": 34 | ||
} | ||
] | ||
}, | ||
{ | ||
"ok": false, | ||
"results": [ | ||
[ | ||
{ | ||
"keyword": "When", | ||
"title": "I add 1 and 2", | ||
"line": 32 | ||
}, | ||
{ | ||
"logs": [], | ||
"ok": true, | ||
"duration": 102, | ||
"executed": { | ||
"keyword": "When", | ||
"title": "I add 1 and 2", | ||
"line": 32 | ||
}, | ||
"tries": 1, | ||
"skipped": false | ||
} | ||
], | ||
[ | ||
{ | ||
"keyword": "Then", | ||
"title": "the result should be 3", | ||
"line": 34 | ||
}, | ||
{ | ||
"logs": [], | ||
"ok": false, | ||
"duration": 651, | ||
"executed": { | ||
"keyword": "Then", | ||
"title": "the result should be 3", | ||
"line": 34 | ||
}, | ||
"tries": 1, | ||
"skipped": false | ||
} | ||
] | ||
], | ||
"duration": 753, | ||
"logs": [], | ||
"skipped": false | ||
} | ||
] | ||
], | ||
"duration": 771, | ||
"logs": [], | ||
"skipped": false | ||
} | ||
] | ||
], | ||
"summary": { | ||
"total": 1, | ||
"passed": 0, | ||
"failed": 1, | ||
"duration": 3083, | ||
"skipped": 0 | ||
}, | ||
"name": "Calculator" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"ok": true, | ||
"results": [ | ||
[ | ||
{ | ||
"root": "/", | ||
"dir": "/path/to/features", | ||
"base": "Calculator.feature.md", | ||
"ext": ".md", | ||
"name": "Calculator.feature" | ||
}, | ||
{ | ||
"ok": true, | ||
"results": [ | ||
[ | ||
{ | ||
"keyword": "Scenario", | ||
"title": "Adding", | ||
"line": 30, | ||
"steps": [ | ||
{ | ||
"keyword": "When", | ||
"title": "I add 1 and 2", | ||
"line": 32 | ||
}, | ||
{ | ||
"keyword": "Then", | ||
"title": "the result should be 3", | ||
"line": 34 | ||
} | ||
] | ||
}, | ||
{ | ||
"ok": false, | ||
"results": [ | ||
[ | ||
{ | ||
"keyword": "When", | ||
"title": "I add 1 and 2", | ||
"line": 32 | ||
}, | ||
{ | ||
"logs": [], | ||
"ok": true, | ||
"duration": 102, | ||
"executed": { | ||
"keyword": "When", | ||
"title": "I add 1 and 2", | ||
"line": 32 | ||
}, | ||
"tries": 1, | ||
"skipped": false | ||
} | ||
], | ||
[ | ||
{ | ||
"keyword": "Then", | ||
"title": "the result should be 3", | ||
"line": 34 | ||
}, | ||
{ | ||
"logs": [], | ||
"ok": false, | ||
"duration": 651, | ||
"executed": { | ||
"keyword": "Then", | ||
"title": "the result should be 3", | ||
"line": 34 | ||
}, | ||
"tries": 1, | ||
"skipped": false | ||
} | ||
] | ||
], | ||
"duration": 753, | ||
"logs": [], | ||
"skipped": false | ||
} | ||
] | ||
], | ||
"duration": 771, | ||
"logs": [], | ||
"skipped": false | ||
} | ||
] | ||
], | ||
"summary": { | ||
"total": 1, | ||
"passed": 1, | ||
"failed": 0, | ||
"duration": 3083, | ||
"skipped": 0 | ||
}, | ||
"name": "Calculator" | ||
} |
Oops, something went wrong.