@travetto/test
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -28,3 +28,3 @@ { | ||
}, | ||
"version": "0.0.4" | ||
"version": "0.0.5" | ||
} |
@@ -22,3 +22,10 @@ import { AppEnv } from '@travetto/base'; | ||
let base = process.cwd() + '/test/'; | ||
let lines = err.stack!.split('[Continued From]').find(x => x.includes(base)).split('\n').filter(x => x.includes(base)); | ||
let subParts = err.stack!.split('[Continued From]'); | ||
let sub: string = subParts.find(x => x.includes(base)); | ||
let lines: string[]; | ||
if (!sub) { | ||
lines = subParts[0].split('\n').slice(1, 2); | ||
} else { | ||
lines = sub.split('\n').filter(x => x.includes(base)); | ||
} | ||
let [file, line] = lines.pop()!.split(/[()]/g).slice(-2, -1)[0].split(':'); | ||
@@ -25,0 +32,0 @@ file = file.split(process.cwd() + '/')[1]; |
@@ -114,2 +114,25 @@ import * as fs from 'fs'; | ||
static async affixProcess(suite: SuiteConfig, result: SuiteResult, phase: 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach') { | ||
try { | ||
for (let after of suite[phase]) { | ||
await after.call(suite.instance); | ||
} | ||
} catch (error) { | ||
let { line, file } = AssertUtil.readFilePosition(error); | ||
result.tests.push({ | ||
status: 'fail', | ||
suiteName: suite.name, | ||
method: phase, | ||
description: phase, | ||
line, | ||
lineEnd: line, | ||
file, | ||
error, | ||
assertions: [], | ||
output: {} | ||
} as TestResult); | ||
throw new Error('breakout'); | ||
} | ||
} | ||
static async executeSuite(suite: SuiteConfig, emitter?: TestEmitter) { | ||
@@ -129,32 +152,32 @@ let result: SuiteResult = { | ||
for (let before of suite.beforeAll) { | ||
await before.call(suite.instance); | ||
} | ||
try { | ||
await this.affixProcess(suite, result, 'beforeAll'); | ||
for (let test of suite.tests) { | ||
if (emitter) { | ||
emitter.emit({ type: 'test', phase: 'before', test }); | ||
} | ||
for (let test of suite.tests) { | ||
if (emitter) { | ||
emitter.emit({ type: 'test', phase: 'before', test }); | ||
} | ||
for (let before of suite.beforeEach) { | ||
await before.call(suite.instance); | ||
} | ||
await this.affixProcess(suite, result, 'beforeEach'); | ||
let ret = await this.executeTest(test); | ||
result[ret.status]++; | ||
result.tests.push(ret); | ||
let ret = await this.executeTest(test); | ||
result[ret.status]++; | ||
result.tests.push(ret); | ||
if (emitter) { | ||
emitter.emit({ type: 'test', phase: 'after', test: ret }); | ||
if (emitter) { | ||
emitter.emit({ type: 'test', phase: 'after', test: ret }); | ||
} | ||
await this.affixProcess(suite, result, 'afterEach'); | ||
} | ||
for (let after of suite.afterEach) { | ||
await after.call(suite.instance); | ||
await this.affixProcess(suite, result, 'afterAll'); | ||
} catch (e) { | ||
if (e.message === 'breakout') { | ||
// Done | ||
} else { | ||
throw e; | ||
} | ||
} | ||
for (let after of suite.afterAll) { | ||
await after.call(suite.instance); | ||
} | ||
result.total = result.success + result.fail; | ||
@@ -161,0 +184,0 @@ |
254073
1029