Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
purecatamphetamine committed Apr 17, 2018
1 parent f916dda commit 90e69ad
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "print-error",
"version": "0.1.15",
"version": "0.1.16",
"description": "Javascript print error stack trace (pretty, terminal, html, markdown, etc)",
"main": "index.umd.js",
"module": "index.es6.js",
Expand Down
5 changes: 4 additions & 1 deletion source/helpers.js
Expand Up @@ -113,8 +113,11 @@ export function convert_from_camel_case(object)

export function tabulate(text, tabs)
{
return text.split('\n').map(line =>
return text.split('\n').map((line) =>
{
if (line.trim() === '') {
return ''
}
if (tabs < 0)
{
let i = -tabs
Expand Down
29 changes: 15 additions & 14 deletions source/html.js
Expand Up @@ -14,8 +14,8 @@ export default function render(error, options = {})
<html>
<head>
<title>Error</title>
${getErrorPageStyle(options)}
${ERROR_STACK_STYLE}
${tabulate(getErrorPageStyle(options), 4)}
${tabulate(ERROR_STACK_STYLE, 4)}
</head>
<body>\n${renderErrorStack(error)}
</body>
Expand All @@ -41,11 +41,10 @@ export function renderErrorStack(error)

const markup =
`
<h1 class="print-error-stack__heading${i === 0 ? '' : '--secondary' }">${escape_html(group.title)}</h1>
<h1 class="print-error-stack__heading${i === 0 ? '' : ' print-error-stack__heading--secondary' }">${escape_html(group.title)}</h1>
<ul class="print-error-stack">\n${tabulate(list_items_markup, 4)}
</ul>
`

</ul>`

return tabulate(markup, -3)
})
.join('')
Expand Down Expand Up @@ -101,8 +100,9 @@ function escape_html(text)
return text.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
}

export const ERROR_STACK_STYLE = `
<style>
export const ERROR_STACK_STYLE = tabulate
(
` <style>
.print-error-stack__heading
{
font-size : 140%;
Expand Down Expand Up @@ -157,13 +157,14 @@ export const ERROR_STACK_STYLE = `
color: #0091C2;
font-weight: bold;
}
</style>
`
</style>`,
-1)

function getErrorPageStyle(options)
{
return `
<style>
return tabulate
(
` <style>
html
{
font-family : Monospace, Arial;
Expand All @@ -177,6 +178,6 @@ function getErrorPageStyle(options)
margin-left : 2.3em;
margin-right : 2.3em;
}
</style>
`
</style>`,
-2)
}
6 changes: 3 additions & 3 deletions test/examples/error.html
Expand Up @@ -15,7 +15,8 @@
margin-left : 2.3em;
margin-right : 2.3em;
}

</style>
<style>
.print-error-stack__heading
{
font-size : 140%;
Expand Down Expand Up @@ -142,8 +143,7 @@ <h1 class="print-error-stack__heading">Testing error</h1>
</div>
</li>
</ul>

<h1 class="print-error-stack__heading--secondary">From previous event</h1>
<h1 class="print-error-stack__heading print-error-stack__heading--secondary">From previous event</h1>
<ul class="print-error-stack">
<li class="print-error-stack__entry">
<span class="print-error-stack__file-name">server.js</span><span class="print-error-stack__colon">:</span><span class="print-error-stack__line-number">153</span>
Expand Down
4 changes: 3 additions & 1 deletion test/helpers.js
Expand Up @@ -120,6 +120,8 @@ describe(`helpers`, function()

it(`should tabulate`, function()
{
tabulate('', 1).should.equal('\t')
tabulate('', 1).should.equal('')
tabulate('', -1).should.equal('')
tabulate('a', 1).should.equal('\ta')
})
})
6 changes: 2 additions & 4 deletions test/html.js
Expand Up @@ -9,11 +9,9 @@ describe(`html`, function()
{
const markup = fs.readFileSync(path.join(__dirname, 'examples/error.html'), 'utf8')

// Commented out because of issues with line endings on Windows.
// It works.
//
// console.log(html(global.error))
// html(global.error, { fontSize: '20px' }).should.equal(markup)
// Convert line endings on Windows.
html(global.error, { fontSize: '20px' }).should.equal(markup.replace(/\r/g, ''))

// Examine the output.
// fs.writeFileSync(path.join(__dirname, 'examples/error.actual.html'), html(global.error, { fontSize: '20px' }), 'utf8')
Expand Down
6 changes: 2 additions & 4 deletions test/markdown.js
Expand Up @@ -9,10 +9,8 @@ describe(`markdown`, function()
{
const markup = fs.readFileSync(path.join(__dirname, 'examples/error.md'), 'utf8')

// Commented out because of issues with line endings on Windows.
// It works.
//
// console.log(markdown(global.error))
// markdown(global.error).should.equal(markup)
// Convert line endings on Windows.
markdown(global.error).should.equal(markup.replace(/\r/g, ''))
})
})

0 comments on commit 90e69ad

Please sign in to comment.