diff --git a/index.js b/index.js index 5ec00a2..02c1f92 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,14 @@ import {errToJSON} from 'error-to-json' +/** + * @param source + */ export default async function*(source) { - let test = {}; + let test = {} - const nesting = [test]; + const nesting = [test] for await(const {data, type} of source) switch(type) @@ -13,82 +16,82 @@ export default async function*(source) case 'test:enqueue': case 'test:dequeue': case 'test:watch:drained': - break; + break case 'test:start': - test = data; - nesting.push(test); - break; + test = data + nesting.push(test) + break case 'test:pass': { - const oldTest = Object.assign(nesting.pop(), data); + const oldTest = Object.assign(nesting.pop(), data) test = nesting.at(-1) - let {passed} = test; - if(!passed) test.passed = passed = []; + let {passed} = test + if(!passed) test.passed = passed = [] - passed.push(oldTest); - break; + passed.push(oldTest) + break } case 'test:fail': { - const oldTest = Object.assign(nesting.pop(), data); - oldTest.details.error = errToJSON(oldTest.details.error); + const oldTest = Object.assign(nesting.pop(), data) + oldTest.details.error = errToJSON(oldTest.details.error) test = nesting.at(-1) - let {failed} = test; - if(!failed) test.failed = failed = []; + let {failed} = test + if(!failed) test.failed = failed = [] - failed.push(oldTest); - break; + failed.push(oldTest) + break } case 'test:plan': - Object.assign(test, data); - break; + Object.assign(test, data) + break case 'test:diagnostic': { - let {diagnostics} = test; - if(!diagnostics) test.diagnostics = diagnostics = []; + let {diagnostics} = test + if(!diagnostics) test.diagnostics = diagnostics = [] - diagnostics.push(data.message); - break; + diagnostics.push(data.message) + break } case 'test:stderr': { - let {messages} = test; - if(!messages) test.messages = messages = []; + let {messages} = test + if(!messages) test.messages = messages = [] - messages.push(Object.assign({date: new Date, type: 'stderr'}, data)); + messages.push(Object.assign({date: new Date, type: 'stderr'}, data)) - break; + break } case 'test:stdout': { - let {messages} = test; - if(!messages) test.messages = messages = []; + let {messages} = test + if(!messages) test.messages = messages = [] - messages.push(Object.assign({date: new Date, type: 'stdout'}, data)); + messages.push(Object.assign({date: new Date, type: 'stdout'}, data)) - break; + break } case 'test:coverage': { - Object.assign(test, data); + Object.assign(test, data) - yield JSON.stringify(test, null, 2); - break; + yield JSON.stringify(test, null, 2) + break } default: - throw new Error(`Unknown event type: ${type}`); + throw new Error(`Unknown event type: ${type}`) } }