@ephox/bedrock-common
Advanced tools
Comparing version 11.2.1 to 11.3.0
@@ -0,1 +1,2 @@ | ||
import { ErrorData } from './ErrorExtractor'; | ||
import * as Failure from './Failure'; | ||
@@ -10,2 +11,2 @@ import { Global } from './Global'; | ||
declare type TestThrowable = TestLabel | TestError.TestError; | ||
export { Failure, Global, TestError, LoggedError, Reporter, TestLabel, TestLogs, TestThrowable, Context, ExecuteFn, Hook, HookType, Runnable, RunnableState, Suite, Test, TestGlobals }; | ||
export { Failure, Global, TestError, LoggedError, ErrorData, Reporter, TestLabel, TestLogs, TestThrowable, Context, ExecuteFn, Hook, HookType, Runnable, RunnableState, Suite, Test, TestGlobals }; |
import * as TestError from './TestError'; | ||
import * as ErrorExtractor from './ErrorExtractor'; | ||
import * as LoggedError from './LoggedError'; | ||
declare type LoggedError = LoggedError.LoggedError; | ||
declare type TestError = TestError.TestError; | ||
declare type PprintAssertionError = TestError.PprintAssertionError; | ||
export declare const pprintAssertionErrorHtml: (e: PprintAssertionError) => string; | ||
export declare const pprintAssertionErrorText: (e: PprintAssertionError) => string; | ||
declare type ErrorData = ErrorExtractor.ErrorData; | ||
export declare const pprintAssertionError: (e: PprintAssertionError) => string; | ||
export declare const data: (err: LoggedError) => ErrorData; | ||
export declare const dataHtml: (err: ErrorData) => string; | ||
export declare const dataText: (err: ErrorData) => string; | ||
export declare const html: (err: LoggedError) => string; | ||
export declare const text: (err: LoggedError) => string; | ||
export {}; |
@@ -1,16 +0,5 @@ | ||
import * as TestError from './TestError'; | ||
import * as ErrorExtractor from './ErrorExtractor'; | ||
import * as Differ from './Differ'; | ||
import { htmlentities } from './StringUtils'; | ||
var identity = function (val) { return val; }; | ||
var stringify = function (e) { | ||
if (e === undefined) { | ||
return 'undefined'; | ||
} | ||
else if (typeof e === 'string') { | ||
return e; | ||
} | ||
else { | ||
return JSON.stringify(e); | ||
} | ||
}; | ||
/* Required to make <del> and <ins> stay as tags.*/ | ||
@@ -24,99 +13,64 @@ var processQUnit = function (html) { | ||
}; | ||
var extractError = function (err) { | ||
return err === undefined ? new Error('no error given') : err; | ||
}; | ||
var formatExtra = function (e) { | ||
if (!e.logs || e.logs.length === 0) { | ||
if (e.stack) { | ||
var lines = e.stack.split('\n').filter(function (line) { | ||
return line.indexOf('at') !== -1; | ||
}); | ||
return '\n\nStack:\n' + lines.join('\n'); | ||
} | ||
else { | ||
return ''; | ||
} | ||
var pprintExtra = function (e) { | ||
if (e.logs !== undefined && e.logs.length > 0) { | ||
return "\n\nLogs:\n" + e.logs; | ||
} | ||
else { | ||
var lines = e.logs.map(function (log) { | ||
return log.replace(/\n/g, '\\n').replace(/\r/g, '\\r'); | ||
}); | ||
return '\n\nLogs:\n' + lines.join('\n'); | ||
else if (e.stack !== undefined && e.stack.length > 0) { | ||
return "\n\nStack:\n" + e.stack; | ||
} | ||
}; | ||
var htmlDiffAssertionError = function (e, escape, process) { | ||
// TODO: make this look more like the PprintAssertionError | ||
return "Test failure: " + escape(e.message) + "\nExpected: " + escape(e.diff.expected) + "\nActual: " + escape(e.diff.actual) + "\n\nHTML Diff: " + process(escape(e.diff.comparison)); | ||
}; | ||
var htmlDiffAssertionErrorHtml = function (e) { return htmlDiffAssertionError(e, htmlentities, processQUnit); }; | ||
// TODO: get rid of the <ins> and <del> in the text output. Probably need to change the code that throws this. | ||
var htmlDiffAssertionErrorText = function (e) { return htmlDiffAssertionError(e, identity, identity); }; | ||
var pprintAssertionError = function (e, escape, diff) { | ||
var dh = diff(e.diff.actual, e.diff.expected); | ||
return "Test failure: " + escape(e.message) + "\nExpected:\n" + escape(e.diff.expected) + "\nActual:\n" + escape(e.diff.actual) + "\nDiff:\n" + dh; | ||
}; | ||
export var pprintAssertionErrorHtml = function (e) { return pprintAssertionError(e, htmlentities, Differ.diffPrettyHtml); }; | ||
export var pprintAssertionErrorText = function (e) { return pprintAssertionError(e, identity, Differ.diffPrettyText); }; | ||
var assertionError = function (e, escape, diff) { | ||
var actual = stringify(e.actual); | ||
var expected = stringify(e.expected); | ||
var message = "Assertion error: " + (e.message ? escape(e.message) : ''); | ||
if (e.showDiff !== false) { | ||
var dh = diff(actual, expected); | ||
return message + "\nExpected:\n" + escape(expected) + "\nActual:\n" + escape(actual) + "\nDiff:\n" + dh; | ||
} | ||
else { | ||
return message; | ||
return ''; | ||
} | ||
}; | ||
var assertionErrorHtml = function (e) { return assertionError(e, htmlentities, Differ.diffPrettyHtml); }; | ||
var assertionErrorText = function (e) { return assertionError(e, identity, Differ.diffPrettyText); }; | ||
var mkHtml = function (e) { | ||
if (TestError.isHTMLDiffError(e)) { | ||
return htmlDiffAssertionErrorHtml(e); | ||
var pprintDiff = function (e, escape, diff) { | ||
if (e.diff) { | ||
var comparison = e.type === 'HtmlAssertion' ? escape(e.diff.comparison) : undefined; | ||
var dh = diff(e.diff.actual, e.diff.expected, comparison); | ||
return "Expected:\n" + escape(e.diff.expected) + "\nActual:\n" + escape(e.diff.actual) + "\nDiff:\n" + dh; | ||
} | ||
else if (TestError.isPprintAssertionError(e)) { | ||
return pprintAssertionErrorHtml(e); | ||
} | ||
else if (TestError.isAssertionError(e)) { | ||
return assertionErrorHtml(e); | ||
} | ||
else if (e.name && e.message) { | ||
return htmlentities(e.name + ': ' + e.message); | ||
} | ||
else if (e.toString !== undefined) { | ||
return htmlentities(String(e)); | ||
} | ||
else { | ||
return htmlentities(JSON.stringify(e)); | ||
return ''; | ||
} | ||
}; | ||
var mkText = function (e) { | ||
if (TestError.isHTMLDiffError(e)) { | ||
return htmlDiffAssertionErrorText(e); | ||
var pprintBasicError = function (e, escape, diff) { | ||
var message = escape(e.message); | ||
var diffMessage = pprintDiff(e, escape, diff); | ||
if (diffMessage.length > 0) { | ||
return message + "\n" + diffMessage; | ||
} | ||
else if (TestError.isPprintAssertionError(e)) { | ||
return pprintAssertionErrorText(e); | ||
} | ||
else if (TestError.isAssertionError(e)) { | ||
return assertionErrorText(e); | ||
} | ||
else if (e.name && e.message) { | ||
return (e.name + ': ' + e.message); | ||
} | ||
else if (e.toString !== undefined) { | ||
return String(e); | ||
} | ||
else { | ||
return JSON.stringify(e); | ||
return message; | ||
} | ||
}; | ||
var pprintError = function (e, escape, diff) { | ||
var message = pprintBasicError(e, escape, diff); | ||
var extras = escape(pprintExtra(e)); | ||
return "" + message + extras; | ||
}; | ||
export var pprintAssertionError = function (e) { | ||
var err = ErrorExtractor.getBasicErrorData(e); | ||
return pprintBasicError(err, identity, Differ.diffPrettyText); | ||
}; | ||
export var data = function (err) { | ||
return ErrorExtractor.getErrorData(err); | ||
}; | ||
export var dataHtml = function (err) { | ||
return pprintError(err, htmlentities, function (actual, expected, comparison) { | ||
return comparison !== undefined ? processQUnit(comparison) : Differ.diffPrettyHtml(actual, expected); | ||
}); | ||
}; | ||
export var dataText = function (err) { | ||
return pprintError(err, identity, function (actual, expected, comparison) { | ||
// TODO: get rid of the <ins> and <del> in the comparison. Probably need to change the code that throws HtmlAssertionError. | ||
return comparison !== undefined ? comparison : Differ.diffPrettyText(actual, expected); | ||
}); | ||
}; | ||
export var html = function (err) { | ||
var e = extractError(err); | ||
return mkHtml(e) + htmlentities(formatExtra(err)); | ||
var e = ErrorExtractor.getErrorData(err); | ||
return dataHtml(e); | ||
}; | ||
export var text = function (err) { | ||
var e = extractError(err); | ||
return mkText(e) + formatExtra(err); | ||
var e = ErrorExtractor.getErrorData(err); | ||
return dataText(e); | ||
}; | ||
//# sourceMappingURL=Reporter.js.map |
@@ -10,3 +10,3 @@ import * as Reporter from './Reporter'; | ||
e.toString = function () { | ||
return Reporter.pprintAssertionErrorText(e); | ||
return Reporter.pprintAssertionError(e); | ||
}; | ||
@@ -13,0 +13,0 @@ return e; |
@@ -74,7 +74,9 @@ import { assert } from 'chai'; | ||
var expected = 'Test failure: message"\n' + | ||
'Expected: abc"hello"\n' + | ||
'Actual: ab"hello"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'<ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'HTML Diff: <ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
@@ -92,7 +94,9 @@ assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
var expected = 'Test failure: message"\n' + | ||
'Expected: abc"hello"\n' + | ||
'Actual: ab"hello"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'<ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'HTML Diff: <ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
@@ -121,3 +125,23 @@ assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
}); | ||
it('Reports thrown AssertionError errors as text', function () { | ||
try { | ||
// noinspection ExceptionCaughtLocallyJS | ||
throw assertion(); | ||
} | ||
catch (e) { | ||
var actual = Reporter.text(LoggedError.loggedError(e, [])); | ||
var expected = 'Assertion error: message"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'- | ab"hello"\n' + | ||
'+ | abc"hello"\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
}); | ||
}); | ||
//# sourceMappingURL=ReporterTest.js.map |
{ | ||
"name": "@ephox/bedrock-common", | ||
"version": "11.2.1", | ||
"version": "11.3.0", | ||
"author": "Tiny Technologies Inc", | ||
@@ -26,3 +26,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "f57be99e8bf8eb5974f98dfb63f56875ff1f9c35" | ||
"gitHead": "de0f274ecaa8b6cb8c5193fa0c9b8b4e3caf1a3e" | ||
} |
@@ -0,1 +1,2 @@ | ||
import { ErrorData } from './ErrorExtractor'; | ||
import * as Failure from './Failure'; | ||
@@ -17,2 +18,3 @@ import { Global } from './Global'; | ||
LoggedError, | ||
ErrorData, | ||
Reporter, | ||
@@ -19,0 +21,0 @@ TestLabel, |
import * as TestError from './TestError'; | ||
import * as ErrorExtractor from './ErrorExtractor'; | ||
import * as LoggedError from './LoggedError'; | ||
@@ -8,19 +9,10 @@ import * as Differ from './Differ'; | ||
type TestError = TestError.TestError; | ||
type PprintAssertionError = TestError.PprintAssertionError; | ||
type HtmlDiffAssertionError = TestError.HtmlDiffAssertionError; | ||
type AssertionError = TestError.AssertionError; | ||
type BasicErrorData = ErrorExtractor.BasicErrorData; | ||
type ErrorData = ErrorExtractor.ErrorData; | ||
type DifferFn = (actual: string, expected: string, comparison?: string) => string; | ||
const identity = <T>(val: T): T => val; | ||
const stringify = (e: any) => { | ||
if (e === undefined) { | ||
return 'undefined'; | ||
} else if (typeof e === 'string') { | ||
return e; | ||
} else { | ||
return JSON.stringify(e); | ||
} | ||
}; | ||
/* Required to make <del> and <ins> stay as tags.*/ | ||
@@ -34,38 +26,17 @@ const processQUnit = (html: string): string => | ||
const extractError = (err?: LoggedError): TestError => | ||
err === undefined ? new Error('no error given') : err; | ||
const formatExtra = (e: LoggedError): string => { | ||
if (!e.logs || e.logs.length === 0) { | ||
if (e.stack) { | ||
const lines = e.stack.split('\n').filter((line) => | ||
line.indexOf('at') !== -1); | ||
return '\n\nStack:\n' + lines.join('\n'); | ||
} else { | ||
return ''; | ||
} | ||
const pprintExtra = (e: ErrorData): string => { | ||
if (e.logs !== undefined && e.logs.length > 0) { | ||
return `\n\nLogs:\n${e.logs}`; | ||
} else if (e.stack !== undefined && e.stack.length > 0) { | ||
return `\n\nStack:\n${e.stack}`; | ||
} else { | ||
const lines = e.logs.map((log) => | ||
log.replace(/\n/g, '\\n').replace(/\r/g, '\\r')); | ||
return '\n\nLogs:\n' + lines.join('\n'); | ||
return ''; | ||
} | ||
}; | ||
const htmlDiffAssertionError = (e: HtmlDiffAssertionError, escape: (value: string) => string, process: (value: string) => string): string => { | ||
// TODO: make this look more like the PprintAssertionError | ||
return `Test failure: ${escape(e.message)} | ||
Expected: ${escape(e.diff.expected)} | ||
Actual: ${escape(e.diff.actual)} | ||
HTML Diff: ${process(escape(e.diff.comparison))}`; | ||
}; | ||
const htmlDiffAssertionErrorHtml = (e: HtmlDiffAssertionError): string => htmlDiffAssertionError(e, htmlentities, processQUnit); | ||
// TODO: get rid of the <ins> and <del> in the text output. Probably need to change the code that throws this. | ||
const htmlDiffAssertionErrorText = (e: HtmlDiffAssertionError): string => htmlDiffAssertionError(e, identity, identity); | ||
const pprintAssertionError = (e: PprintAssertionError, escape: (value: string) => string, diff: (actual: string, expected: string) => string): string => { | ||
const dh = diff(e.diff.actual, e.diff.expected); | ||
return `Test failure: ${escape(e.message)} | ||
Expected: | ||
const pprintDiff = (e: BasicErrorData, escape: (value: string) => string, diff: DifferFn) => { | ||
if (e.diff) { | ||
const comparison = e.type === 'HtmlAssertion' ? escape(e.diff.comparison) : undefined; | ||
const dh = diff(e.diff.actual, e.diff.expected, comparison); | ||
return `Expected: | ||
${escape(e.diff.expected)} | ||
@@ -76,20 +47,12 @@ Actual: | ||
${dh}`; | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
export const pprintAssertionErrorHtml = (e: PprintAssertionError): string => pprintAssertionError(e, htmlentities, Differ.diffPrettyHtml); | ||
export const pprintAssertionErrorText = (e: PprintAssertionError): string => pprintAssertionError(e, identity, Differ.diffPrettyText); | ||
const assertionError = (e: AssertionError, escape: (value: string) => string, diff: (actual: string, expected: string) => string): string => { | ||
const actual = stringify(e.actual); | ||
const expected = stringify(e.expected); | ||
const message = `Assertion error: ${e.message ? escape(e.message) : ''}`; | ||
if (e.showDiff !== false) { | ||
const dh = diff(actual, expected); | ||
return `${message} | ||
Expected: | ||
${escape(expected)} | ||
Actual: | ||
${escape(actual)} | ||
Diff: | ||
${dh}`; | ||
const pprintBasicError = (e: BasicErrorData, escape: (value: string) => string, diff: DifferFn): string => { | ||
const message = escape(e.message); | ||
const diffMessage = pprintDiff(e, escape, diff); | ||
if (diffMessage.length > 0) { | ||
return `${message}\n${diffMessage}`; | ||
} else { | ||
@@ -100,45 +63,35 @@ return message; | ||
const assertionErrorHtml = (e: AssertionError): string => assertionError(e, htmlentities, Differ.diffPrettyHtml); | ||
const assertionErrorText = (e: AssertionError): string => assertionError(e, identity, Differ.diffPrettyText); | ||
const mkHtml = (e: TestError): string => { | ||
if (TestError.isHTMLDiffError(e)) { | ||
return htmlDiffAssertionErrorHtml(e); | ||
} else if (TestError.isPprintAssertionError(e)) { | ||
return pprintAssertionErrorHtml(e); | ||
} else if (TestError.isAssertionError(e)) { | ||
return assertionErrorHtml(e); | ||
} else if (e.name && e.message) { | ||
return htmlentities(e.name + ': ' + e.message); | ||
} else if (e.toString !== undefined) { | ||
return htmlentities(String(e)); | ||
} else { | ||
return htmlentities(JSON.stringify(e)); | ||
} | ||
const pprintError = (e: ErrorData, escape: (value: string) => string, diff: DifferFn): string => { | ||
const message = pprintBasicError(e, escape, diff); | ||
const extras = escape(pprintExtra(e)); | ||
return `${message}${extras}`; | ||
}; | ||
const mkText = (e: TestError): string => { | ||
if (TestError.isHTMLDiffError(e)) { | ||
return htmlDiffAssertionErrorText(e); | ||
} else if (TestError.isPprintAssertionError(e)) { | ||
return pprintAssertionErrorText(e); | ||
} else if (TestError.isAssertionError(e)) { | ||
return assertionErrorText(e); | ||
} else if (e.name && e.message) { | ||
return (e.name + ': ' + e.message); | ||
} else if (e.toString !== undefined) { | ||
return String(e); | ||
} else { | ||
return JSON.stringify(e); | ||
} | ||
export const pprintAssertionError = (e: PprintAssertionError): string => { | ||
const err = ErrorExtractor.getBasicErrorData(e); | ||
return pprintBasicError(err, identity, Differ.diffPrettyText); | ||
}; | ||
export const data = (err: LoggedError): ErrorData => | ||
ErrorExtractor.getErrorData(err); | ||
export const dataHtml = (err: ErrorData): string => | ||
pprintError(err, htmlentities, (actual, expected, comparison) => { | ||
return comparison !== undefined ? processQUnit(comparison) : Differ.diffPrettyHtml(actual, expected); | ||
}); | ||
export const dataText = (err: ErrorData): string => | ||
pprintError(err, identity, (actual, expected, comparison) => { | ||
// TODO: get rid of the <ins> and <del> in the comparison. Probably need to change the code that throws HtmlAssertionError. | ||
return comparison !== undefined ? comparison : Differ.diffPrettyText(actual, expected); | ||
}); | ||
export const html = (err: LoggedError): string => { | ||
const e = extractError(err); | ||
return mkHtml(e) + htmlentities(formatExtra(err)); | ||
const e = ErrorExtractor.getErrorData(err); | ||
return dataHtml(e); | ||
}; | ||
export const text = (err: LoggedError): string => { | ||
const e = extractError(err); | ||
return mkText(e) + formatExtra(err); | ||
}; | ||
const e = ErrorExtractor.getErrorData(err); | ||
return dataText(e); | ||
}; |
@@ -41,3 +41,3 @@ import * as Reporter from './Reporter'; | ||
e.toString = (): string => { | ||
return Reporter.pprintAssertionErrorText(e as PprintAssertionError); | ||
return Reporter.pprintAssertionError(e as PprintAssertionError); | ||
}; | ||
@@ -44,0 +44,0 @@ return e as PprintAssertionError; |
@@ -78,7 +78,9 @@ import { assert } from 'chai'; | ||
'Test failure: message"\n' + | ||
'Expected: abc"hello"\n' + | ||
'Actual: ab"hello"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'<ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'HTML Diff: <ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
@@ -97,7 +99,9 @@ assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
'Test failure: message"\n' + | ||
'Expected: abc"hello"\n' + | ||
'Actual: ab"hello"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'<ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'HTML Diff: <ins>blah</ins><del>hello</del>"hello"<span>\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
@@ -127,2 +131,23 @@ assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
}); | ||
it('Reports thrown AssertionError errors as text', () => { | ||
try { | ||
// noinspection ExceptionCaughtLocallyJS | ||
throw assertion(); | ||
} catch (e) { | ||
const actual = Reporter.text(LoggedError.loggedError(e, [])); | ||
const expected = | ||
'Assertion error: message"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'- | ab"hello"\n' + | ||
'+ | abc"hello"\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
85013
70
1637