power-assert-renderer-assertion
Advanced tools
Comparing version 1.0.7 to 1.1.0
37
index.js
'use strict'; | ||
var BaseRenderer = require('power-assert-renderer-base'); | ||
var stringWidth = require('power-assert-util-string-width'); | ||
var inherits = require('util').inherits; | ||
@@ -12,2 +13,3 @@ | ||
AssertionRenderer.prototype.onStart = function (context) { | ||
this.context = context; | ||
this.assertionLine = context.source.content; | ||
@@ -19,4 +21,39 @@ }; | ||
this.write(this.assertionLine); | ||
var e = this.context.source.error; | ||
if (e && e instanceof SyntaxError) { | ||
var re = /Unexpected token \(1\:(\d+)\)/; | ||
var matchResult = re.exec(e.message); | ||
if (matchResult) { | ||
var syntaxErrorIndex = Number(matchResult[1]); | ||
this.renderValueAt(syntaxErrorIndex, '?'); | ||
this.renderValueAt(syntaxErrorIndex, '?'); | ||
this.renderValueAt(syntaxErrorIndex, e.toString()); | ||
this.renderValueAt(0, ''); | ||
this.renderValueAt(0, 'If you are using `babel-plugin-espower` and want to use experimental syntax in your assert(), you should set `embedAst` option to true.'); | ||
this.renderValueAt(0, 'see: https://github.com/power-assert-js/babel-plugin-espower#optionsembedast'); | ||
} | ||
} | ||
}; | ||
AssertionRenderer.prototype.renderValueAt = function (idx, str) { | ||
var row = createRow(stringWidth(this.assertionLine), ' '); | ||
replaceColumn(idx, row, str); | ||
this.write(row.join('')); | ||
}; | ||
function replaceColumn (columnIndex, row, str) { | ||
var i, width = stringWidth(str); | ||
for (i = 0; i < width; i += 1) { | ||
row.splice(columnIndex + i, 1, str.charAt(i)); | ||
} | ||
} | ||
function createRow (numCols, initial) { | ||
var row = [], i; | ||
for(i = 0; i < numCols; i += 1) { | ||
row[i] = initial; | ||
} | ||
return row; | ||
} | ||
module.exports = AssertionRenderer; |
{ | ||
"name": "power-assert-renderer-assertion", | ||
"description": "assertion renderer for power-assert context", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -14,6 +14,8 @@ "name": "Takuto Wada", | ||
"dependencies": { | ||
"power-assert-renderer-base": "^1.0.7" | ||
"power-assert-renderer-base": "^1.1.0", | ||
"power-assert-util-string-width": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.4.5" | ||
"mocha": "^2.4.5", | ||
"power-assert-context-reducer-ast": "^1.1.0" | ||
}, | ||
@@ -20,0 +22,0 @@ "files": [ |
@@ -49,3 +49,3 @@ [![power-assert][power-assert-banner]][power-assert-url] | ||
[license-url]: http://twada.mit-license.org/ | ||
[license-url]: https://github.com/twada/power-assert-runtime/blob/master/LICENSE | ||
[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg |
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
4170
49
2
2
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedpower-assert-util-string-width@1.2.0(transitive)