@ephox/bedrock-common
Advanced tools
Comparing version 9.3.2 to 10.0.0
@@ -9,3 +9,3 @@ import * as JsDiff from 'diff'; | ||
var texts = c.value; | ||
var tz = texts.map(function (t) { return prefix + htmlentities(t) + suffix + "<br />"; }); | ||
var tz = texts.map(function (t) { return prefix + htmlentities(t) + suffix + '<br />'; }); | ||
return tz.join(''); | ||
@@ -12,0 +12,0 @@ }); |
@@ -1,6 +0,7 @@ | ||
import { TestError } from './TestError'; | ||
export interface LoggedError { | ||
error: TestError; | ||
import { LoggedError, TestLabel } from './Main'; | ||
import { JsError, TestError } from './TestError'; | ||
export interface LoggedError extends JsError { | ||
logs: string[]; | ||
} | ||
export declare const isLoggedError: (error: TestLabel | TestError | LoggedError) => error is LoggedError.LoggedError; | ||
export declare const loggedError: (error: TestError, logs: string[]) => LoggedError; |
@@ -0,4 +1,9 @@ | ||
export var isLoggedError = function (error) { | ||
return typeof error === 'object' && Object.prototype.hasOwnProperty.call(error, 'logs'); | ||
}; | ||
export var loggedError = function (error, logs) { | ||
return ({ error: error, logs: logs }); | ||
var logged = error; | ||
logged.logs = logs; | ||
return logged; | ||
}; | ||
//# sourceMappingURL=LoggedError.js.map |
@@ -1,4 +0,10 @@ | ||
import * as TestError from './TestError'; | ||
import * as Failure from './Failure'; | ||
import { Global } from './Global'; | ||
import * as LoggedError from './LoggedError'; | ||
import * as Reporter from './Reporter'; | ||
export { TestError, LoggedError, Reporter }; | ||
import * as TestError from './TestError'; | ||
import { TestLabel } from './TestLabel'; | ||
import * as TestLogs from './TestLogs'; | ||
import { Context, ExecuteFn, Hook, HookType, Runnable, RunnableState, Suite, Test, TestGlobals } from './TestTypes'; | ||
declare type TestThrowable = TestLabel | TestError.TestError; | ||
export { Failure, Global, TestError, LoggedError, Reporter, TestLabel, TestLogs, TestThrowable, Context, ExecuteFn, Hook, HookType, Runnable, RunnableState, Suite, Test, TestGlobals }; |
@@ -1,5 +0,9 @@ | ||
import * as TestError from './TestError'; | ||
import * as Failure from './Failure'; | ||
import { Global } from './Global'; | ||
import * as LoggedError from './LoggedError'; | ||
import * as Reporter from './Reporter'; | ||
export { TestError, LoggedError, Reporter }; | ||
import * as TestError from './TestError'; | ||
import { TestLabel } from './TestLabel'; | ||
import * as TestLogs from './TestLogs'; | ||
export { Failure, Global, TestError, LoggedError, Reporter, TestLabel, TestLogs }; | ||
//# sourceMappingURL=Main.js.map |
@@ -5,5 +5,7 @@ import * as TestError from './TestError'; | ||
declare type TestError = TestError.TestError; | ||
export declare const pprintAssertionText: (e: TestError.PprintAssertionError) => string; | ||
export declare const html: (err: LoggedError.LoggedError) => string; | ||
export declare const text: (err: LoggedError.LoggedError) => string; | ||
declare type PprintAssertionError = TestError.PprintAssertionError; | ||
export declare const pprintAssertionErrorHtml: (e: PprintAssertionError) => string; | ||
export declare const pprintAssertionErrorText: (e: PprintAssertionError) => string; | ||
export declare const html: (err: LoggedError) => string; | ||
export declare const text: (err: LoggedError) => string; | ||
export {}; |
import * as TestError from './TestError'; | ||
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.*/ | ||
@@ -13,8 +25,8 @@ var processQUnit = function (html) { | ||
var extractError = function (err) { | ||
return err === undefined ? new Error('no error given') : err.error; | ||
return err === undefined ? new Error('no error given') : err; | ||
}; | ||
var formatExtra = function (e) { | ||
if (!e.logs) { | ||
if (e.error && e.error.stack) { | ||
var lines = e.error.stack.split('\n').filter(function (line) { | ||
if (!e.logs || e.logs.length === 0) { | ||
if (e.stack) { | ||
var lines = e.stack.split('\n').filter(function (line) { | ||
return line.indexOf('at') !== -1; | ||
@@ -35,30 +47,29 @@ }); | ||
}; | ||
var htmlDiffAssertionErrorHtml = function (e) { | ||
return "Test failure: " + e.message + "\nExpected: " + htmlentities(e.diff.expected) + "\nActual: " + htmlentities(e.diff.actual) + "\n\nHTML Diff: " + processQUnit(htmlentities(e.diff.comparison)); | ||
}; | ||
var htmlDiffAssertionErrorText = function (e) { | ||
var htmlDiffAssertionError = function (e, escape, process) { | ||
// TODO: make this look more like the PprintAssertionError | ||
// TODO: get rid of the <ins> and <del> in the text output. Probably need to change the code that throws this. | ||
return "Test failure: " + e.message + "\nExpected: " + e.diff.expected + "\nActual: " + e.diff.actual + "\n\nHTML Diff: " + e.diff.comparison; | ||
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 pprintAssertionErrorHtml = function (e) { | ||
var dh = Differ.diffPrettyHtml(e.diff.actual, e.diff.expected); | ||
return "Test failure: " + e.message + "\nExpected: \n" + htmlentities(e.diff.expected) + "\nActual: \n" + htmlentities(e.diff.actual) + "\nDiff: \n" + dh; | ||
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 pprintAssertionText = function (e) { | ||
var dh = Differ.diffPrettyText(e.diff.actual, e.diff.expected); | ||
return "Test failure: " + e.message + "\nExpected: \n" + e.diff.expected + "\nActual: \n" + 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; | ||
} | ||
}; | ||
var assertionErrorHtml = function (e) { | ||
// TODO: make this look more like the PprintAssertionError | ||
return 'Assertion error' + (e.message ? ' [' + e.message + ']' : '') + | ||
': [' + htmlentities(JSON.stringify(e.expected)) + '] ' + e.operator + | ||
' [' + htmlentities(JSON.stringify(e.actual)) + ']'; | ||
}; | ||
var assertionErrorText = function (e) { | ||
// TODO: make this look more like the PprintAssertionError | ||
return 'Assertion error' + (e.message ? ' [' + e.message + ']' : '') + | ||
': [' + (JSON.stringify(e.expected)) + '] ' + e.operator + | ||
' [' + (JSON.stringify(e.actual)) + ']'; | ||
}; | ||
var assertionErrorHtml = function (e) { return assertionError(e, htmlentities, Differ.diffPrettyHtml); }; | ||
var assertionErrorText = function (e) { return assertionError(e, identity, Differ.diffPrettyText); }; | ||
var mkHtml = function (e) { | ||
@@ -89,3 +100,3 @@ if (TestError.isHTMLDiffError(e)) { | ||
else if (TestError.isPprintAssertionError(e)) { | ||
return pprintAssertionText(e); | ||
return pprintAssertionErrorText(e); | ||
} | ||
@@ -92,0 +103,0 @@ else if (TestError.isAssertionError(e)) { |
@@ -5,5 +5,6 @@ export interface JsError extends Error { | ||
export interface AssertionError extends JsError { | ||
expected: string; | ||
actual: string; | ||
expected: any; | ||
actual: any; | ||
operator: string; | ||
showDiff?: boolean; | ||
} | ||
@@ -10,0 +11,0 @@ export interface HtmlDiffAssertionError extends JsError { |
@@ -10,3 +10,3 @@ import * as Reporter from './Reporter'; | ||
e.toString = function () { | ||
return Reporter.pprintAssertionText(e); | ||
return Reporter.pprintAssertionErrorText(e); | ||
}; | ||
@@ -13,0 +13,0 @@ return e; |
import { assert } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import * as Differ from '../../../main/ts/api/Differ'; | ||
describe("Differ", function () { | ||
it("does stuff", function () { | ||
var text1 = "a\nx\ny\nc"; | ||
var text2 = "a\nb\nc"; | ||
assert.deepEqual(Differ.diffPrettyText(text1, text2), " | a\n" + | ||
"- | x\n" + | ||
"- | y\n" + | ||
"+ | b\n" + | ||
" | c"); | ||
assert.deepEqual(Differ.diffPrettyHtml(text1, text2), "<span>a</span><br />" + | ||
"<del style=\"background:#ffe6e6;\">x</del><br />" + | ||
"<del style=\"background:#ffe6e6;\">y</del><br />" + | ||
"<ins style=\"background:#e6ffe6;\">b</ins><br />" + | ||
"<span>c</span><br />"); | ||
describe('Differ', function () { | ||
it('does stuff', function () { | ||
var text1 = 'a\nx\ny\nc'; | ||
var text2 = 'a\nb\nc'; | ||
assert.deepEqual(Differ.diffPrettyText(text1, text2), ' | a\n' + | ||
'- | x\n' + | ||
'- | y\n' + | ||
'+ | b\n' + | ||
' | c'); | ||
assert.deepEqual(Differ.diffPrettyHtml(text1, text2), '<span>a</span><br />' + | ||
'<del style="background:#ffe6e6;">x</del><br />' + | ||
'<del style="background:#ffe6e6;">y</del><br />' + | ||
'<ins style="background:#e6ffe6;">b</ins><br />' + | ||
'<span>c</span><br />'); | ||
}); | ||
}); | ||
//# sourceMappingURL=DifferTest.js.map |
import { assert } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import * as LoggedError from '../../../main/ts/api/LoggedError'; | ||
import * as Reporter from '../../../main/ts/api/Reporter'; | ||
import * as LoggedError from '../../../main/ts/api/LoggedError'; | ||
function htmlAssertion() { | ||
var htmlAssertion = function () { | ||
var e = new Error('message"'); | ||
@@ -15,4 +15,16 @@ e.diff = { | ||
return e; | ||
} | ||
describe("Reporter", function () { | ||
}; | ||
var assertion = function () { | ||
var e = new Error('message"'); | ||
e.expected = 'abc"hello"'; | ||
e.actual = 'ab"hello"'; | ||
e.showDiff = true; | ||
e.label = '"label"1'; | ||
e.name = 'AssertionError'; | ||
return e; | ||
}; | ||
var cleanStack = function (message) { | ||
return message.replace(/Stack:(\n|.)*/, 'Stack:\n'); | ||
}; | ||
describe('Reporter', function () { | ||
it('Reports thrown js errors as html', function () { | ||
@@ -24,4 +36,4 @@ try { | ||
catch (e) { | ||
var actual = Reporter.html(LoggedError.loggedError(e, [])); | ||
var expected = 'Error: blarg<span>\n\nLogs:\n'; | ||
var actual = Reporter.html(LoggedError.loggedError(e, [' * Log Message'])); | ||
var expected = 'Error: blarg<span>\n\nLogs:\n * Log Message'; | ||
assert.deepEqual(actual, expected, 'Error message'); | ||
@@ -50,4 +62,4 @@ } | ||
catch (e) { | ||
var actual = Reporter.text(LoggedError.loggedError(e, [])); | ||
var expected = 'Error: blarg<span>\n\nLogs:\n'; | ||
var actual = Reporter.text(LoggedError.loggedError(e, [' * Log Message'])); | ||
var expected = 'Error: blarg<span>\n\nLogs:\n * Log Message'; | ||
assert.deepEqual(actual, expected, 'Error message'); | ||
@@ -64,3 +76,3 @@ } | ||
// NOTE: the <ins> and <del> are supposed to remain | ||
var expected = 'Test failure: message"\n' + | ||
var expected = 'Test failure: message"\n' + | ||
'Expected: abc"hello"\n' + | ||
@@ -71,4 +83,4 @@ 'Actual: ab"hello"\n' + | ||
'\n' + | ||
'Logs:\n'; | ||
assert.deepEqual(actual, expected, 'Error message'); | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
@@ -89,7 +101,26 @@ }); | ||
'\n' + | ||
'Logs:\n'; | ||
assert.deepEqual(actual, expected, 'Error message'); | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
}); | ||
it('Reports thrown AssertionError errors as html', function () { | ||
try { | ||
// noinspection ExceptionCaughtLocallyJS | ||
throw assertion(); | ||
} | ||
catch (e) { | ||
var actual = Reporter.html(LoggedError.loggedError(e, [])); | ||
var expected = 'Assertion error: message"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'<del style="background:#ffe6e6;">ab"hello"</del><br /><ins style="background:#e6ffe6;">abc"hello"</ins><br />\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
}); | ||
}); | ||
//# sourceMappingURL=ReporterTest.js.map |
import { describe, it } from 'mocha'; | ||
import { assert } from 'chai'; | ||
import * as TestError from '../../../main/ts/api/TestError'; | ||
describe("PprintAssertionError.toString()", function () { | ||
it("includes a diff", function () { | ||
describe('PprintAssertionError.toString()', function () { | ||
it('includes a diff', function () { | ||
var actual = TestError.pprintAssertionError('message', 'b', 'a').toString(); | ||
var expected = 'Test failure: message\n' + | ||
'Expected: \n' + | ||
'Expected:\n' + | ||
'b\n' + | ||
'Actual: \n' + | ||
'Actual:\n' + | ||
'a\n' + | ||
'Diff: \n' + | ||
'Diff:\n' + | ||
'- | a\n' + | ||
@@ -14,0 +14,0 @@ '+ | b'; |
{ | ||
"name": "@ephox/bedrock-common", | ||
"version": "9.3.2", | ||
"version": "10.0.0", | ||
"author": "Tiny Technologies Inc", | ||
@@ -23,3 +23,6 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "be4dde2091df43967b03d8e28d46fcd86ca38ec5" | ||
"dependencies": { | ||
"diff": "^4.0.1" | ||
}, | ||
"gitHead": "5a3e35056d38b48b81503e7ee256276c3544cd02" | ||
} |
@@ -11,3 +11,3 @@ import * as JsDiff from 'diff'; | ||
const texts = c.value; | ||
const tz = texts.map((t) => prefix + htmlentities(t) + suffix + "<br />"); | ||
const tz = texts.map((t) => prefix + htmlentities(t) + suffix + '<br />'); | ||
return tz.join(''); | ||
@@ -18,3 +18,3 @@ }); | ||
export const diffPrettyText = (text1: string, text2: string) => { | ||
export const diffPrettyText = (text1: string, text2: string): string => { | ||
const changes: ArrayChange<string>[] = JsDiff.diffArrays(text1.split('\n'), text2.split('\n')); | ||
@@ -21,0 +21,0 @@ const lines = changes.map((c) => { |
@@ -1,9 +0,15 @@ | ||
import { TestError } from './TestError'; | ||
import { LoggedError, TestLabel } from './Main'; | ||
import { JsError, TestError } from './TestError'; | ||
export interface LoggedError { | ||
error: TestError; | ||
export interface LoggedError extends JsError { | ||
logs: string[]; | ||
} | ||
export const loggedError = (error: TestError, logs: string[]): LoggedError => | ||
({error, logs}); | ||
export const isLoggedError = (error: TestLabel | TestError | LoggedError): error is LoggedError => | ||
typeof error === 'object' && Object.prototype.hasOwnProperty.call(error, 'logs'); | ||
export const loggedError = (error: TestError, logs: string[]): LoggedError => { | ||
const logged = error as LoggedError; | ||
logged.logs = logs; | ||
return logged; | ||
}; |
@@ -1,5 +0,31 @@ | ||
import * as TestError from './TestError'; | ||
import * as Failure from './Failure'; | ||
import { Global } from './Global'; | ||
import * as LoggedError from './LoggedError'; | ||
import * as Reporter from './Reporter'; | ||
import * as TestError from './TestError'; | ||
import { TestLabel } from './TestLabel'; | ||
import * as TestLogs from './TestLogs'; | ||
import { Context, ExecuteFn, Hook, HookType, Runnable, RunnableState, Suite, Test, TestGlobals } from './TestTypes'; | ||
export { TestError, LoggedError, Reporter }; | ||
type TestThrowable = TestLabel | TestError.TestError; | ||
export { | ||
Failure, | ||
Global, | ||
TestError, | ||
LoggedError, | ||
Reporter, | ||
TestLabel, | ||
TestLogs, | ||
TestThrowable, | ||
Context, | ||
ExecuteFn, | ||
Hook, | ||
HookType, | ||
Runnable, | ||
RunnableState, | ||
Suite, | ||
Test, | ||
TestGlobals | ||
}; |
@@ -13,2 +13,14 @@ import * as TestError from './TestError'; | ||
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.*/ | ||
@@ -22,9 +34,9 @@ const processQUnit = (html: string): string => | ||
const extractError = (err: LoggedError): TestError => | ||
err === undefined ? new Error('no error given') : err.error; | ||
const extractError = (err?: LoggedError): TestError => | ||
err === undefined ? new Error('no error given') : err; | ||
const formatExtra = (e: LoggedError): string => { | ||
if (!e.logs) { | ||
if (e.error && e.error.stack) { | ||
const lines = e.error.stack.split('\n').filter((line) => | ||
if (!e.logs || e.logs.length === 0) { | ||
if (e.stack) { | ||
const lines = e.stack.split('\n').filter((line) => | ||
line.indexOf('at') !== -1); | ||
@@ -42,56 +54,50 @@ return '\n\nStack:\n' + lines.join('\n'); | ||
const htmlDiffAssertionErrorHtml = (e: HtmlDiffAssertionError): string => { | ||
return `Test failure: ${e.message} | ||
Expected: ${htmlentities(e.diff.expected)} | ||
Actual: ${htmlentities(e.diff.actual)} | ||
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: ${processQUnit(htmlentities(e.diff.comparison))}`; | ||
HTML Diff: ${process(escape(e.diff.comparison))}`; | ||
}; | ||
const htmlDiffAssertionErrorText = (e: HtmlDiffAssertionError): string => { | ||
// TODO: make this look more like the PprintAssertionError | ||
// TODO: get rid of the <ins> and <del> in the text output. Probably need to change the code that throws this. | ||
return `Test failure: ${e.message} | ||
Expected: ${e.diff.expected} | ||
Actual: ${e.diff.actual} | ||
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); | ||
HTML Diff: ${e.diff.comparison}`; | ||
}; | ||
const pprintAssertionErrorHtml = (e: PprintAssertionError): string => { | ||
const dh = Differ.diffPrettyHtml(e.diff.actual, e.diff.expected); | ||
return `Test failure: ${e.message} | ||
Expected: | ||
${htmlentities(e.diff.expected)} | ||
Actual: | ||
${htmlentities(e.diff.actual)} | ||
Diff: | ||
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: | ||
${escape(e.diff.expected)} | ||
Actual: | ||
${escape(e.diff.actual)} | ||
Diff: | ||
${dh}`; | ||
}; | ||
export const pprintAssertionText = (e: PprintAssertionError): string => { | ||
const dh = Differ.diffPrettyText(e.diff.actual, e.diff.expected); | ||
return `Test failure: ${e.message} | ||
Expected: | ||
${e.diff.expected} | ||
Actual: | ||
${e.diff.actual} | ||
Diff: | ||
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}`; | ||
} else { | ||
return message; | ||
} | ||
}; | ||
const assertionErrorHtml = (e: AssertionError) => { | ||
// TODO: make this look more like the PprintAssertionError | ||
return 'Assertion error' + (e.message ? ' [' + e.message + ']' : '') + | ||
': [' + htmlentities(JSON.stringify(e.expected)) + '] ' + e.operator + | ||
' [' + htmlentities(JSON.stringify(e.actual)) + ']'; | ||
}; | ||
const assertionErrorHtml = (e: AssertionError): string => assertionError(e, htmlentities, Differ.diffPrettyHtml); | ||
const assertionErrorText = (e: AssertionError): string => assertionError(e, identity, Differ.diffPrettyText); | ||
const assertionErrorText = (e: AssertionError): string => { | ||
// TODO: make this look more like the PprintAssertionError | ||
return 'Assertion error' + (e.message ? ' [' + e.message + ']' : '') + | ||
': [' + (JSON.stringify(e.expected)) + '] ' + e.operator + | ||
' [' + (JSON.stringify(e.actual)) + ']'; | ||
}; | ||
const mkHtml = (e: TestError): string => { | ||
@@ -117,3 +123,3 @@ if (TestError.isHTMLDiffError(e)) { | ||
} else if (TestError.isPprintAssertionError(e)) { | ||
return pprintAssertionText(e) | ||
return pprintAssertionErrorText(e); | ||
} else if (TestError.isAssertionError(e)) { | ||
@@ -120,0 +126,0 @@ return assertionErrorText(e); |
@@ -8,5 +8,6 @@ import * as Reporter from './Reporter'; | ||
export interface AssertionError extends JsError { | ||
expected: string; | ||
actual: string; | ||
expected: any; | ||
actual: any; | ||
operator: string; | ||
showDiff?: boolean; | ||
} | ||
@@ -41,3 +42,3 @@ | ||
e.toString = (): string => { | ||
return Reporter.pprintAssertionText(e as PprintAssertionError); | ||
return Reporter.pprintAssertionErrorText(e as PprintAssertionError); | ||
}; | ||
@@ -55,1 +56,2 @@ return e as PprintAssertionError; | ||
err.name === 'AssertionError'; | ||
@@ -5,23 +5,23 @@ import { assert } from 'chai'; | ||
describe("Differ", () => { | ||
it("does stuff", () => { | ||
const text1 = "a\nx\ny\nc"; | ||
const text2 = "a\nb\nc"; | ||
describe('Differ', () => { | ||
it('does stuff', () => { | ||
const text1 = 'a\nx\ny\nc'; | ||
const text2 = 'a\nb\nc'; | ||
assert.deepEqual(Differ.diffPrettyText(text1, text2), | ||
" | a\n" + | ||
"- | x\n" + | ||
"- | y\n" + | ||
"+ | b\n" + | ||
" | c" | ||
' | a\n' + | ||
'- | x\n' + | ||
'- | y\n' + | ||
'+ | b\n' + | ||
' | c' | ||
); | ||
assert.deepEqual(Differ.diffPrettyHtml(text1, text2), | ||
"<span>a</span><br />" + | ||
"<del style=\"background:#ffe6e6;\">x</del><br />" + | ||
"<del style=\"background:#ffe6e6;\">y</del><br />" + | ||
"<ins style=\"background:#e6ffe6;\">b</ins><br />" + | ||
"<span>c</span><br />" | ||
'<span>a</span><br />' + | ||
'<del style="background:#ffe6e6;">x</del><br />' + | ||
'<del style="background:#ffe6e6;">y</del><br />' + | ||
'<ins style="background:#e6ffe6;">b</ins><br />' + | ||
'<span>c</span><br />' | ||
); | ||
}); | ||
}); |
import { assert } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import * as LoggedError from '../../../main/ts/api/LoggedError'; | ||
import * as Reporter from '../../../main/ts/api/Reporter'; | ||
import * as LoggedError from '../../../main/ts/api/LoggedError'; | ||
import { AssertionError, HtmlDiffAssertionError } from '../../../main/ts/api/TestError'; | ||
function htmlAssertion() { | ||
const htmlAssertion = (): HtmlDiffAssertionError => { | ||
const e: any = new Error('message"'); | ||
@@ -16,5 +17,18 @@ e.diff = { | ||
return e; | ||
} | ||
}; | ||
describe("Reporter", () => { | ||
const assertion = (): AssertionError => { | ||
const e: any = new Error('message"'); | ||
e.expected = 'abc"hello"'; | ||
e.actual = 'ab"hello"'; | ||
e.showDiff = true; | ||
e.label = '"label"1'; | ||
e.name = 'AssertionError'; | ||
return e; | ||
}; | ||
const cleanStack = (message: string): string => | ||
message.replace(/Stack:(\n|.)*/, 'Stack:\n'); | ||
describe('Reporter', () => { | ||
it('Reports thrown js errors as html', () => { | ||
@@ -25,5 +39,5 @@ try { | ||
} catch (e) { | ||
const actual = Reporter.html(LoggedError.loggedError(e, [])); | ||
const expected = 'Error: blarg<span>\n\nLogs:\n'; | ||
assert.deepEqual(actual, expected, 'Error message') | ||
const actual = Reporter.html(LoggedError.loggedError(e, [ ' * Log Message' ])); | ||
const expected = 'Error: blarg<span>\n\nLogs:\n * Log Message'; | ||
assert.deepEqual(actual, expected, 'Error message'); | ||
} | ||
@@ -42,3 +56,3 @@ }); | ||
'PprintAssertionError: Checking attribute: "height" of <iframe src="http://www.example.com/" width="200" height="200"></iframe>'; | ||
assert.deepEqual(actual, expected, 'Error message') | ||
assert.deepEqual(actual, expected, 'Error message'); | ||
} | ||
@@ -52,5 +66,5 @@ }); | ||
} catch (e) { | ||
const actual = Reporter.text(LoggedError.loggedError(e, [])); | ||
const expected = 'Error: blarg<span>\n\nLogs:\n'; | ||
assert.deepEqual(actual, expected, 'Error message') | ||
const actual = Reporter.text(LoggedError.loggedError(e, [ ' * Log Message' ])); | ||
const expected = 'Error: blarg<span>\n\nLogs:\n * Log Message'; | ||
assert.deepEqual(actual, expected, 'Error message'); | ||
} | ||
@@ -67,3 +81,3 @@ }); | ||
const expected = | ||
'Test failure: message"\n' + | ||
'Test failure: message"\n' + | ||
'Expected: abc"hello"\n' + | ||
@@ -74,4 +88,4 @@ 'Actual: ab"hello"\n' + | ||
'\n' + | ||
'Logs:\n'; | ||
assert.deepEqual(actual, expected, 'Error message') | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
@@ -93,7 +107,26 @@ }); | ||
'\n' + | ||
'Logs:\n'; | ||
assert.deepEqual(actual, expected, 'Error message') | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
}); | ||
it('Reports thrown AssertionError errors as html', () => { | ||
try { | ||
// noinspection ExceptionCaughtLocallyJS | ||
throw assertion(); | ||
} catch (e) { | ||
const actual = Reporter.html(LoggedError.loggedError(e, [])); | ||
const expected = | ||
'Assertion error: message"\n' + | ||
'Expected:\n' + | ||
'abc"hello"\n' + | ||
'Actual:\n' + | ||
'ab"hello"\n' + | ||
'Diff:\n' + | ||
'<del style="background:#ffe6e6;">ab"hello"</del><br /><ins style="background:#e6ffe6;">abc"hello"</ins><br />\n' + | ||
'\n' + | ||
'Stack:\n'; | ||
assert.deepEqual(cleanStack(actual), expected, 'Error message'); | ||
} | ||
}); | ||
}); |
@@ -5,12 +5,12 @@ import { describe, it } from 'mocha'; | ||
describe("PprintAssertionError.toString()", () => { | ||
it("includes a diff", () => { | ||
describe('PprintAssertionError.toString()', () => { | ||
it('includes a diff', () => { | ||
const actual = TestError.pprintAssertionError('message', 'b', 'a').toString(); | ||
const expected = | ||
'Test failure: message\n' + | ||
'Expected: \n' + | ||
'Expected:\n' + | ||
'b\n' + | ||
'Actual: \n' + | ||
'Actual:\n' + | ||
'a\n' + | ||
'Diff: \n' + | ||
'Diff:\n' + | ||
'- | a\n' + | ||
@@ -17,0 +17,0 @@ '+ | b'; |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
78565
66
1465
1
1
+ Addeddiff@^4.0.1
+ Addeddiff@4.0.2(transitive)