Comparing version 1.0.1 to 1.0.2
@@ -0,1 +1,9 @@ | ||
### [1.0.2](https://github.com/power-assert-js/espower/releases/tag/v1.0.2) (2015-05-30) | ||
#### Bug Fixes | ||
* use basename when incoming `options.path` is absolute and it conflicts with `options.sourceRoot` or `sourceRoot` in `options.sourceMap` ([02f7b35a](https://github.com/power-assert-js/espower/commit/02f7b35a5acad20994b745de32cf512c2b95f57a)) | ||
### [1.0.1](https://github.com/power-assert-js/espower/releases/tag/v1.0.1) (2015-05-29) | ||
@@ -2,0 +10,0 @@ |
@@ -79,2 +79,5 @@ 'use strict'; | ||
} | ||
this.filepath = useBasenameIfConflicted(this.filepath); | ||
if (!this.lineNum) { | ||
@@ -204,2 +207,11 @@ this.lineNum = currentNode.loc.start.line; | ||
function useBasenameIfConflicted (filepath) { | ||
if (filepath) { | ||
if (filepath.split(_path.sep).indexOf('..') !== -1) { | ||
filepath = _path.basename(filepath); | ||
} | ||
} | ||
return filepath; | ||
} | ||
function guessPowerAssertCalleeObjectFor (node) { | ||
@@ -206,0 +218,0 @@ switch(node.type) { |
{ | ||
"name": "espower", | ||
"description": "Power Assert feature instrumentor based on the ECMAScript AST", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Takuto Wada", |
@@ -114,3 +114,3 @@ espower | ||
Filepath of `originalAst`. If passed, espower stores filepath information for reporting. This property is optional. | ||
Filepath of `originalAst`. If passed, espower stores filepath information for reporting. If `options.path` is absolute and it conflicts with `options.sourceRoot` or `sourceRoot` in `options.sourceMap`, then filepath in power-assert output will be fall back on `basename` of `options.path`. This property is optional. | ||
@@ -117,0 +117,0 @@ |
@@ -321,18 +321,17 @@ (function (root, factory) { | ||
var compactResult = escodegen.generate(acorn.parse(originalCode, {ecmaVersion: 6, locations: true, sourceFile: opts.filepath}), { | ||
var incomingCodeAndMap = escodegen.generate(acorn.parse(originalCode, {ecmaVersion: 6, locations: true, sourceFile: opts.filepath}), { | ||
format: { | ||
compact: true | ||
}, | ||
sourceMap: true, | ||
sourceMap: opts.filepath, | ||
sourceMapRoot: opts.sourceMapRoot, | ||
sourceContent: originalCode, | ||
sourceMapWithCode: true | ||
}); | ||
var compactCode = compactResult.code; | ||
// console.log(compactCode); | ||
var incomingSourceMap = compactResult.map.toString(); | ||
// console.log(incomingSourceMap); | ||
var compactCode = incomingCodeAndMap.code; | ||
var incomingSourceMap = incomingCodeAndMap.map.toString(); | ||
var transformedPath = '/path/to/absolute/intermediate/transformed_test.js'; | ||
var espoweredAST = espower(acorn.parse(compactCode, {ecmaVersion: 6, locations: true, sourceFile: transformedPath}), { | ||
var intermediateFilepath = '/path/to/absolute/intermediate/transformed_test.js'; | ||
var espoweredAST = espower(acorn.parse(compactCode, {ecmaVersion: 6, locations: true, sourceFile: intermediateFilepath}), { | ||
patterns: [ | ||
@@ -392,2 +391,16 @@ 'assert.equal(actual, expected, [message])' | ||
}); | ||
incomingSourceMapTest('broken sourceMap: when both sources and sourceRoot in SourceMap is absolute and conflicted, fallback to basename', { | ||
filepath: '/some/path/to/project/test/original_test.js', | ||
sourceMapRoot: '/another/path/to/project/', | ||
espowerSourceRoot: null, | ||
expectedPath: 'original_test.js' | ||
}); | ||
incomingSourceMapTest('conflicted sourceRoot: when both sources and options.sourceRoot is absolute and conflicted, fallback to basename', { | ||
filepath: '/some/path/to/project/test/original_test.js', | ||
sourceMapRoot: null, | ||
espowerSourceRoot: '/another/path/to/project/', | ||
expectedPath: 'original_test.js' | ||
}); | ||
}); | ||
@@ -397,32 +410,38 @@ | ||
describe('sourceRoot option', function () { | ||
function instrumentCodeWithOptions (espowerOptions) { | ||
var jsCode = 'assert(falsyStr);'; | ||
var jsAST = acorn.parse(jsCode, {ecmaVersion: 6, locations: true, sourceFile: espowerOptions.path}); | ||
var espoweredAST = espower(jsAST, espowerOptions); | ||
return escodegen.generate(espoweredAST, {format: {compact: true}}); | ||
function sourceRootTest (testName, config) { | ||
it(testName, function () { | ||
var jsCode = 'assert(falsyStr);'; | ||
var jsAST = acorn.parse(jsCode, {ecmaVersion: 6, locations: true, sourceFile: config.path}); | ||
var espoweredAST = espower(jsAST, { | ||
path: config.incomingFilepath, | ||
sourceRoot: config.espowerSourceRoot | ||
}); | ||
var instrumentedCode = escodegen.generate(espoweredAST, {format: {compact: true}}); | ||
assert.equal(instrumentedCode, "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'" + config.filepathInGeneratedCode + "',line:1}));"); | ||
}); | ||
} | ||
it('when sourceRoot ends with slash', function () { | ||
var instrumentedCode = instrumentCodeWithOptions({ | ||
path: '/path/to/project/test/some_test.js', | ||
sourceRoot: '/path/to/project/' | ||
}); | ||
assert.equal(instrumentedCode, "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'test/some_test.js',line:1}));"); | ||
sourceRootTest('when sourceRoot ends with slash', { | ||
incomingFilepath: '/path/to/project/test/some_test.js', | ||
espowerSourceRoot: '/path/to/project/', | ||
filepathInGeneratedCode: 'test/some_test.js' | ||
}); | ||
it('when sourceRoot does not end with slash', function () { | ||
var instrumentedCode = instrumentCodeWithOptions({ | ||
path: '/path/to/project/test/some_test.js', | ||
sourceRoot: '/path/to/project' | ||
}); | ||
assert.equal(instrumentedCode, "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'test/some_test.js',line:1}));"); | ||
sourceRootTest('when sourceRoot does not end with slash', { | ||
incomingFilepath: '/path/to/project/test/some_test.js', | ||
espowerSourceRoot: '/path/to/project', | ||
filepathInGeneratedCode: 'test/some_test.js' | ||
}); | ||
it('when path is already relative, just use it even if sourceRoot exists', function () { | ||
var instrumentedCode = instrumentCodeWithOptions({ | ||
path: 'any/test/some_test.js', | ||
sourceRoot: '/path/to/any/test' | ||
}); | ||
assert.equal(instrumentedCode, "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'any/test/some_test.js',line:1}));"); | ||
sourceRootTest('when path is already relative, just use it even if sourceRoot exists', { | ||
incomingFilepath: 'any/test/some_test.js', | ||
espowerSourceRoot: '/path/to/any/test', | ||
filepathInGeneratedCode: 'any/test/some_test.js' | ||
}); | ||
sourceRootTest('when incoming absolute filepath conflicts with options.sourceRoot, fallback to basename', { | ||
incomingFilepath: '/some/path/to/project/test/original_test.js', | ||
espowerSourceRoot: '/another/path/to/project/', | ||
filepathInGeneratedCode: 'original_test.js' | ||
}); | ||
}); | ||
@@ -429,0 +448,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
732879
17810