@travetto/test
Advanced tools
Comparing version 0.0.28 to 0.0.29
@@ -31,3 +31,3 @@ { | ||
}, | ||
"version": "0.0.28" | ||
"version": "0.0.29" | ||
} |
@@ -26,3 +26,3 @@ import * as yaml from 'js-yaml'; | ||
const { test } = e; | ||
let header = `${test.suiteName} - ${test.method}`; | ||
let header = `${test.className} - ${test.methodName}`; | ||
if (test.description) { | ||
@@ -29,0 +29,0 @@ header += `: ${test.description}`; |
@@ -5,2 +5,4 @@ import { Class } from '@travetto/registry'; | ||
export type SuitePhase = 'beforeAll' | 'beforeEach' | 'afterAll' | 'afterEach'; | ||
export function Suite(description?: string, extra?: Partial<SuiteConfig>) { | ||
@@ -13,3 +15,3 @@ return (target: Class<any>) => { | ||
function listener(phase: 'beforeAll' | 'beforeEach' | 'afterAll' | 'afterEach') { | ||
function listener(phase: SuitePhase) { | ||
return (inst: any, prop: string, descriptor: PropertyDescriptor) => { | ||
@@ -16,0 +18,0 @@ TestRegistry.registerPendingListener(inst.constructor, descriptor.value, phase); |
@@ -6,7 +6,8 @@ import { TestConfig, TestResult } from './test'; | ||
class: Class; | ||
className: string; | ||
file: string; | ||
lines: { start: number, end: number }; | ||
instance: any; | ||
name: string; | ||
description: string; | ||
line: number; | ||
lineEnd: number; | ||
tests: TestConfig[]; | ||
@@ -27,8 +28,6 @@ beforeAll: Function[]; | ||
export interface SuiteResult extends Counts { | ||
className: string; | ||
file: string; | ||
line: number; | ||
lineEnd: number; | ||
class: string; | ||
lines: { start: number, end: number }; | ||
tests: TestResult[]; | ||
name: string; | ||
} | ||
@@ -35,0 +34,0 @@ |
@@ -5,8 +5,7 @@ import { Class } from '@travetto/registry/src/model/types'; | ||
class: Class<any>; | ||
suiteName: string; | ||
className: string; | ||
description: string; | ||
line: number; | ||
lineEnd: number; | ||
file: string; | ||
method: string; | ||
lines: { start: number, end: number }; | ||
methodName: string; | ||
shouldError: string | RegExp | Function; | ||
@@ -21,6 +20,6 @@ skip: boolean; | ||
message?: string; | ||
error?: Error; | ||
file: string; | ||
line: number; | ||
text: string; | ||
error?: Error; | ||
} | ||
@@ -31,7 +30,6 @@ | ||
error?: Error; | ||
line: number; | ||
lineEnd: number; | ||
file: string; | ||
method: string; | ||
suiteName: string; | ||
lines: { start: number, end: number }; | ||
methodName: string; | ||
className: string; | ||
description: string; | ||
@@ -38,0 +36,0 @@ assertions: Assertion[], |
@@ -11,3 +11,6 @@ import * as fs from 'fs'; | ||
import { Consumer } from '../consumer'; | ||
import { SuitePhase } from '..'; | ||
export const BREAKOUT = Symbol('breakout'); | ||
export class ExecuteUtil { | ||
@@ -17,3 +20,3 @@ | ||
static async affixProcess(suite: SuiteConfig, result: SuiteResult, phase: 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach') { | ||
static async affixProcess(suite: SuiteConfig, result: SuiteResult, phase: SuitePhase) { | ||
try { | ||
@@ -24,10 +27,9 @@ for (const fn of suite[phase]) { | ||
} catch (error) { | ||
const { line, file } = AssertUtil.readFilePosition(error, suite.class.__filename); | ||
const { line, file } = AssertUtil.readFilePosition(error, suite.file); | ||
result.tests.push({ | ||
status: 'fail', | ||
suiteName: suite.name, | ||
method: phase, | ||
className: suite.className, | ||
methodName: phase, | ||
description: phase, | ||
line, | ||
lineEnd: line, | ||
lines: { start: line, end: line }, | ||
file, | ||
@@ -38,3 +40,3 @@ error, | ||
} as TestResult); | ||
throw new Error('breakout'); | ||
throw BREAKOUT; | ||
} | ||
@@ -49,20 +51,19 @@ } | ||
const test = { | ||
line: suite.line, | ||
lineEnd: suite.lineEnd, | ||
suiteName: suite.name, | ||
className: suite.className, | ||
lines: { ...suite.lines }, | ||
status: 'fail', | ||
method: 'all', | ||
methodName: 'all', | ||
error: e, | ||
output: { error: e.stack }, | ||
assertions: [{ | ||
file: suite.file, | ||
line: suite.lines.start, | ||
text: '(init)', | ||
error: e, | ||
line: suite.line, | ||
message: e.message, | ||
file: suite.class.__filename, | ||
operator: 'throws', | ||
text: '(init)' | ||
operator: 'throws' | ||
}], | ||
class: suite.class.name, | ||
description: '', | ||
file: suite.class.__filename | ||
file: suite.file | ||
} as TestResult; | ||
@@ -131,7 +132,6 @@ | ||
const result: Partial<TestResult> = { | ||
method: test.method, | ||
methodName: test.methodName, | ||
description: test.description, | ||
suiteName: test.suiteName, | ||
line: test.line, | ||
lineEnd: test.lineEnd, | ||
className: test.className, | ||
lines: { ...test.lines }, | ||
file: test.file, | ||
@@ -151,3 +151,3 @@ status: 'skip' | ||
const timeout = new Promise((_, reject) => setTimeout(reject, this.timeout).unref()); | ||
const res = await Promise.race([suite.instance[test.method](), timeout]); | ||
const res = await Promise.race([suite.instance[test.methodName](), timeout]); | ||
result.status = 'success'; | ||
@@ -190,7 +190,5 @@ } catch (err) { | ||
total: 0, | ||
line: suite.line, | ||
lineEnd: suite.lineEnd, | ||
file: suite.class.__filename, | ||
class: suite.class.name, | ||
name: suite.name, | ||
lines: { ...suite.lines }, | ||
file: suite.file, | ||
className: suite.className, | ||
tests: [] | ||
@@ -224,7 +222,5 @@ }; | ||
total: 0, | ||
line: suite.line, | ||
lineEnd: suite.lineEnd, | ||
file: suite.class.__filename, | ||
class: suite.class.name, | ||
name: suite.name, | ||
lines: { ...suite.lines }, | ||
file: suite.file, | ||
className: suite.className, | ||
tests: [] | ||
@@ -272,5 +268,5 @@ }; | ||
const clses = TestRegistry.getClasses().filter(f => f.__filename === file).map(x => TestRegistry.get(x)); | ||
const cls = clses.find(x => line >= x.line && line <= x.lineEnd); | ||
const cls = clses.find(x => line >= x.lines.start && line <= x.lines.end); | ||
if (cls) { | ||
const meth = cls.tests.find(x => line >= x.line && line <= x.lineEnd); | ||
const meth = cls.tests.find(x => line >= x.lines.start && line <= x.lines.end); | ||
if (meth) { | ||
@@ -288,3 +284,3 @@ res = [cls, meth]; | ||
const clsConf = TestRegistry.get(cls); | ||
const meth = clsConf.tests.find(x => x.method === method)!; | ||
const meth = clsConf.tests.find(x => x.methodName === method)!; | ||
res = [clsConf, meth]; | ||
@@ -291,0 +287,0 @@ } else if (clsName) { |
@@ -138,3 +138,3 @@ import * as minimist from 'minimist'; | ||
try { | ||
console.log('Runner Args', this.state); | ||
console.debug('Runner Args', this.state); | ||
@@ -141,0 +141,0 @@ switch (this.state.mode) { |
@@ -16,3 +16,3 @@ import * as util from 'util'; | ||
if (TestRegistry.has(cls)) { | ||
const conf = TestRegistry.get(cls).tests.find(x => x.method === method.name); | ||
const conf = TestRegistry.get(cls).tests.find(x => x.methodName === method.name); | ||
return conf; | ||
@@ -73,3 +73,3 @@ } | ||
send('test-changed', { | ||
method: conf.method, | ||
method: conf.methodName, | ||
file: conf.file, | ||
@@ -81,3 +81,3 @@ class: conf.class.__id | ||
send('test-removed', { | ||
method: conf.method, | ||
method: conf.methodName, | ||
file: conf.file, | ||
@@ -106,3 +106,3 @@ class: conf.class.__id | ||
class: conf.class.name, | ||
method: conf.method | ||
method: conf.methodName | ||
}; | ||
@@ -109,0 +109,0 @@ } |
@@ -34,8 +34,8 @@ import { MetadataRegistry, Class, ChangeEvent } from '@travetto/registry'; | ||
config.tests = Array.from(tests) as TestConfig[]; | ||
config.name = cls.__id.split(':')[1].replace(/^test[.]/, '').replace('#', '.'); | ||
config.className = cls.__id.split(':')[1].replace(/^test[.]/, '').replace('#', '.'); | ||
if (!config.description) { | ||
config.description = config.name; | ||
config.description = config.className; | ||
} | ||
for (const t of config.tests) { | ||
t.suiteName = config.name; | ||
t.className = config.className; | ||
} | ||
@@ -42,0 +42,0 @@ return config; |
@@ -26,4 +26,3 @@ import * as ts from 'typescript'; | ||
dec.expression.arguments = ts.createNodeArray([...args, TransformUtil.fromLiteral({ | ||
line: start.line + 1, | ||
lineEnd: end.line + 1 | ||
lines: TransformUtil.fromLiteral({ start: start.line + 1, end: end.line + 1 }) | ||
})]); | ||
@@ -30,0 +29,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44715
1295