Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
feat: console-json reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Dec 20, 2021
1 parent 7f0ea39 commit 531ea31
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/demo/peeky.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export default defineConfig({
// external: [],
// runtimeEnv: MyEnv,
// mockFs: false,
reporters: ['console-json'],
})
2 changes: 1 addition & 1 deletion packages/peeky-config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type ModuleFilterOption<T = ModuleFilter> = T[] | T
export type SerializableModuleFilter = string | RegExp

export type SerializableRuntimeEnv = 'node' | 'dom'
export type BuiltinReporter = 'console-fancy'
export type BuiltinReporter = 'console-fancy' | 'console-json'

export interface PeekyConfig {
targetDirectory?: string
Expand Down
70 changes: 70 additions & 0 deletions packages/peeky-runner/src/reporters/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Reporter } from '../types.js'

export function createRawReporter (write: (data: Record<string, any>) => unknown): Reporter {
return {
log: ({ type, text, suite, test }) => {
write({
__type: 'log',
type,
text,
suiteId: suite?.id,
testId: test?.id,
})
},

suiteStart: (payload) => {
write(payload)
},

suiteComplete: (payload) => {
write({
__type: 'suiteComplete',
suiteId: payload.suite.id,
duration: payload.suite.duration,
testErrors: payload.suite.testErrors,
otherErrors: payload.suite.otherErrors,
})
},

testStart: (payload) => {
write({
__type: 'testStart',
suiteId: payload.suite.id,
testId: payload.test.id,
})
},

testSuccess: (payload) => {
write({
__type: 'testSuccess',
suiteId: payload.suite.id,
testId: payload.test.id,
duration: payload.test.duration,
})
},

testFail: (payload) => {
write({
___type: 'testFail',
suiteId: payload.suite.id,
testId: payload.test.id,
duration: payload.test.duration,
error: payload.test.error,
})
},

coverageSummary: (payload) => {
write({
__type: 'coverageSummary',
...payload,
})
},

summary: (payload) => {
write({
__type: 'summary',
...payload,
})
},
}
}
5 changes: 5 additions & 0 deletions packages/peeky-runner/src/run-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { setupRunner } from './runner.js'
import { getStats } from './stats.js'
import { computeCoveredLines, getEmptyCoverageFromFiles, mergeCoverage } from './runtime/coverage.js'
import { createConsoleFancyReporter } from './reporters/console-fancy.js'
import { createRawReporter } from './reporters/raw.js'

export interface RunAllOptions {
quickTestFilter?: string
Expand All @@ -14,6 +15,10 @@ export async function runAllTests (config: ProgramPeekyConfig, options: RunAllOp
const reporters = config.reporters ? config.reporters.map(id => {
if (id === 'console-fancy') {
return createConsoleFancyReporter()
} else if (id === 'console-json') {
return createRawReporter(data => {
console.log(JSON.stringify(data))
})
}
}) : [
createConsoleFancyReporter(),
Expand Down

0 comments on commit 531ea31

Please sign in to comment.