diff --git a/CHANGELOG.md b/CHANGELOG.md index ca671f1..05b5c0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +### [1.3.2](https://github.com/power-assert-js/espower/releases/tag/v1.3.2) (2016-06-22) + + +#### Bug Fixes + + * fix breaking changes introduced in 1.3.0 and 1.3.1 + + +### [1.3.1](https://github.com/power-assert-js/espower/releases/tag/v1.3.1) (2016-06-21) + + +#### Bug Fixes + + * stop capturing SequenceExpression itself since SequenceExpressions are not enclosed in parentheses in some cases ([e8acbc61](https://github.com/power-assert-js/espower/commit/e8acbc61810454da05098baf6624b57d68deb3f9)) + + +## [1.3.0](https://github.com/power-assert-js/espower/releases/tag/v1.3.0) (2016-06-21) + + +#### Features + + * [Support SequenceExpression (i.e., comma operator)](https://github.com/power-assert-js/espower/pull/27) + + ### [1.2.1](https://github.com/power-assert-js/espower/releases/tag/v1.2.1) (2015-11-06) diff --git a/gulpfile.js b/gulpfile.js index b391f41..63e55e0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,12 +7,16 @@ var mochaPhantomJS = require('gulp-mocha-phantomjs'); var webserver = require('gulp-webserver'); var del = require('del'); var path = require('path'); +var fs = require('fs'); var source = require('vinyl-source-stream'); var through = require('through2'); var browserify = require('browserify'); var licensify = require('licensify'); +var packageJsonVersionify = require('package-json-versionify'); var dereserve = require('gulp-dereserve'); var derequire = require('gulp-derequire'); +var acorn = require('acorn'); +var espurify = require('espurify'); var config = { jshint: { src: './lib/**/*.js' @@ -146,6 +150,7 @@ gulp.task('clean_bundle', function () { gulp.task('bundle', ['clean_bundle'], function() { var b = browserify({entries: config.bundle.srcFile, standalone: config.bundle.standalone}); b.plugin(licensify); + b.transform(packageJsonVersionify, {global: true}); var bundleStream = b.bundle(); return bundleStream .pipe(source(config.bundle.destName)) @@ -160,6 +165,7 @@ LOCAL_BUILDS.forEach(function (name) { }); gulp.task(name + '_bundle', ['clean_' + name + '_bundle'], function() { var b = browserify({standalone: config[name + '_bundle'].standalone}); + b.transform(packageJsonVersionify, {global: true}); if (config[name + '_bundle'].srcFile) { b.add(config[name + '_bundle'].srcFile); } @@ -175,7 +181,15 @@ LOCAL_BUILDS.forEach(function (name) { gulp.task('clean_deps', LOCAL_BUILDS.map(function (name) { return 'clean_' + name + '_bundle'; })); gulp.task('build_deps', LOCAL_BUILDS.map(function (name) { return name + '_bundle'; })); -gulp.task('unit', function () { +gulp.task('generate_recorder_json', function (done) { + var filepath = path.join(__dirname, 'power-assert-recorder.js'); + var ast = acorn.parse(fs.readFileSync(filepath), { ecmaVersion: 6, locations: true }); + var callexp = espurify(ast).body[0].expression; + fs.writeFileSync(path.join(__dirname, 'lib', 'power-assert-recorder.json'), JSON.stringify(callexp, null, 2)); + done(); +}); + +gulp.task('unit', ['generate_recorder_json'], function () { return runMochaSimply(); }); diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 5024d5f..63cc370 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -5,7 +5,6 @@ var escodegen = require('escodegen'); var espurify = require('espurify'); var espurifyWithRaw = espurify.customize({extra: 'raw'}); var isArray = require('isarray'); -var deepEqual = require('deep-equal'); var syntax = estraverse.Syntax; var EspowerLocationDetector = require('espower-location-detector'); var EspowerError = require('./espower-error'); @@ -20,10 +19,12 @@ var canonicalCodeOptions = { }, verbatim: 'x-verbatim-espower' }; +var recorderClassAst = require('./power-assert-recorder.json'); function AssertionVisitor (matcher, options) { this.matcher = matcher; - this.options = options || {}; + this.options = options; + this.valueRecorder = null; this.locationDetector = new EspowerLocationDetector(this.options); this.currentArgumentPath = null; this.argumentModified = false; @@ -33,7 +34,6 @@ AssertionVisitor.prototype.enter = function (controller) { this.assertionPath = [].concat(controller.path()); var currentNode = controller.current(); this.canonicalCode = this.generateCanonicalCode(currentNode); - this.powerAssertCalleeObject = this.guessPowerAssertCalleeObjectFor(currentNode.callee); this.location = this.locationDetector.locationFor(currentNode); var enclosingFunc = findEnclosingFunction(controller.parents()); this.withinGenerator = enclosingFunc && enclosingFunc.generator; @@ -52,6 +52,8 @@ AssertionVisitor.prototype.enterArgument = function (controller) { return undefined; } this.verifyNotInstrumented(currentNode); + // create recorder per argument + this.valueRecorder = this.createNewRecorder(controller); // entering target argument this.currentArgumentPath = [].concat(controller.path()); return undefined; @@ -67,6 +69,7 @@ AssertionVisitor.prototype.leaveArgument = function (resultTree) { } finally { this.currentArgumentPath = null; this.argumentModified = false; + this.valueRecorder = null; } }; @@ -76,13 +79,12 @@ AssertionVisitor.prototype.captureNode = function (controller) { var path = controller.path(); var n = newNodeWithLocationCopyOf(currentNode); var relativeEsPath = path.slice(this.assertionPath.length); - var newCalleeObject = updateLocRecursively(espurify(this.powerAssertCalleeObject), n, this.options.visitorKeys); return n({ type: syntax.CallExpression, callee: n({ type: syntax.MemberExpression, computed: false, - object: newCalleeObject, + object: this.valueRecorder, property: n({ type: syntax.Identifier, name: '_capt' @@ -152,7 +154,6 @@ AssertionVisitor.prototype.generateCanonicalCode = function (node) { AssertionVisitor.prototype.captureArgument = function (node) { var n = newNodeWithLocationCopyOf(node); var props = []; - var newCalleeObject = updateLocRecursively(espurify(this.powerAssertCalleeObject), n, this.options.visitorKeys); addLiteralTo(props, n, 'content', this.canonicalCode); addLiteralTo(props, n, 'filepath', this.location.source); addLiteralTo(props, n, 'line', this.location.line); @@ -167,7 +168,7 @@ AssertionVisitor.prototype.captureArgument = function (node) { callee: n({ type: syntax.MemberExpression, computed: false, - object: newCalleeObject, + object: this.valueRecorder, property: n({ type: syntax.Identifier, name: '_expr' @@ -189,24 +190,90 @@ AssertionVisitor.prototype.verifyNotInstrumented = function (currentNode) { } var prop = currentNode.callee.property; if (prop.type === syntax.Identifier && prop.name === '_expr') { - if (astEqual(currentNode.callee.object, this.powerAssertCalleeObject)) { - var errorMessage = 'Attempted to transform AST twice.'; - if (this.options.path) { - errorMessage += ' path: ' + this.options.path; - } - throw new EspowerError(errorMessage, this.verifyNotInstrumented); + var errorMessage = 'Attempted to transform AST twice.'; + if (this.options.path) { + errorMessage += ' path: ' + this.options.path; } + throw new EspowerError(errorMessage, this.verifyNotInstrumented); } }; -AssertionVisitor.prototype.guessPowerAssertCalleeObjectFor = function (node) { - switch(node.type) { - case syntax.Identifier: - return node; - case syntax.MemberExpression: - return node.object; // Returns browser.assert when browser.assert.element(selector) +AssertionVisitor.prototype.createNewRecorder = function (controller) { + var currentScope = this.options.currentScope; + var scopeBlockEspath = findEspathOfAncestorNode(currentScope.block, controller); + var recorderConstructorName = this.getRecorderConstructorName(controller); + var recorderVariableName = this.options.transformation.generateUniqueName('rec'); + + var currentNode = controller.current(); + var createNode = newNodeWithLocationCopyOf(currentNode); + var ident = createNode({ + type: syntax.Identifier, + name: recorderVariableName + }); + var init = this.createNewExpression(createNode, recorderConstructorName); + var decl = this.createVariableDeclaration(createNode, ident, init); + this.options.transformation.register(scopeBlockEspath, function (matchNode) { + var body; + if (/Function/.test(matchNode.type)) { + var blockStatement = matchNode.body; + body = blockStatement.body; + } else { + body = matchNode.body; + } + insertAfterUseStrictDirective(decl, body); + }); + return ident; +}; + +AssertionVisitor.prototype.getRecorderConstructorName = function (controller) { + var ctorName = this.options.storage.powerAssertRecorderConstructorName; + if (!ctorName) { + ctorName = this.createRecorderClass(controller); } - return null; + return ctorName; +}; + +AssertionVisitor.prototype.createRecorderClass = function (controller) { + var globalScope = this.options.globalScope; + var globalScopeBlockEspath = findEspathOfAncestorNode(globalScope.block, controller); + var createNode = newNodeWithLocationCopyOf(globalScope.block); + var ctorName = this.options.transformation.generateUniqueName('PowerAssertRecorder'); + var ident = createNode({ + type: syntax.Identifier, + name: ctorName + }); + var classDef = updateLocRecursively(espurify(recorderClassAst), createNode, this.options.visitorKeys); + var decl = this.createVariableDeclaration(createNode, ident, classDef); + this.options.transformation.register(globalScopeBlockEspath, function (matchNode) { + insertAfterUseStrictDirective(decl, matchNode.body); + }); + this.options.storage.powerAssertRecorderConstructorName = ctorName; + return ctorName; +}; + +AssertionVisitor.prototype.createVariableDeclaration = function (createNode, ident, init) { + return createNode({ + type: syntax.VariableDeclaration, + declarations: [ + createNode({ + type: syntax.VariableDeclarator, + id: ident, + init: init + }) + ], + kind: 'var' + }); +}; + +AssertionVisitor.prototype.createNewExpression = function (createNode, constructorName) { + return createNode({ + type: syntax.NewExpression, + callee: createNode({ + type: syntax.Identifier, + name: constructorName + }), + arguments: [] + }); }; function addLiteralTo (props, createNode, name, value) { @@ -278,8 +345,40 @@ function newNodeWithLocationCopyOf (original) { }; } -function astEqual (ast1, ast2) { - return deepEqual(espurify(ast1), espurify(ast2)); +function findEspathOfAncestorNode (targetNode, controller) { + // iterate child to root + var child, parent; + var path = controller.path(); + var parents = controller.parents(); + var popUntilParent = function (key) { + if (parent[key] !== undefined) { + return; + } + popUntilParent(path.pop()); + }; + for (var i = parents.length - 1; i >= 0; i--) { + parent = parents[i]; + if (child) { + popUntilParent(path.pop()); + } + if (parent === targetNode) { + return path.join('/'); + } + child = parent; + } + return null; +} + +function insertAfterUseStrictDirective (decl, body) { + var firstBody = body[0]; + if (firstBody.type === syntax.ExpressionStatement) { + var expression = firstBody.expression; + if (expression.type === syntax.Literal && expression.value === 'use strict') { + body.splice(1,0, decl); + return; + } + } + body.unshift(decl); } function isFunction (node) { diff --git a/lib/instrumentor.js b/lib/instrumentor.js index ad851d0..f813d7c 100644 --- a/lib/instrumentor.js +++ b/lib/instrumentor.js @@ -2,12 +2,40 @@ var estraverse = require('estraverse'); var syntax = estraverse.Syntax; +var escope = require('escope'); var escallmatch = require('escallmatch'); var cloneAst = require('./clone-ast'); var AssertionVisitor = require('./assertion-visitor'); var EspowerError = require('./espower-error'); var typeName = require('type-name'); var find = require('array-find'); +var extend = require('xtend'); + +function Transformation () { + this.mutations = {}; + this.nameCounts = {}; +} +Transformation.prototype.register = function (espath, callback) { + if (!this.mutations[espath]) { + this.mutations[espath] = []; + } + this.mutations[espath].unshift(callback); +}; +Transformation.prototype.apply = function (espath, node) { + this.mutations[espath].forEach(function (callback) { + callback(node); + }); +}; +Transformation.prototype.isTarget = function (espath) { + return !!this.mutations[espath]; +}; +Transformation.prototype.generateUniqueName = function (name) { + if (!this.nameCounts[name]) { + this.nameCounts[name] = 0; + } + this.nameCounts[name] += 1; + return '_' + name + this.nameCounts[name]; +}; function Instrumentor (options) { verifyOptionPrerequisites(options); @@ -19,10 +47,18 @@ Instrumentor.prototype.instrument = function (ast) { verifyAstPrerequisites(ast, this.options); var that = this; var assertionVisitor; + var storage = {}; var skipping = false; var result = (this.options.destructive) ? ast : cloneAst(ast); + var scopeManager = escope.analyze(result); + var currentScope = scopeManager.acquire(result); + var globalScope = currentScope; + var transformation = new Transformation(); var visitor = { enter: function (currentNode, parentNode) { + if (/Function/.test(currentNode.type)) { + currentScope = scopeManager.acquire(currentNode); + } var controller = this; var path = controller.path(); var currentKey = path ? path[path.length - 1] : null; @@ -38,7 +74,12 @@ Instrumentor.prototype.instrument = function (ast) { var matcher = find(that.matchers, function (matcher) { return matcher.test(currentNode); }); if (matcher) { // entering target assertion - assertionVisitor = new AssertionVisitor(matcher, that.options); + assertionVisitor = new AssertionVisitor(matcher, extend({ + storage: storage, + transformation: transformation, + globalScope: globalScope, + currentScope: currentScope + }, that.options)); assertionVisitor.enter(controller); return undefined; } @@ -46,30 +87,42 @@ Instrumentor.prototype.instrument = function (ast) { return undefined; }, leave: function (currentNode, parentNode) { - var controller = this; - var resultTree = currentNode; - if (!assertionVisitor) { - return undefined; - } - if (skipping) { - skipping = false; - return undefined; - } - if (assertionVisitor.isLeavingAssertion(controller)) { - assertionVisitor.leave(controller); - assertionVisitor = null; - return undefined; - } - if (!assertionVisitor.isCapturingArgument()) { - return undefined; - } - if (assertionVisitor.toBeCaptured(controller)) { - resultTree = assertionVisitor.captureNode(controller); - } - if (assertionVisitor.isLeavingArgument(controller)) { - return assertionVisitor.leaveArgument(resultTree); + try { + var controller = this; + var resultTree = currentNode; + var path = controller.path(); + var espath = path ? path.join('/') : ''; + if (transformation.isTarget(espath)) { + transformation.apply(espath, resultTree); + return resultTree; + } + if (!assertionVisitor) { + return undefined; + } + if (skipping) { + skipping = false; + return undefined; + } + if (assertionVisitor.isLeavingAssertion(controller)) { + assertionVisitor.leave(controller); + assertionVisitor = null; + return undefined; + } + if (!assertionVisitor.isCapturingArgument()) { + return undefined; + } + if (assertionVisitor.toBeCaptured(controller)) { + resultTree = assertionVisitor.captureNode(controller); + } + if (assertionVisitor.isLeavingArgument(controller)) { + return assertionVisitor.leaveArgument(resultTree); + } + return resultTree; + } finally { + if (/Function/.test(currentNode.type)) { + currentScope = currentScope.upper; + } } - return resultTree; } }; if (this.options.visitorKeys) { diff --git a/lib/power-assert-recorder.json b/lib/power-assert-recorder.json new file mode 100644 index 0000000..c6fae0b --- /dev/null +++ b/lib/power-assert-recorder.json @@ -0,0 +1,303 @@ +{ + "type": "CallExpression", + "callee": { + "type": "FunctionExpression", + "id": null, + "params": [], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "FunctionDeclaration", + "id": { + "type": "Identifier", + "name": "PowerAssertRecorder" + }, + "params": [], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression" + }, + "property": { + "type": "Identifier", + "name": "captured" + }, + "computed": false + }, + "right": { + "type": "ArrayExpression", + "elements": [] + } + } + } + ] + }, + "generator": false + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "PowerAssertRecorder" + }, + "property": { + "type": "Identifier", + "name": "prototype" + }, + "computed": false + }, + "property": { + "type": "Identifier", + "name": "_capt" + }, + "computed": false + }, + "right": { + "type": "FunctionExpression", + "id": { + "type": "Identifier", + "name": "_capt" + }, + "params": [ + { + "type": "Identifier", + "name": "value" + }, + { + "type": "Identifier", + "name": "espath" + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression" + }, + "property": { + "type": "Identifier", + "name": "captured" + }, + "computed": false + }, + "property": { + "type": "Identifier", + "name": "push" + }, + "computed": false + }, + "arguments": [ + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "value" + }, + "value": { + "type": "Identifier", + "name": "value" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "espath" + }, + "value": { + "type": "Identifier", + "name": "espath" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + ] + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "value" + } + } + ] + }, + "generator": false + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "PowerAssertRecorder" + }, + "property": { + "type": "Identifier", + "name": "prototype" + }, + "computed": false + }, + "property": { + "type": "Identifier", + "name": "_expr" + }, + "computed": false + }, + "right": { + "type": "FunctionExpression", + "id": { + "type": "Identifier", + "name": "_expr" + }, + "params": [ + { + "type": "Identifier", + "name": "value" + }, + { + "type": "Identifier", + "name": "source" + } + ], + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ReturnStatement", + "argument": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "powerAssertContext" + }, + "value": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "value" + }, + "value": { + "type": "Identifier", + "name": "value" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "events" + }, + "value": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression" + }, + "property": { + "type": "Identifier", + "name": "captured" + }, + "computed": false + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "source" + }, + "value": { + "type": "Identifier", + "name": "source" + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false + } + ] + } + } + ] + }, + "generator": false + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "PowerAssertRecorder" + } + } + ] + }, + "generator": false + }, + "arguments": [] +} \ No newline at end of file diff --git a/lib/rules/supported-node-types.js b/lib/rules/supported-node-types.js index 4887bf7..ae442f8 100644 --- a/lib/rules/supported-node-types.js +++ b/lib/rules/supported-node-types.js @@ -16,6 +16,7 @@ module.exports = [ syntax.ArrayExpression, syntax.ConditionalExpression, syntax.UpdateExpression, + syntax.SequenceExpression, syntax.TemplateLiteral, syntax.TaggedTemplateExpression, syntax.SpreadElement, diff --git a/package.json b/package.json index 7ab6669..2936dfc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "espower", "description": "Power Assert feature instrumentor based on the ECMAScript AST", - "version": "1.2.1", + "version": "1.3.2", "author": { "name": "Takuto Wada", "email": "takuto.wada@gmail.com", @@ -18,10 +18,10 @@ ], "dependencies": { "array-find": "^1.0.0", - "deep-equal": "^1.0.0", "escallmatch": "^1.4.2", "escodegen": "^1.7.0", - "espower-location-detector": "^0.1.1", + "escope": "^3.3.0", + "espower-location-detector": "^0.1.2", "espurify": "^1.3.0", "estraverse": "^4.1.0", "is-url": "^1.2.1", @@ -38,6 +38,7 @@ "blanket": "1.1.9", "browserify": "^13.0.1", "del": "^2.0.2", + "esprima": "^2.7.2", "gulp": "^3.9.0", "gulp-derequire": "^2.1.0", "gulp-dereserve": "^0.2.1", @@ -51,6 +52,7 @@ "licensify": "^3.1.2", "mocha": "^2.5.3", "mocha-lcov-reporter": "^1.2.0", + "package-json-versionify": "^1.0.2", "through2": "^2.0.0", "vinyl-source-stream": "^1.1.0" }, diff --git a/power-assert-recorder.js b/power-assert-recorder.js new file mode 100644 index 0000000..383967e --- /dev/null +++ b/power-assert-recorder.js @@ -0,0 +1,19 @@ +(function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ value: value, espath: espath }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +})(); diff --git a/test/espower_option_test.js b/test/espower_option_test.js index b146e7a..aed071d 100644 --- a/test/espower_option_test.js +++ b/test/espower_option_test.js @@ -28,6 +28,16 @@ function instrument (jsCode, options) { return instrumentedCode; } +function rec(num) { + return 'var _rec' + num + '=new _PowerAssertRecorder1();'; +} +function prelude(num) { + var decl = "var _PowerAssertRecorder1=function(){function PowerAssertRecorder(){this.captured=[];}PowerAssertRecorder.prototype._capt=function _capt(value,espath){this.captured.push({value:value,espath:espath});return value;};PowerAssertRecorder.prototype._expr=function _expr(value,source){return{powerAssertContext:{value:value,events:this.captured},source:source};};return PowerAssertRecorder;}();"; + for (var i = 1; i <= num; i+=1) { + decl += rec(i); + } + return decl; +} describe('espower.defaultOptions()', function () { beforeEach(function () { @@ -121,7 +131,8 @@ describe('instrumentation tests for options', function () { 'refute(value)' ] }); - assert.equal(instrumentedCode, "refute(refute._expr(refute._capt(falsyStr,'arguments/0'),{content:'refute(falsyStr)',line:1}));"); + assert.equal(instrumentedCode, + prelude(1) + "refute(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'refute(falsyStr)',line:1}));"); }); it('matches method call', function () { @@ -130,7 +141,8 @@ describe('instrumentation tests for options', function () { 'refute.equal(actual, expected)' ] }); - assert.equal(instrumentedCode, "refute.equal(refute._expr(refute._capt(foo,'arguments/0'),{content:'refute.equal(foo, bar)',line:1}),refute._expr(refute._capt(bar,'arguments/1'),{content:'refute.equal(foo, bar)',line:1}));"); + assert.equal(instrumentedCode, + prelude(2) + "refute.equal(_rec1._expr(_rec1._capt(foo,'arguments/0'),{content:'refute.equal(foo, bar)',line:1}),_rec2._expr(_rec2._capt(bar,'arguments/1'),{content:'refute.equal(foo, bar)',line:1}));"); }); it('deep callee chain', function () { @@ -139,7 +151,8 @@ describe('instrumentation tests for options', function () { 'browser.assert.element(selection, [message])' ] }); - assert.equal(instrumentedCode, "browser.assert.element(browser.assert._expr(browser.assert._capt(foo,'arguments/0'),{content:'browser.assert.element(foo)',line:1}));"); + assert.equal(instrumentedCode, + prelude(1) + "browser.assert.element(_rec1._expr(_rec1._capt(foo,'arguments/0'),{content:'browser.assert.element(foo)',line:1}));"); }); }); @@ -147,11 +160,13 @@ describe('instrumentation tests for options', function () { describe('path option.', function () { it('path: null', function () { var instrumentedCode = instrument('assert(falsyStr);', {}); - assert.equal(instrumentedCode, "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',line:1}));"); + assert.equal(instrumentedCode, + prelude(1) + "assert(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',line:1}));"); }); it('with path', function () { var instrumentedCode = instrument('assert(falsyStr);', {path: 'path/to/baz_test.js'}); - assert.equal(instrumentedCode, "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'path/to/baz_test.js',line:1}));"); + assert.equal(instrumentedCode, + prelude(1) + "assert(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'path/to/baz_test.js',line:1}));"); }); }); }); @@ -221,7 +236,7 @@ describe('AST prerequisites. Error should be thrown if location is missing.', fu describe('AST prerequisites. Error should be thrown if AST is already instrumented.', function () { it('when going to instrument "assert(falsyStr);" twice', function () { - var alreadyEspoweredCode = "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'/path/to/some_test.js',line:1}));"; + var alreadyEspoweredCode = "assert(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'/path/to/some_test.js',line:1}));"; var ast = acorn.parse(alreadyEspoweredCode, {ecmaVersion: 6, locations: true}); try { espower(ast, {destructive: false, path: '/path/to/baz_test.js'}); @@ -236,7 +251,7 @@ describe('AST prerequisites. Error should be thrown if AST is already instrument }); it('when going to instrument "browser.assert.element(foo);" twice', function () { - var alreadyEspoweredCode = "browser.assert.element(browser.assert._expr(browser.assert._capt(foo,'arguments/0'),{content:'browser.assert.element(foo)',line:1}));"; + var alreadyEspoweredCode = "browser.assert.element(_rec1._expr(_rec1._capt(foo,'arguments/0'),{content:'browser.assert.element(foo)',line:1}));"; var ast = acorn.parse(alreadyEspoweredCode, {ecmaVersion: 6, locations: true}); try { espower(ast, { @@ -274,7 +289,7 @@ describe('location information', function () { describe('lineSeparator', function () { - var lineDetected = "var falsyStr='';assert.ok(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert.ok(falsyStr)',line:3}));"; + var lineDetected = "var _PowerAssertRecorder1=function(){function PowerAssertRecorder(){this.captured=[];}PowerAssertRecorder.prototype._capt=function _capt(value,espath){this.captured.push({value:value,espath:espath});return value;};PowerAssertRecorder.prototype._expr=function _expr(value,source){return{powerAssertContext:{value:value,events:this.captured},source:source};};return PowerAssertRecorder;}();var _rec1=new _PowerAssertRecorder1();var falsyStr='';assert.ok(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert.ok(falsyStr)',line:3}));"; function lineSeparatorTest (name, lineSeparatorInCode, options, expected) { it(name, function () { var sourceLines = [ @@ -336,7 +351,8 @@ describe('incoming SourceMap support', function () { var espoweredCode = escodegen.generate(espoweredAST, {format: {compact: true}}); - assert.equal(espoweredCode, "var str='foo';var anotherStr='bar';assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'" + opts.expectedPath + "',line:4}),assert._expr(assert._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'" + opts.expectedPath + "',line:4}));"); + var expectedOutput = "var _PowerAssertRecorder1=function(){function PowerAssertRecorder(){this.captured=[];}PowerAssertRecorder.prototype._capt=function _capt(value,espath){this.captured.push({value:value,espath:espath});return value;};PowerAssertRecorder.prototype._expr=function _expr(value,source){return{powerAssertContext:{value:value,events:this.captured},source:source};};return PowerAssertRecorder;}();var _rec1=new _PowerAssertRecorder1();var _rec2=new _PowerAssertRecorder1();var str='foo';var anotherStr='bar';assert.equal(_rec1._expr(_rec1._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'" + opts.expectedPath + "',line:4}),_rec2._expr(_rec2._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'" + opts.expectedPath + "',line:4}));"; + assert.equal(espoweredCode, expectedOutput); }); } @@ -436,7 +452,8 @@ describe('sourceRoot option', function () { 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}));"); + assert.equal(instrumentedCode, + prelude(1) + "assert(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'" + config.filepathInGeneratedCode + "',line:1}));"); }); } diff --git a/test/fixture_test.js b/test/fixture_test.js index c5b189e..13924ae 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -3,20 +3,21 @@ var espower = require('..'); var acorn = require('acorn'); require('acorn-es7-plugin')(acorn); +var esprima = require('esprima'); var escodegen = require('escodegen'); var assert = require('assert'); var fs = require('fs'); var path = require('path'); var extend = require('xtend'); -function testTransform (fixtureName, extraOptions) { - it(fixtureName, function () { + +function testWithParser (fixtureName, parse) { + it(parse.name + ' ' + fixtureName, function () { var fixtureFilepath = path.resolve(__dirname, 'fixtures', fixtureName, 'fixture.js'); var expectedFilepath = path.resolve(__dirname, 'fixtures', fixtureName, 'expected.js'); var actualFilepath = path.resolve(__dirname, 'fixtures', fixtureName, 'actual.js'); - var parserOptions = {ecmaVersion: 7, locations: true, plugins: { asyncawait: true }}; - var jsAST = acorn.parse(fs.readFileSync(fixtureFilepath, 'utf8'), parserOptions); + var jsAST = parse(fixtureFilepath); var espoweredAST = espower(jsAST, {path: 'path/to/some_test.js'}); var output = escodegen.generate(espoweredAST); @@ -29,28 +30,46 @@ function testTransform (fixtureName, extraOptions) { }); } -describe('espower', function () { +function testTransform (fixtureName, extraOptions) { + testWithParser(fixtureName, function by_acorn (filepath) { + var parserOptions = {ecmaVersion: 7, locations: true, plugins: { asyncawait: true }}; + return acorn.parse(fs.readFileSync(filepath, 'utf8'), parserOptions); + }); + if (fixtureName !== 'AwaitExpression') { + testWithParser(fixtureName, function by_esprima (filepath) { + var parserOptions = {tolerant: true, loc: true}; + return esprima.parse(fs.readFileSync(filepath, 'utf8'), parserOptions); + }); + } +} + +describe('fixtures', function () { + testTransform('WithoutUseStrict'); + testTransform('WithoutRequireAssert'); + testTransform('WithoutUseStrictNorRequireAssert'); testTransform('Mocha'); testTransform('NonTarget'); testTransform('Literal'); testTransform('Identifier'); testTransform('BinaryExpression'); testTransform('UnaryExpression'); - testTransform('LogicalExpression'); testTransform('MemberExpression'); testTransform('CallExpression'); - testTransform('AssignmentExpression'); + testTransform('NewExpression'); testTransform('ArrayExpression'); - testTransform('UpdateExpression'); - testTransform('ConditionalExpression'); testTransform('ObjectExpression'); - testTransform('NewExpression'); + testTransform('Property'); + testTransform('LogicalExpression'); + testTransform('ConditionalExpression'); + testTransform('AssignmentExpression'); + testTransform('UpdateExpression'); + testTransform('SequenceExpression'); testTransform('FunctionExpression'); - testTransform('TemplateLiteral'); - testTransform('TaggedTemplateExpression'); testTransform('ArrowFunctionExpression'); testTransform('ClassExpression'); + testTransform('TemplateLiteral'); + testTransform('TaggedTemplateExpression'); testTransform('SpreadElement'); - testTransform('Property'); testTransform('YieldExpression'); + testTransform('AwaitExpression'); }); diff --git a/test/fixtures/ArrayExpression/expected.js b/test/fixtures/ArrayExpression/expected.js index 4e7bd48..4ceb404 100644 --- a/test/fixtures/ArrayExpression/expected.js +++ b/test/fixtures/ArrayExpression/expected.js @@ -1,34 +1,60 @@ 'use strict'; -assert(assert._expr(assert._capt([ - assert._capt(foo, 'arguments/0/elements/0'), - assert._capt(bar, 'arguments/0/elements/1') +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt([ + _rec1._capt(foo, 'arguments/0/elements/0'), + _rec1._capt(bar, 'arguments/0/elements/1') ], 'arguments/0'), { content: 'assert([foo,bar])', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(assert._capt(typeof assert._capt([ - assert._capt([ - assert._capt(assert._capt(foo, 'arguments/0/left/argument/elements/0/elements/0/object').bar, 'arguments/0/left/argument/elements/0/elements/0'), - assert._capt(baz(assert._capt(moo, 'arguments/0/left/argument/elements/0/elements/1/arguments/0')), 'arguments/0/left/argument/elements/0/elements/1') +assert(_rec2._expr(_rec2._capt(_rec2._capt(typeof _rec2._capt([ + _rec2._capt([ + _rec2._capt(_rec2._capt(foo, 'arguments/0/left/argument/elements/0/elements/0/object').bar, 'arguments/0/left/argument/elements/0/elements/0'), + _rec2._capt(baz(_rec2._capt(moo, 'arguments/0/left/argument/elements/0/elements/1/arguments/0')), 'arguments/0/left/argument/elements/0/elements/1') ], 'arguments/0/left/argument/elements/0'), - assert._capt(+assert._capt(fourStr, 'arguments/0/left/argument/elements/1/argument'), 'arguments/0/left/argument/elements/1') + _rec2._capt(+_rec2._capt(fourStr, 'arguments/0/left/argument/elements/1/argument'), 'arguments/0/left/argument/elements/1') ], 'arguments/0/left/argument'), 'arguments/0/left') === 'number', 'arguments/0'), { content: 'assert(typeof [[foo.bar,baz(moo)],+fourStr] === \'number\')', filepath: 'path/to/some_test.js', line: 5 })); -assert.notDeepEqual(assert._expr(assert._capt([ - assert._capt(foo, 'arguments/0/elements/0'), - assert._capt(bar, 'arguments/0/elements/1') +assert.notDeepEqual(_rec3._expr(_rec3._capt([ + _rec3._capt(foo, 'arguments/0/elements/0'), + _rec3._capt(bar, 'arguments/0/elements/1') ], 'arguments/0'), { content: 'assert.notDeepEqual([foo,bar], [hoge,fuga,piyo])', filepath: 'path/to/some_test.js', line: 7 -}), assert._expr(assert._capt([ - assert._capt(hoge, 'arguments/1/elements/0'), - assert._capt(fuga, 'arguments/1/elements/1'), - assert._capt(piyo, 'arguments/1/elements/2') +}), _rec4._expr(_rec4._capt([ + _rec4._capt(hoge, 'arguments/1/elements/0'), + _rec4._capt(fuga, 'arguments/1/elements/1'), + _rec4._capt(piyo, 'arguments/1/elements/2') ], 'arguments/1'), { content: 'assert.notDeepEqual([foo,bar], [hoge,fuga,piyo])', filepath: 'path/to/some_test.js', diff --git a/test/fixtures/ArrowFunctionExpression/expected.js b/test/fixtures/ArrowFunctionExpression/expected.js index 821bdef..f7c5085 100644 --- a/test/fixtures/ArrowFunctionExpression/expected.js +++ b/test/fixtures/ArrowFunctionExpression/expected.js @@ -1,11 +1,34 @@ 'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); assert(v => v + 1); assert((v, i) => v + i); assert(v => ({ even: v, odd: v + 1 })); -assert(assert._expr(assert._capt(assert._capt(seven, 'arguments/0/left') === assert._capt(((v, i) => v + i)(assert._capt(four, 'arguments/0/right/arguments/0'), assert._capt(five, 'arguments/0/right/arguments/1')), 'arguments/0/right'), 'arguments/0'), { +assert(_rec1._expr(_rec1._capt(_rec1._capt(seven, 'arguments/0/left') === _rec1._capt(((v, i) => v + i)(_rec1._capt(four, 'arguments/0/right/arguments/0'), _rec1._capt(five, 'arguments/0/right/arguments/1')), 'arguments/0/right'), 'arguments/0'), { content: 'assert(seven === ((v, i) => v + i)(four, five))', filepath: 'path/to/some_test.js', line: 9 diff --git a/test/fixtures/AssignmentExpression/expected.js b/test/fixtures/AssignmentExpression/expected.js index c5836c7..05b770e 100644 --- a/test/fixtures/AssignmentExpression/expected.js +++ b/test/fixtures/AssignmentExpression/expected.js @@ -1,34 +1,63 @@ 'use strict'; -assert(assert._expr(assert._capt(counter += 1, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +var _rec7 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(counter += 1, 'arguments/0'), { content: 'assert(counter += 1)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(dog.age += 1, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(dog.age += 1, 'arguments/0'), { content: 'assert(dog.age += 1)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(dog.age += 1, 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(dog.age += 1, 'arguments/0'), { content: 'assert(dog.age += 1)', filepath: 'path/to/some_test.js', line: 7 })); -assert.strictEqual(assert._expr(assert._capt(dog.age += 1, 'arguments/0'), { +assert.strictEqual(_rec4._expr(_rec4._capt(dog.age += 1, 'arguments/0'), { content: 'assert.strictEqual(dog.age += 1, three)', filepath: 'path/to/some_test.js', line: 9 -}), assert._expr(assert._capt(three, 'arguments/1'), { +}), _rec5._expr(_rec5._capt(three, 'arguments/1'), { content: 'assert.strictEqual(dog.age += 1, three)', filepath: 'path/to/some_test.js', line: 9 })); -assert(assert._expr(assert._capt([x] = assert._capt([3], 'arguments/0/right'), 'arguments/0'), { +assert(_rec6._expr(_rec6._capt([x] = _rec6._capt([3], 'arguments/0/right'), 'arguments/0'), { content: 'assert([x] = [3])', filepath: 'path/to/some_test.js', line: 11 })); -assert(assert._expr(assert._capt([x] = assert._capt([assert._capt(foo, 'arguments/0/right/elements/0')], 'arguments/0/right'), 'arguments/0'), { +assert(_rec7._expr(_rec7._capt([x] = _rec7._capt([_rec7._capt(foo, 'arguments/0/right/elements/0')], 'arguments/0/right'), 'arguments/0'), { content: 'assert([x] = [foo])', filepath: 'path/to/some_test.js', line: 13 diff --git a/test/fixtures/AwaitExpression/expected.js b/test/fixtures/AwaitExpression/expected.js new file mode 100644 index 0000000..7523641 --- /dev/null +++ b/test/fixtures/AwaitExpression/expected.js @@ -0,0 +1,32 @@ +'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +async function myAsync(a) { + var _rec1 = new _PowerAssertRecorder1(); + assert(_rec1._expr(_rec1._capt(_rec1._capt(await a, 'arguments/0/left') === 3, 'arguments/0'), { + content: 'assert((await a) === 3)', + filepath: 'path/to/some_test.js', + line: 4, + async: true + })); +} diff --git a/test/fixtures/AwaitExpression/fixture.js b/test/fixtures/AwaitExpression/fixture.js new file mode 100644 index 0000000..2f96747 --- /dev/null +++ b/test/fixtures/AwaitExpression/fixture.js @@ -0,0 +1,9 @@ +'use strict'; + +async function myAsync(a){ + assert((await (a)) === 3); +} + +// function notAsync(a){ +// assert((await (a)) === 3); +// } diff --git a/test/fixtures/BinaryExpression/expected.js b/test/fixtures/BinaryExpression/expected.js index eac0d50..9441489 100644 --- a/test/fixtures/BinaryExpression/expected.js +++ b/test/fixtures/BinaryExpression/expected.js @@ -1,41 +1,77 @@ 'use strict'; -assert(assert._expr(assert._capt(4 !== 4, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +var _rec7 = new _PowerAssertRecorder1(); +var _rec8 = new _PowerAssertRecorder1(); +var _rec9 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(4 !== 4, 'arguments/0'), { content: 'assert(4 !== 4)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(assert._capt(fuga, 'arguments/0/left') !== 4, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(_rec2._capt(fuga, 'arguments/0/left') !== 4, 'arguments/0'), { content: 'assert(fuga !== 4)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(assert._capt(fuga, 'arguments/0/left') === assert._capt(piyo, 'arguments/0/right'), 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(_rec3._capt(fuga, 'arguments/0/left') === _rec3._capt(piyo, 'arguments/0/right'), 'arguments/0'), { content: 'assert(fuga === piyo)', filepath: 'path/to/some_test.js', line: 7 })); -assert(assert._expr(assert._capt(assert._capt(fuga, 'arguments/0/left') === assert._capt(piyo, 'arguments/0/right'), 'arguments/0'), { +assert(_rec4._expr(_rec4._capt(_rec4._capt(fuga, 'arguments/0/left') === _rec4._capt(piyo, 'arguments/0/right'), 'arguments/0'), { content: 'assert(fuga === piyo)', filepath: 'path/to/some_test.js', line: 9 })); -assert(assert._expr(assert._capt(assert._capt(fuga, 'arguments/0/left') === assert._capt(piyo, 'arguments/0/right'), 'arguments/0'), { +assert(_rec5._expr(_rec5._capt(_rec5._capt(fuga, 'arguments/0/left') === _rec5._capt(piyo, 'arguments/0/right'), 'arguments/0'), { content: 'assert(fuga === piyo)', filepath: 'path/to/some_test.js', line: 13 })); -assert(assert._expr(assert._capt(assert._capt(fuga, 'arguments/0/left') !== assert._capt(piyo, 'arguments/0/right'), 'arguments/0'), { +assert(_rec6._expr(_rec6._capt(_rec6._capt(fuga, 'arguments/0/left') !== _rec6._capt(piyo, 'arguments/0/right'), 'arguments/0'), { content: 'assert(fuga !== piyo)', filepath: 'path/to/some_test.js', line: 15 })); -assert.ok(assert._expr(assert._capt(assert._capt(hoge, 'arguments/0/left') === assert._capt(fuga, 'arguments/0/right'), 'arguments/0'), { +assert.ok(_rec7._expr(_rec7._capt(_rec7._capt(hoge, 'arguments/0/left') === _rec7._capt(fuga, 'arguments/0/right'), 'arguments/0'), { content: 'assert.ok(hoge === fuga, \'comment\')', filepath: 'path/to/some_test.js', line: 17 }), 'comment'); -assert(assert._expr(assert._capt(assert._capt(assert._capt(ary1, 'arguments/0/left/object').length, 'arguments/0/left') === assert._capt(assert._capt(ary2, 'arguments/0/right/object').length, 'arguments/0/right'), 'arguments/0'), { +assert(_rec8._expr(_rec8._capt(_rec8._capt(_rec8._capt(ary1, 'arguments/0/left/object').length, 'arguments/0/left') === _rec8._capt(_rec8._capt(ary2, 'arguments/0/right/object').length, 'arguments/0/right'), 'arguments/0'), { content: 'assert(ary1.length === ary2.length)', filepath: 'path/to/some_test.js', line: 19 })); +assert(_rec9._expr(_rec9._capt(_rec9._capt(foo, 'arguments/0/left') instanceof _rec9._capt(Foo, 'arguments/0/right'), 'arguments/0'), { + content: 'assert(foo instanceof Foo)', + filepath: 'path/to/some_test.js', + line: 21 +})); diff --git a/test/fixtures/BinaryExpression/fixture.js b/test/fixtures/BinaryExpression/fixture.js index 824c268..a884b0a 100644 --- a/test/fixtures/BinaryExpression/fixture.js +++ b/test/fixtures/BinaryExpression/fixture.js @@ -17,3 +17,5 @@ assert(fuga !== piyo); assert.ok(hoge === fuga, 'comment'); assert(ary1.length === ary2.length); + +assert(foo instanceof Foo); diff --git a/test/fixtures/CallExpression/expected.js b/test/fixtures/CallExpression/expected.js index fe322fe..8b856a1 100644 --- a/test/fixtures/CallExpression/expected.js +++ b/test/fixtures/CallExpression/expected.js @@ -1,59 +1,93 @@ 'use strict'; -assert(assert._expr(assert._capt(func(), 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +var _rec7 = new _PowerAssertRecorder1(); +var _rec8 = new _PowerAssertRecorder1(); +var _rec9 = new _PowerAssertRecorder1(); +var _rec10 = new _PowerAssertRecorder1(); +var _rec11 = new _PowerAssertRecorder1(); +var _rec12 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(func(), 'arguments/0'), { content: 'assert(func())', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(assert._capt(obj, 'arguments/0/callee/object').age(), 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(_rec2._capt(obj, 'arguments/0/callee/object').age(), 'arguments/0'), { content: 'assert(obj.age())', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(isFalsy(assert._capt(positiveInt, 'arguments/0/arguments/0')), 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(isFalsy(_rec3._capt(positiveInt, 'arguments/0/arguments/0')), 'arguments/0'), { content: 'assert(isFalsy(positiveInt))', filepath: 'path/to/some_test.js', line: 7 })); -assert(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/callee/object')[assert._capt(propName, 'arguments/0/callee/property')](), 'arguments/0'), { +assert(_rec4._expr(_rec4._capt(_rec4._capt(foo, 'arguments/0/callee/object')[_rec4._capt(propName, 'arguments/0/callee/property')](), 'arguments/0'), { content: 'assert(foo[propName]())', filepath: 'path/to/some_test.js', line: 9 })); -assert(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/callee/object')[assert._capt(assert._capt(hoge, 'arguments/0/callee/property/object')[assert._capt(assert._capt(fuga, 'arguments/0/callee/property/property/object')[assert._capt(piyo, 'arguments/0/callee/property/property/property')], 'arguments/0/callee/property/property')], 'arguments/0/callee/property')](), 'arguments/0'), { +assert(_rec5._expr(_rec5._capt(_rec5._capt(foo, 'arguments/0/callee/object')[_rec5._capt(_rec5._capt(hoge, 'arguments/0/callee/property/object')[_rec5._capt(_rec5._capt(fuga, 'arguments/0/callee/property/property/object')[_rec5._capt(piyo, 'arguments/0/callee/property/property/property')], 'arguments/0/callee/property/property')], 'arguments/0/callee/property')](), 'arguments/0'), { content: 'assert(foo[hoge[fuga[piyo]]]())', filepath: 'path/to/some_test.js', line: 11 })); -assert(assert._expr(assert._capt(assert._capt(sum(assert._capt(one, 'arguments/0/left/arguments/0'), assert._capt(two, 'arguments/0/left/arguments/1'), assert._capt(three, 'arguments/0/left/arguments/2')), 'arguments/0/left') === assert._capt(seven, 'arguments/0/right'), 'arguments/0'), { +assert(_rec6._expr(_rec6._capt(_rec6._capt(sum(_rec6._capt(one, 'arguments/0/left/arguments/0'), _rec6._capt(two, 'arguments/0/left/arguments/1'), _rec6._capt(three, 'arguments/0/left/arguments/2')), 'arguments/0/left') === _rec6._capt(seven, 'arguments/0/right'), 'arguments/0'), { content: 'assert(sum(one, two, three) === seven)', filepath: 'path/to/some_test.js', line: 13 })); -assert(assert._expr(assert._capt(assert._capt(sum(assert._capt(sum(assert._capt(one, 'arguments/0/left/arguments/0/arguments/0'), assert._capt(two, 'arguments/0/left/arguments/0/arguments/1')), 'arguments/0/left/arguments/0'), assert._capt(three, 'arguments/0/left/arguments/1')), 'arguments/0/left') === assert._capt(sum(assert._capt(sum(assert._capt(two, 'arguments/0/right/arguments/0/arguments/0'), assert._capt(three, 'arguments/0/right/arguments/0/arguments/1')), 'arguments/0/right/arguments/0'), assert._capt(seven, 'arguments/0/right/arguments/1')), 'arguments/0/right'), 'arguments/0'), { +assert(_rec7._expr(_rec7._capt(_rec7._capt(sum(_rec7._capt(sum(_rec7._capt(one, 'arguments/0/left/arguments/0/arguments/0'), _rec7._capt(two, 'arguments/0/left/arguments/0/arguments/1')), 'arguments/0/left/arguments/0'), _rec7._capt(three, 'arguments/0/left/arguments/1')), 'arguments/0/left') === _rec7._capt(sum(_rec7._capt(sum(_rec7._capt(two, 'arguments/0/right/arguments/0/arguments/0'), _rec7._capt(three, 'arguments/0/right/arguments/0/arguments/1')), 'arguments/0/right/arguments/0'), _rec7._capt(seven, 'arguments/0/right/arguments/1')), 'arguments/0/right'), 'arguments/0'), { content: 'assert(sum(sum(one, two), three) === sum(sum(two, three), seven))', filepath: 'path/to/some_test.js', line: 15 })); -assert(assert._expr(assert._capt(assert._capt(assert._capt(assert._capt(math, 'arguments/0/left/callee/object/object').calc, 'arguments/0/left/callee/object').sum(assert._capt(one, 'arguments/0/left/arguments/0'), assert._capt(two, 'arguments/0/left/arguments/1'), assert._capt(three, 'arguments/0/left/arguments/2')), 'arguments/0/left') === assert._capt(seven, 'arguments/0/right'), 'arguments/0'), { +assert(_rec8._expr(_rec8._capt(_rec8._capt(_rec8._capt(_rec8._capt(math, 'arguments/0/left/callee/object/object').calc, 'arguments/0/left/callee/object').sum(_rec8._capt(one, 'arguments/0/left/arguments/0'), _rec8._capt(two, 'arguments/0/left/arguments/1'), _rec8._capt(three, 'arguments/0/left/arguments/2')), 'arguments/0/left') === _rec8._capt(seven, 'arguments/0/right'), 'arguments/0'), { content: 'assert(math.calc.sum(one, two, three) === seven)', filepath: 'path/to/some_test.js', line: 17 })); -assert(assert._expr(assert._capt(assert._capt(assert._capt(three, 'arguments/0/left/left') * assert._capt(assert._capt(seven, 'arguments/0/left/right/left') * assert._capt(ten, 'arguments/0/left/right/right'), 'arguments/0/left/right'), 'arguments/0/left') === assert._capt(three, 'arguments/0/right'), 'arguments/0'), { +assert(_rec9._expr(_rec9._capt(_rec9._capt(_rec9._capt(three, 'arguments/0/left/left') * _rec9._capt(_rec9._capt(seven, 'arguments/0/left/right/left') * _rec9._capt(ten, 'arguments/0/left/right/right'), 'arguments/0/left/right'), 'arguments/0/left') === _rec9._capt(three, 'arguments/0/right'), 'arguments/0'), { content: 'assert(three * (seven * ten) === three)', filepath: 'path/to/some_test.js', line: 19 })); -assert(assert._expr(assert._capt(!assert._capt(concat(assert._capt(fuga, 'arguments/0/argument/arguments/0'), assert._capt(piyo, 'arguments/0/argument/arguments/1')), 'arguments/0/argument'), 'arguments/0'), { +assert(_rec10._expr(_rec10._capt(!_rec10._capt(concat(_rec10._capt(fuga, 'arguments/0/argument/arguments/0'), _rec10._capt(piyo, 'arguments/0/argument/arguments/1')), 'arguments/0/argument'), 'arguments/0'), { content: 'assert(!concat(fuga, piyo))', filepath: 'path/to/some_test.js', line: 21 })); -assert.strictEqual(assert._expr(assert._capt(assert._capt(three, 'arguments/0/left') * assert._capt(assert._capt(seven, 'arguments/0/right/left') * assert._capt(ten, 'arguments/0/right/right'), 'arguments/0/right'), 'arguments/0'), { +assert.strictEqual(_rec11._expr(_rec11._capt(_rec11._capt(three, 'arguments/0/left') * _rec11._capt(_rec11._capt(seven, 'arguments/0/right/left') * _rec11._capt(ten, 'arguments/0/right/right'), 'arguments/0/right'), 'arguments/0'), { content: 'assert.strictEqual(three * (seven * ten), math.calc.sum(one, two, three))', filepath: 'path/to/some_test.js', line: 23 -}), assert._expr(assert._capt(assert._capt(assert._capt(math, 'arguments/1/callee/object/object').calc, 'arguments/1/callee/object').sum(assert._capt(one, 'arguments/1/arguments/0'), assert._capt(two, 'arguments/1/arguments/1'), assert._capt(three, 'arguments/1/arguments/2')), 'arguments/1'), { +}), _rec12._expr(_rec12._capt(_rec12._capt(_rec12._capt(math, 'arguments/1/callee/object/object').calc, 'arguments/1/callee/object').sum(_rec12._capt(one, 'arguments/1/arguments/0'), _rec12._capt(two, 'arguments/1/arguments/1'), _rec12._capt(three, 'arguments/1/arguments/2')), 'arguments/1'), { content: 'assert.strictEqual(three * (seven * ten), math.calc.sum(one, two, three))', filepath: 'path/to/some_test.js', line: 23 diff --git a/test/fixtures/ConditionalExpression/expected.js b/test/fixtures/ConditionalExpression/expected.js index 5b1f81d..e43e46e 100644 --- a/test/fixtures/ConditionalExpression/expected.js +++ b/test/fixtures/ConditionalExpression/expected.js @@ -1,24 +1,51 @@ 'use strict'; -assert(assert._expr(assert._capt(foo, 'arguments/0/test') ? assert._capt(bar, 'arguments/0/consequent') : assert._capt(baz, 'arguments/0/alternate'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(foo, 'arguments/0/test') ? _rec1._capt(bar, 'arguments/0/consequent') : _rec1._capt(baz, 'arguments/0/alternate'), { content: 'assert(foo ? bar : baz)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(falsy, 'arguments/0/test') ? assert._capt(truthy, 'arguments/0/consequent') : assert._capt(truthy, 'arguments/0/alternate/test') ? assert._capt(anotherFalsy, 'arguments/0/alternate/consequent') : assert._capt(truthy, 'arguments/0/alternate/alternate'), { +assert(_rec2._expr(_rec2._capt(falsy, 'arguments/0/test') ? _rec2._capt(truthy, 'arguments/0/consequent') : _rec2._capt(truthy, 'arguments/0/alternate/test') ? _rec2._capt(anotherFalsy, 'arguments/0/alternate/consequent') : _rec2._capt(truthy, 'arguments/0/alternate/alternate'), { content: 'assert(falsy ? truthy : truthy ? anotherFalsy : truthy)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(foo(), 'arguments/0/test') ? assert._capt(assert._capt(bar, 'arguments/0/consequent/object').baz, 'arguments/0/consequent') : assert._capt(typeof goo, 'arguments/0/alternate'), { +assert(_rec3._expr(_rec3._capt(foo(), 'arguments/0/test') ? _rec3._capt(_rec3._capt(bar, 'arguments/0/consequent/object').baz, 'arguments/0/consequent') : _rec3._capt(typeof goo, 'arguments/0/alternate'), { content: 'assert(foo() ? bar.baz : typeof goo)', filepath: 'path/to/some_test.js', line: 7 })); -assert.equal(assert._expr(assert._capt(foo, 'arguments/0/test') ? assert._capt(bar, 'arguments/0/consequent') : assert._capt(baz, 'arguments/0/alternate'), { +assert.equal(_rec4._expr(_rec4._capt(foo, 'arguments/0/test') ? _rec4._capt(bar, 'arguments/0/consequent') : _rec4._capt(baz, 'arguments/0/alternate'), { content: 'assert.equal(foo ? bar : baz, falsy ? truthy : truthy ? anotherFalsy : truthy)', filepath: 'path/to/some_test.js', line: 9 -}), assert._expr(assert._capt(falsy, 'arguments/1/test') ? assert._capt(truthy, 'arguments/1/consequent') : assert._capt(truthy, 'arguments/1/alternate/test') ? assert._capt(anotherFalsy, 'arguments/1/alternate/consequent') : assert._capt(truthy, 'arguments/1/alternate/alternate'), { +}), _rec5._expr(_rec5._capt(falsy, 'arguments/1/test') ? _rec5._capt(truthy, 'arguments/1/consequent') : _rec5._capt(truthy, 'arguments/1/alternate/test') ? _rec5._capt(anotherFalsy, 'arguments/1/alternate/consequent') : _rec5._capt(truthy, 'arguments/1/alternate/alternate'), { content: 'assert.equal(foo ? bar : baz, falsy ? truthy : truthy ? anotherFalsy : truthy)', filepath: 'path/to/some_test.js', line: 9 diff --git a/test/fixtures/FunctionExpression/expected.js b/test/fixtures/FunctionExpression/expected.js index 0b3e74e..cadf7a2 100644 --- a/test/fixtures/FunctionExpression/expected.js +++ b/test/fixtures/FunctionExpression/expected.js @@ -1,10 +1,33 @@ 'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); assert(function (a, b) { return a + b; }); -assert(assert._expr(assert._capt(assert._capt(baz, 'arguments/0/left') === assert._capt(function (a, b) { +assert(_rec1._expr(_rec1._capt(_rec1._capt(baz, 'arguments/0/left') === _rec1._capt(function (a, b) { return a + b; -}(assert._capt(foo, 'arguments/0/right/arguments/0'), assert._capt(bar, 'arguments/0/right/arguments/1')), 'arguments/0/right'), 'arguments/0'), { +}(_rec1._capt(foo, 'arguments/0/right/arguments/0'), _rec1._capt(bar, 'arguments/0/right/arguments/1')), 'arguments/0/right'), 'arguments/0'), { content: 'assert(baz === function (a, b) {return a + b;}(foo, bar))', filepath: 'path/to/some_test.js', line: 5 diff --git a/test/fixtures/Identifier/expected.js b/test/fixtures/Identifier/expected.js index 98107bb..00c2ef4 100644 --- a/test/fixtures/Identifier/expected.js +++ b/test/fixtures/Identifier/expected.js @@ -1,55 +1,89 @@ 'use strict'; -assert(assert._expr(assert._capt(falsyStr, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +var _rec7 = new _PowerAssertRecorder1(); +var _rec8 = new _PowerAssertRecorder1(); +var _rec9 = new _PowerAssertRecorder1(); +var _rec10 = new _PowerAssertRecorder1(); +var _rec11 = new _PowerAssertRecorder1(); +var _rec12 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(falsyStr, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr, messageStr)', filepath: 'path/to/some_test.js', line: 5 }), messageStr); -assert.equal(assert._expr(assert._capt(str, 'arguments/0'), { +assert.equal(_rec3._expr(_rec3._capt(str, 'arguments/0'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 7 -}), assert._expr(assert._capt(anotherStr, 'arguments/1'), { +}), _rec4._expr(_rec4._capt(anotherStr, 'arguments/1'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 7 })); -assert.equal(assert._expr(assert._capt(str, 'arguments/0'), { +assert.equal(_rec5._expr(_rec5._capt(str, 'arguments/0'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 9 -}), assert._expr(assert._capt(anotherStr, 'arguments/1'), { +}), _rec6._expr(_rec6._capt(anotherStr, 'arguments/1'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 9 })); -assert.equal(assert._expr(assert._capt(str, 'arguments/0'), { +assert.equal(_rec7._expr(_rec7._capt(str, 'arguments/0'), { content: 'assert.equal(str, anotherStr, messageStr)', filepath: 'path/to/some_test.js', line: 14 -}), assert._expr(assert._capt(anotherStr, 'arguments/1'), { +}), _rec8._expr(_rec8._capt(anotherStr, 'arguments/1'), { content: 'assert.equal(str, anotherStr, messageStr)', filepath: 'path/to/some_test.js', line: 14 }), messageStr); -assert.equal(assert._expr(assert._capt(str, 'arguments/0'), { +assert.equal(_rec9._expr(_rec9._capt(str, 'arguments/0'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 16 -}), assert._expr(assert._capt(anotherStr, 'arguments/1'), { +}), _rec10._expr(_rec10._capt(anotherStr, 'arguments/1'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 16 })); -assert.equal(assert._expr(assert._capt(str, 'arguments/0'), { +assert.equal(_rec11._expr(_rec11._capt(str, 'arguments/0'), { content: 'assert.equal(str, yetAnotherStr)', filepath: 'path/to/some_test.js', line: 21 -}), assert._expr(assert._capt(yetAnotherStr, 'arguments/1'), { +}), _rec12._expr(_rec12._capt(yetAnotherStr, 'arguments/1'), { content: 'assert.equal(str, yetAnotherStr)', filepath: 'path/to/some_test.js', line: 21 diff --git a/test/fixtures/Literal/expected.js b/test/fixtures/Literal/expected.js index ea02332..f7749f7 100644 --- a/test/fixtures/Literal/expected.js +++ b/test/fixtures/Literal/expected.js @@ -1,25 +1,51 @@ 'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); assert(false); assert(0); assert.equal(1, 0); assert(false, 'message'); assert(false, messageStr); -assert.equal(assert._expr(assert._capt(foo, 'arguments/0'), { +assert.equal(_rec1._expr(_rec1._capt(foo, 'arguments/0'), { content: 'assert.equal(foo, \'bar\', \'msg\')', filepath: 'path/to/some_test.js', line: 13 }), 'bar', 'msg'); -assert(assert._expr(assert._capt(/^not/.exec(assert._capt(str, 'arguments/0/arguments/0')), 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(/^not/.exec(_rec2._capt(str, 'arguments/0/arguments/0')), 'arguments/0'), { content: 'assert(/^not/.exec(str))', filepath: 'path/to/some_test.js', line: 15 })); -assert(assert._expr(assert._capt(assert._capt(fuga, 'arguments/0/left') !== 'ふが', 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(_rec3._capt(fuga, 'arguments/0/left') !== 'ふが', 'arguments/0'), { content: 'assert(fuga !== \'ふが\')', filepath: 'path/to/some_test.js', line: 17 })); -assert(assert._expr(assert._capt('ほげ' !== 'ふが', 'arguments/0'), { +assert(_rec4._expr(_rec4._capt('ほげ' !== 'ふが', 'arguments/0'), { content: 'assert(\'ほげ\' !== \'ふが\')', filepath: 'path/to/some_test.js', line: 19 diff --git a/test/fixtures/LogicalExpression/expected.js b/test/fixtures/LogicalExpression/expected.js index 5b31e0d..c008d94 100644 --- a/test/fixtures/LogicalExpression/expected.js +++ b/test/fixtures/LogicalExpression/expected.js @@ -1,29 +1,57 @@ 'use strict'; -assert(assert._expr(assert._capt(assert._capt(5 < assert._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && assert._capt(assert._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(_rec1._capt(5 < _rec1._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && _rec1._capt(_rec1._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { content: 'assert(5 < actual && actual < 13)', filepath: 'path/to/some_test.js', line: 3 })); -assert.ok(assert._expr(assert._capt(assert._capt(assert._capt(actual, 'arguments/0/left/left') < 5, 'arguments/0/left') || assert._capt(13 < assert._capt(actual, 'arguments/0/right/right'), 'arguments/0/right'), 'arguments/0'), { +assert.ok(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(actual, 'arguments/0/left/left') < 5, 'arguments/0/left') || _rec2._capt(13 < _rec2._capt(actual, 'arguments/0/right/right'), 'arguments/0/right'), 'arguments/0'), { content: 'assert.ok(actual < 5 || 13 < actual)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(assert._capt(2 > assert._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && assert._capt(assert._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(_rec3._capt(2 > _rec3._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && _rec3._capt(_rec3._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { content: 'assert(2 > actual && actual < 13)', filepath: 'path/to/some_test.js', line: 7 })); -assert(assert._expr(assert._capt(assert._capt(2 > assert._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && assert._capt(assert._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { +assert(_rec4._expr(_rec4._capt(_rec4._capt(2 > _rec4._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && _rec4._capt(_rec4._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { content: 'assert(2 > actual && actual < 13)', filepath: 'path/to/some_test.js', line: 9 })); -assert.equal(assert._expr(assert._capt(assert._capt(5 < assert._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && assert._capt(assert._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { +assert.equal(_rec5._expr(_rec5._capt(_rec5._capt(5 < _rec5._capt(actual, 'arguments/0/left/right'), 'arguments/0/left') && _rec5._capt(_rec5._capt(actual, 'arguments/0/right/left') < 13, 'arguments/0/right'), 'arguments/0'), { content: 'assert.equal(5 < actual && actual < 13, falsy)', filepath: 'path/to/some_test.js', line: 11 -}), assert._expr(assert._capt(falsy, 'arguments/1'), { +}), _rec6._expr(_rec6._capt(falsy, 'arguments/1'), { content: 'assert.equal(5 < actual && actual < 13, falsy)', filepath: 'path/to/some_test.js', line: 11 diff --git a/test/fixtures/MemberExpression/expected.js b/test/fixtures/MemberExpression/expected.js index e30b1bc..ba5d2d7 100644 --- a/test/fixtures/MemberExpression/expected.js +++ b/test/fixtures/MemberExpression/expected.js @@ -1,58 +1,92 @@ 'use strict'; -assert(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/object').bar, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +var _rec7 = new _PowerAssertRecorder1(); +var _rec8 = new _PowerAssertRecorder1(); +var _rec9 = new _PowerAssertRecorder1(); +var _rec10 = new _PowerAssertRecorder1(); +var _rec11 = new _PowerAssertRecorder1(); +var _rec12 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(_rec1._capt(foo, 'arguments/0/object').bar, 'arguments/0'), { content: 'assert(foo.bar)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(assert._capt(assert._capt(foo, 'arguments/0/object/object').bar, 'arguments/0/object').baz, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(foo, 'arguments/0/object/object').bar, 'arguments/0/object').baz, 'arguments/0'), { content: 'assert(foo.bar.baz)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/object')['bar'], 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(_rec3._capt(foo, 'arguments/0/object')['bar'], 'arguments/0'), { content: 'assert(foo[\'bar\'])', filepath: 'path/to/some_test.js', line: 7 })); -assert(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/object')[assert._capt(propName, 'arguments/0/property')], 'arguments/0'), { +assert(_rec4._expr(_rec4._capt(_rec4._capt(foo, 'arguments/0/object')[_rec4._capt(propName, 'arguments/0/property')], 'arguments/0'), { content: 'assert(foo[propName])', filepath: 'path/to/some_test.js', line: 9 })); -assert(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/object')[assert._capt(propName, 'arguments/0/property')], 'arguments/0'), { +assert(_rec5._expr(_rec5._capt(_rec5._capt(foo, 'arguments/0/object')[_rec5._capt(propName, 'arguments/0/property')], 'arguments/0'), { content: 'assert(foo[propName])', filepath: 'path/to/some_test.js', line: 11 })); -assert(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/object')[assert._capt(func(assert._capt(key, 'arguments/0/property/arguments/0')), 'arguments/0/property')], 'arguments/0'), { +assert(_rec6._expr(_rec6._capt(_rec6._capt(foo, 'arguments/0/object')[_rec6._capt(func(_rec6._capt(key, 'arguments/0/property/arguments/0')), 'arguments/0/property')], 'arguments/0'), { content: 'assert(foo[func(key)])', filepath: 'path/to/some_test.js', line: 13 })); -assert(assert._expr(assert._capt(assert._capt(assert._capt(assert._capt(foo, 'arguments/0/object/object/object')[assert._capt(propName, 'arguments/0/object/object/property')], 'arguments/0/object/object')['key'], 'arguments/0/object')[assert._capt(assert._capt(keys(), 'arguments/0/property/object')['name'], 'arguments/0/property')], 'arguments/0'), { +assert(_rec7._expr(_rec7._capt(_rec7._capt(_rec7._capt(_rec7._capt(foo, 'arguments/0/object/object/object')[_rec7._capt(propName, 'arguments/0/object/object/property')], 'arguments/0/object/object')['key'], 'arguments/0/object')[_rec7._capt(_rec7._capt(keys(), 'arguments/0/property/object')['name'], 'arguments/0/property')], 'arguments/0'), { content: 'assert(foo[propName][\'key\'][keys()[\'name\']])', filepath: 'path/to/some_test.js', line: 15 })); -assert(assert._expr(assert._capt(assert._capt(assert._capt(assert._capt(foo, 'arguments/0/object/object/object')[assert._capt(propName, 'arguments/0/object/object/property')], 'arguments/0/object/object')['key'], 'arguments/0/object')[assert._capt(assert._capt(keys(), 'arguments/0/property/object')['name'], 'arguments/0/property')], 'arguments/0'), { +assert(_rec8._expr(_rec8._capt(_rec8._capt(_rec8._capt(_rec8._capt(foo, 'arguments/0/object/object/object')[_rec8._capt(propName, 'arguments/0/object/object/property')], 'arguments/0/object/object')['key'], 'arguments/0/object')[_rec8._capt(_rec8._capt(keys(), 'arguments/0/property/object')['name'], 'arguments/0/property')], 'arguments/0'), { content: 'assert(foo[propName][\'key\'][keys()[\'name\']])', filepath: 'path/to/some_test.js', line: 17 })); -assert.equal(assert._expr(assert._capt(assert._capt(ary1, 'arguments/0/object').length, 'arguments/0'), { +assert.equal(_rec9._expr(_rec9._capt(_rec9._capt(ary1, 'arguments/0/object').length, 'arguments/0'), { content: 'assert.equal(ary1.length, ary2.length)', filepath: 'path/to/some_test.js', line: 19 -}), assert._expr(assert._capt(assert._capt(ary2, 'arguments/1/object').length, 'arguments/1'), { +}), _rec10._expr(_rec10._capt(_rec10._capt(ary2, 'arguments/1/object').length, 'arguments/1'), { content: 'assert.equal(ary1.length, ary2.length)', filepath: 'path/to/some_test.js', line: 19 })); -assert.deepEqual(assert._expr(assert._capt(assert._capt(foo, 'arguments/0/object').propName, 'arguments/0'), { +assert.deepEqual(_rec11._expr(_rec11._capt(_rec11._capt(foo, 'arguments/0/object').propName, 'arguments/0'), { content: 'assert.deepEqual(foo.propName, foo[key])', filepath: 'path/to/some_test.js', line: 21 -}), assert._expr(assert._capt(assert._capt(foo, 'arguments/1/object')[assert._capt(key, 'arguments/1/property')], 'arguments/1'), { +}), _rec12._expr(_rec12._capt(_rec12._capt(foo, 'arguments/1/object')[_rec12._capt(key, 'arguments/1/property')], 'arguments/1'), { content: 'assert.deepEqual(foo.propName, foo[key])', filepath: 'path/to/some_test.js', line: 21 diff --git a/test/fixtures/Mocha/expected.js b/test/fixtures/Mocha/expected.js index dadaa4c..6cc9200 100644 --- a/test/fixtures/Mocha/expected.js +++ b/test/fixtures/Mocha/expected.js @@ -1,4 +1,26 @@ 'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); var assert = require('power-assert'); describe('Array#indexOf()', function () { beforeEach(function () { @@ -9,16 +31,18 @@ describe('Array#indexOf()', function () { ]; }); it('should return index when the value is present', function () { + var _rec1 = new _PowerAssertRecorder1(); var who = 'ariya', two = 2; - assert(assert._expr(assert._capt(assert._capt(assert._capt(this.ary, 'arguments/0/left/callee/object').indexOf(assert._capt(who, 'arguments/0/left/arguments/0')), 'arguments/0/left') === assert._capt(two, 'arguments/0/right'), 'arguments/0'), { + assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec1._capt(who, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec1._capt(two, 'arguments/0/right'), 'arguments/0'), { content: 'assert(this.ary.indexOf(who) === two)', filepath: 'path/to/some_test.js', line: 11 })); }); it('should return -1 when the value is not present', function () { + var _rec2 = new _PowerAssertRecorder1(); var minusOne = -1, two = 2; - assert.ok(assert._expr(assert._capt(assert._capt(assert._capt(this.ary, 'arguments/0/left/callee/object').indexOf(assert._capt(two, 'arguments/0/left/arguments/0')), 'arguments/0/left') === assert._capt(minusOne, 'arguments/0/right'), 'arguments/0'), { + assert.ok(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec2._capt(two, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec2._capt(minusOne, 'arguments/0/right'), 'arguments/0'), { content: 'assert.ok(this.ary.indexOf(two) === minusOne, \'THIS IS AN ASSERTION MESSAGE\')', filepath: 'path/to/some_test.js', line: 15 diff --git a/test/fixtures/NewExpression/expected.js b/test/fixtures/NewExpression/expected.js index b6ad30f..62fc82b 100644 --- a/test/fixtures/NewExpression/expected.js +++ b/test/fixtures/NewExpression/expected.js @@ -1,24 +1,51 @@ 'use strict'; -assert(assert._expr(assert._capt(new Date(), 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(new Date(), 'arguments/0'), { content: 'assert(new Date())', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(new (assert._capt(assert._capt(foo, 'arguments/0/callee/object/object').bar, 'arguments/0/callee/object')).Baz(), 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(new (_rec2._capt(_rec2._capt(foo, 'arguments/0/callee/object/object').bar, 'arguments/0/callee/object')).Baz(), 'arguments/0'), { content: 'assert(new foo.bar.Baz())', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(!assert._capt(new Array(assert._capt(foo, 'arguments/0/argument/arguments/0'), assert._capt(bar, 'arguments/0/argument/arguments/1'), assert._capt(baz, 'arguments/0/argument/arguments/2')), 'arguments/0/argument'), 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(!_rec3._capt(new Array(_rec3._capt(foo, 'arguments/0/argument/arguments/0'), _rec3._capt(bar, 'arguments/0/argument/arguments/1'), _rec3._capt(baz, 'arguments/0/argument/arguments/2')), 'arguments/0/argument'), 'arguments/0'), { content: 'assert(!new Array(foo, bar, baz))', filepath: 'path/to/some_test.js', line: 7 })); -assert.notEqual(assert._expr(assert._capt(new Date(), 'arguments/0'), { +assert.notEqual(_rec4._expr(_rec4._capt(new Date(), 'arguments/0'), { content: 'assert.notEqual(new Date(), new Date(\'2013-01-12\'))', filepath: 'path/to/some_test.js', line: 9 -}), assert._expr(assert._capt(new Date('2013-01-12'), 'arguments/1'), { +}), _rec5._expr(_rec5._capt(new Date('2013-01-12'), 'arguments/1'), { content: 'assert.notEqual(new Date(), new Date(\'2013-01-12\'))', filepath: 'path/to/some_test.js', line: 9 diff --git a/test/fixtures/ObjectExpression/expected.js b/test/fixtures/ObjectExpression/expected.js index dadc2bd..538ab93 100644 --- a/test/fixtures/ObjectExpression/expected.js +++ b/test/fixtures/ObjectExpression/expected.js @@ -1,33 +1,59 @@ 'use strict'; -assert(assert._expr(assert._capt({ - foo: assert._capt(bar, 'arguments/0/properties/0/value'), - hoge: assert._capt(fuga, 'arguments/0/properties/1/value') +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt({ + foo: _rec1._capt(bar, 'arguments/0/properties/0/value'), + hoge: _rec1._capt(fuga, 'arguments/0/properties/1/value') }, 'arguments/0'), { content: 'assert({foo: bar,hoge: fuga})', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(!assert._capt({ - foo: assert._capt(assert._capt(bar, 'arguments/0/argument/properties/0/value/object').baz, 'arguments/0/argument/properties/0/value'), - name: assert._capt(nameOf(assert._capt({ - firstName: assert._capt(first, 'arguments/0/argument/properties/1/value/arguments/0/properties/0/value'), - lastName: assert._capt(last, 'arguments/0/argument/properties/1/value/arguments/0/properties/1/value') +assert(_rec2._expr(_rec2._capt(!_rec2._capt({ + foo: _rec2._capt(_rec2._capt(bar, 'arguments/0/argument/properties/0/value/object').baz, 'arguments/0/argument/properties/0/value'), + name: _rec2._capt(nameOf(_rec2._capt({ + firstName: _rec2._capt(first, 'arguments/0/argument/properties/1/value/arguments/0/properties/0/value'), + lastName: _rec2._capt(last, 'arguments/0/argument/properties/1/value/arguments/0/properties/1/value') }, 'arguments/0/argument/properties/1/value/arguments/0')), 'arguments/0/argument/properties/1/value') }, 'arguments/0/argument'), 'arguments/0'), { content: 'assert(!{foo: bar.baz,name: nameOf({firstName: first,lastName: last})})', filepath: 'path/to/some_test.js', line: 5 })); -assert.deepEqual(assert._expr(assert._capt({ - foo: assert._capt(bar, 'arguments/0/properties/0/value'), - hoge: assert._capt(fuga, 'arguments/0/properties/1/value') +assert.deepEqual(_rec3._expr(_rec3._capt({ + foo: _rec3._capt(bar, 'arguments/0/properties/0/value'), + hoge: _rec3._capt(fuga, 'arguments/0/properties/1/value') }, 'arguments/0'), { content: 'assert.deepEqual({foo: bar,hoge: fuga}, {hoge: fuga,foo: bar})', filepath: 'path/to/some_test.js', line: 7 -}), assert._expr(assert._capt({ - hoge: assert._capt(fuga, 'arguments/1/properties/0/value'), - foo: assert._capt(bar, 'arguments/1/properties/1/value') +}), _rec4._expr(_rec4._capt({ + hoge: _rec4._capt(fuga, 'arguments/1/properties/0/value'), + foo: _rec4._capt(bar, 'arguments/1/properties/1/value') }, 'arguments/1'), { content: 'assert.deepEqual({foo: bar,hoge: fuga}, {hoge: fuga,foo: bar})', filepath: 'path/to/some_test.js', diff --git a/test/fixtures/Property/expected.js b/test/fixtures/Property/expected.js index 7cbd065..dedeaf3 100644 --- a/test/fixtures/Property/expected.js +++ b/test/fixtures/Property/expected.js @@ -1,27 +1,54 @@ 'use strict'; -assert(assert._expr(assert._capt({ [assert._capt(num, 'arguments/0/properties/0/key')]: assert._capt(foo, 'arguments/0/properties/0/value') }, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt({ [_rec1._capt(num, 'arguments/0/properties/0/key')]: _rec1._capt(foo, 'arguments/0/properties/0/value') }, 'arguments/0'), { content: 'assert({ [num]: foo })', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt({ [assert._capt('prop_' + assert._capt((() => bar())(), 'arguments/0/properties/0/key/right'), 'arguments/0/properties/0/key')]: 42 }, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt({ [_rec2._capt('prop_' + _rec2._capt((() => bar())(), 'arguments/0/properties/0/key/right'), 'arguments/0/properties/0/key')]: 42 }, 'arguments/0'), { content: 'assert({ [\'prop_\' + (() => bar())()]: 42 })', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt({ [assert._capt(`prop_${ assert._capt(generate(assert._capt(seed, 'arguments/0/properties/0/key/expressions/0/arguments/0')), 'arguments/0/properties/0/key/expressions/0') }`, 'arguments/0/properties/0/key')]: assert._capt(foo, 'arguments/0/properties/0/value') }, 'arguments/0'), { +assert(_rec3._expr(_rec3._capt({ [_rec3._capt(`prop_${ _rec3._capt(generate(_rec3._capt(seed, 'arguments/0/properties/0/key/expressions/0/arguments/0')), 'arguments/0/properties/0/key/expressions/0') }`, 'arguments/0/properties/0/key')]: _rec3._capt(foo, 'arguments/0/properties/0/value') }, 'arguments/0'), { content: 'assert({ [`prop_${ generate(seed) }`]: foo })', filepath: 'path/to/some_test.js', line: 7 })); -assert(assert._expr(assert._capt({ foo }, 'arguments/0'), { +assert(_rec4._expr(_rec4._capt({ foo }, 'arguments/0'), { content: 'assert({ foo })', filepath: 'path/to/some_test.js', line: 9 })); -assert(assert._expr(assert._capt({ +assert(_rec5._expr(_rec5._capt({ foo, - bar: assert._capt(baz, 'arguments/0/properties/1/value') + bar: _rec5._capt(baz, 'arguments/0/properties/1/value') }, 'arguments/0'), { content: 'assert({foo,bar: baz})', filepath: 'path/to/some_test.js', diff --git a/test/fixtures/SequenceExpression/expected.js b/test/fixtures/SequenceExpression/expected.js new file mode 100644 index 0000000..19b97f0 --- /dev/null +++ b/test/fixtures/SequenceExpression/expected.js @@ -0,0 +1,55 @@ +'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +assert((2, 1, 0)); +assert(_rec2._expr(_rec2._capt((_rec2._capt(foo, 'arguments/0/left/expressions/0'), _rec2._capt(bar, 'arguments/0/left/expressions/1')) === _rec2._capt(baz, 'arguments/0/right'), 'arguments/0'), { + content: 'assert((foo, bar) === baz)', + filepath: 'path/to/some_test.js', + line: 5 +})); +assert(_rec3._expr(_rec3._capt(toto((_rec3._capt(tata, 'arguments/0/arguments/0/expressions/0'), _rec3._capt(titi, 'arguments/0/arguments/0/expressions/1'))), 'arguments/0'), { + content: 'assert(toto((tata, titi)))', + filepath: 'path/to/some_test.js', + line: 7 +})); +assert(_rec4._expr((_rec4._capt(foo, 'arguments/0/expressions/0'), (_rec4._capt(bar, 'arguments/0/expressions/1/expressions/0'), _rec4._capt(baz, 'arguments/0/expressions/1/expressions/1'))), { + content: 'assert((foo, (bar, baz)))', + filepath: 'path/to/some_test.js', + line: 9 +})); +assert(_rec5._expr((((((_rec5._capt(foo, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/0/expressions/0'), _rec5._capt(bar, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/0/expressions/1')), _rec5._capt(baz, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/1')), _rec5._capt(toto, 'arguments/0/expressions/0/expressions/0/expressions/1')), _rec5._capt(tata, 'arguments/0/expressions/0/expressions/1')), _rec5._capt(titi, 'arguments/0/expressions/1')), { + content: 'assert((((((foo, bar), baz), toto), tata), titi))', + filepath: 'path/to/some_test.js', + line: 11 +})); +assert(_rec6._expr((_rec6._capt(y = _rec6._capt(x, 'arguments/0/expressions/0/right'), 'arguments/0/expressions/0'), _rec6._capt(z, 'arguments/0/expressions/1')), { + content: 'assert((y = x, z))', + filepath: 'path/to/some_test.js', + line: 13 +})); diff --git a/test/fixtures/SequenceExpression/fixture.js b/test/fixtures/SequenceExpression/fixture.js new file mode 100644 index 0000000..389f963 --- /dev/null +++ b/test/fixtures/SequenceExpression/fixture.js @@ -0,0 +1,13 @@ +'use strict'; + +assert((2, 1, 0)); + +assert((foo, bar) === baz); + +assert(toto((tata, titi))); + +assert((foo, (bar, baz))); + +assert((((((foo, bar), baz), toto), tata), titi)); + +assert((y = x, z)); diff --git a/test/fixtures/SpreadElement/expected.js b/test/fixtures/SpreadElement/expected.js index e03887f..df3d8e3 100644 --- a/test/fixtures/SpreadElement/expected.js +++ b/test/fixtures/SpreadElement/expected.js @@ -1,20 +1,45 @@ 'use strict'; -assert(assert._expr(assert._capt(hello(...assert._capt(names, 'arguments/0/arguments/0/argument')), 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(hello(..._rec1._capt(names, 'arguments/0/arguments/0/argument')), 'arguments/0'), { content: 'assert(hello(...names))', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(assert._capt([ - assert._capt(head, 'arguments/0/object/elements/0'), - ...assert._capt(tail, 'arguments/0/object/elements/1/argument') +assert(_rec2._expr(_rec2._capt(_rec2._capt([ + _rec2._capt(head, 'arguments/0/object/elements/0'), + ..._rec2._capt(tail, 'arguments/0/object/elements/1/argument') ], 'arguments/0/object').length, 'arguments/0'), { content: 'assert([head,...tail].length)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(f(assert._capt(head, 'arguments/0/arguments/0'), ...assert._capt(iter(), 'arguments/0/arguments/1/argument'), ...assert._capt([ - assert._capt(foo, 'arguments/0/arguments/2/argument/elements/0'), - assert._capt(bar, 'arguments/0/arguments/2/argument/elements/1') +assert(_rec3._expr(_rec3._capt(f(_rec3._capt(head, 'arguments/0/arguments/0'), ..._rec3._capt(iter(), 'arguments/0/arguments/1/argument'), ..._rec3._capt([ + _rec3._capt(foo, 'arguments/0/arguments/2/argument/elements/0'), + _rec3._capt(bar, 'arguments/0/arguments/2/argument/elements/1') ], 'arguments/0/arguments/2/argument')), 'arguments/0'), { content: 'assert(f(head, ...iter(), ...[foo,bar]))', filepath: 'path/to/some_test.js', diff --git a/test/fixtures/TaggedTemplateExpression/expected.js b/test/fixtures/TaggedTemplateExpression/expected.js index 9da119f..750ed59 100644 --- a/test/fixtures/TaggedTemplateExpression/expected.js +++ b/test/fixtures/TaggedTemplateExpression/expected.js @@ -1,15 +1,40 @@ 'use strict'; -assert(assert._expr(assert._capt(fn`a${ 1 }`, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(fn`a${ 1 }`, 'arguments/0'), { content: 'assert(fn`a${ 1 }`)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(fn`a${ assert._capt(foo, 'arguments/0/quasi/expressions/0') }b${ assert._capt(bar, 'arguments/0/quasi/expressions/1') }c${ assert._capt(baz, 'arguments/0/quasi/expressions/2') }`, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(fn`a${ _rec2._capt(foo, 'arguments/0/quasi/expressions/0') }b${ _rec2._capt(bar, 'arguments/0/quasi/expressions/1') }c${ _rec2._capt(baz, 'arguments/0/quasi/expressions/2') }`, 'arguments/0'), { content: 'assert(fn`a${ foo }b${ bar }c${ baz }`)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(fn`driver ${ assert._capt(assert._capt(bob, 'arguments/0/quasi/expressions/0/object').name, 'arguments/0/quasi/expressions/0') }, navigator ${ assert._capt(assert._capt(alice, 'arguments/0/quasi/expressions/1/callee/object').getName(), 'arguments/0/quasi/expressions/1') }`, 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(fn`driver ${ _rec3._capt(_rec3._capt(bob, 'arguments/0/quasi/expressions/0/object').name, 'arguments/0/quasi/expressions/0') }, navigator ${ _rec3._capt(_rec3._capt(alice, 'arguments/0/quasi/expressions/1/callee/object').getName(), 'arguments/0/quasi/expressions/1') }`, 'arguments/0'), { content: 'assert(fn`driver ${ bob.name }, navigator ${ alice.getName() }`)', filepath: 'path/to/some_test.js', line: 7 diff --git a/test/fixtures/TemplateLiteral/expected.js b/test/fixtures/TemplateLiteral/expected.js index 63e00fe..358d4c1 100644 --- a/test/fixtures/TemplateLiteral/expected.js +++ b/test/fixtures/TemplateLiteral/expected.js @@ -1,15 +1,40 @@ 'use strict'; -assert(assert._expr(assert._capt(`Hello`, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(`Hello`, 'arguments/0'), { content: 'assert(`Hello`)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(`Hello, ${ assert._capt(nickname, 'arguments/0/expressions/0') }`, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(`Hello, ${ _rec2._capt(nickname, 'arguments/0/expressions/0') }`, 'arguments/0'), { content: 'assert(`Hello, ${ nickname }`)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(`Hello, ${ assert._capt(assert._capt(user, 'arguments/0/expressions/0/object').nickname, 'arguments/0/expressions/0') }`, 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(`Hello, ${ _rec3._capt(_rec3._capt(user, 'arguments/0/expressions/0/object').nickname, 'arguments/0/expressions/0') }`, 'arguments/0'), { content: 'assert(`Hello, ${ user.nickname }`)', filepath: 'path/to/some_test.js', line: 7 diff --git a/test/fixtures/UnaryExpression/expected.js b/test/fixtures/UnaryExpression/expected.js index f8deab8..261afa0 100644 --- a/test/fixtures/UnaryExpression/expected.js +++ b/test/fixtures/UnaryExpression/expected.js @@ -1,39 +1,69 @@ 'use strict'; -assert(assert._expr(assert._capt(!assert._capt(truth, 'arguments/0/argument'), 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +var _rec7 = new _PowerAssertRecorder1(); +var _rec8 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(!_rec1._capt(truth, 'arguments/0/argument'), 'arguments/0'), { content: 'assert(!truth)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(!assert._capt(!assert._capt(some, 'arguments/0/argument/argument'), 'arguments/0/argument'), 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(!_rec2._capt(!_rec2._capt(some, 'arguments/0/argument/argument'), 'arguments/0/argument'), 'arguments/0'), { content: 'assert(!!some)', filepath: 'path/to/some_test.js', line: 5 })); -assert(assert._expr(assert._capt(!assert._capt(!assert._capt(assert._capt(foo, 'arguments/0/argument/argument/object').bar, 'arguments/0/argument/argument'), 'arguments/0/argument'), 'arguments/0'), { +assert(_rec3._expr(_rec3._capt(!_rec3._capt(!_rec3._capt(_rec3._capt(foo, 'arguments/0/argument/argument/object').bar, 'arguments/0/argument/argument'), 'arguments/0/argument'), 'arguments/0'), { content: 'assert(!!foo.bar)', filepath: 'path/to/some_test.js', line: 7 })); -assert(assert._expr(assert._capt(delete assert._capt(assert._capt(foo, 'arguments/0/argument/object').bar, 'arguments/0/argument'), 'arguments/0'), { +assert(_rec4._expr(_rec4._capt(delete _rec4._capt(_rec4._capt(foo, 'arguments/0/argument/object').bar, 'arguments/0/argument'), 'arguments/0'), { content: 'assert(delete foo.bar)', filepath: 'path/to/some_test.js', line: 9 })); -assert(assert._expr(assert._capt(assert._capt(typeof foo, 'arguments/0/left') !== 'undefined', 'arguments/0'), { +assert(_rec5._expr(_rec5._capt(_rec5._capt(typeof foo, 'arguments/0/left') !== 'undefined', 'arguments/0'), { content: 'assert(typeof foo !== \'undefined\')', filepath: 'path/to/some_test.js', line: 11 })); -assert(assert._expr(assert._capt(assert._capt(typeof assert._capt(assert._capt(foo, 'arguments/0/left/argument/object').bar, 'arguments/0/left/argument'), 'arguments/0/left') !== 'undefined', 'arguments/0'), { +assert(_rec6._expr(_rec6._capt(_rec6._capt(typeof _rec6._capt(_rec6._capt(foo, 'arguments/0/left/argument/object').bar, 'arguments/0/left/argument'), 'arguments/0/left') !== 'undefined', 'arguments/0'), { content: 'assert(typeof foo.bar !== \'undefined\')', filepath: 'path/to/some_test.js', line: 13 })); -assert.strictEqual(assert._expr(assert._capt(typeof foo, 'arguments/0'), { +assert.strictEqual(_rec7._expr(_rec7._capt(typeof foo, 'arguments/0'), { content: 'assert.strictEqual(typeof foo, typeof bar)', filepath: 'path/to/some_test.js', line: 15 -}), assert._expr(assert._capt(typeof bar, 'arguments/1'), { +}), _rec8._expr(_rec8._capt(typeof bar, 'arguments/1'), { content: 'assert.strictEqual(typeof foo, typeof bar)', filepath: 'path/to/some_test.js', line: 15 diff --git a/test/fixtures/UpdateExpression/expected.js b/test/fixtures/UpdateExpression/expected.js index 3364af7..0e66602 100644 --- a/test/fixtures/UpdateExpression/expected.js +++ b/test/fixtures/UpdateExpression/expected.js @@ -1,19 +1,45 @@ 'use strict'; -assert(assert._expr(assert._capt(++foo, 'arguments/0'), { +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var _rec1 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +assert(_rec1._expr(_rec1._capt(++foo, 'arguments/0'), { content: 'assert(++foo)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(bar--, 'arguments/0'), { +assert(_rec2._expr(_rec2._capt(bar--, 'arguments/0'), { content: 'assert(bar--)', filepath: 'path/to/some_test.js', line: 5 })); -assert.strictEqual(assert._expr(assert._capt(++foo, 'arguments/0'), { +assert.strictEqual(_rec3._expr(_rec3._capt(++foo, 'arguments/0'), { content: 'assert.strictEqual(++foo, bar--)', filepath: 'path/to/some_test.js', line: 7 -}), assert._expr(assert._capt(bar--, 'arguments/1'), { +}), _rec4._expr(_rec4._capt(bar--, 'arguments/1'), { content: 'assert.strictEqual(++foo, bar--)', filepath: 'path/to/some_test.js', line: 7 diff --git a/test/fixtures/WithoutRequireAssert/expected.js b/test/fixtures/WithoutRequireAssert/expected.js new file mode 100644 index 0000000..98b2cb9 --- /dev/null +++ b/test/fixtures/WithoutRequireAssert/expected.js @@ -0,0 +1,50 @@ +'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +describe('Array#indexOf()', function () { + beforeEach(function () { + this.ary = [ + 1, + 2, + 3 + ]; + }); + it('should return index when the value is present', function () { + var _rec1 = new _PowerAssertRecorder1(); + var who = 'ariya', two = 2; + assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec1._capt(who, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec1._capt(two, 'arguments/0/right'), 'arguments/0'), { + content: 'assert(this.ary.indexOf(who) === two)', + filepath: 'path/to/some_test.js', + line: 9 + })); + }); + it('should return -1 when the value is not present', function () { + var _rec2 = new _PowerAssertRecorder1(); + var minusOne = -1, two = 2; + assert.ok(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec2._capt(two, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec2._capt(minusOne, 'arguments/0/right'), 'arguments/0'), { + content: 'assert.ok(this.ary.indexOf(two) === minusOne, \'THIS IS AN ASSERTION MESSAGE\')', + filepath: 'path/to/some_test.js', + line: 13 + }), 'THIS IS AN ASSERTION MESSAGE'); + }); +}); diff --git a/test/fixtures/WithoutRequireAssert/fixture.js b/test/fixtures/WithoutRequireAssert/fixture.js new file mode 100644 index 0000000..bc51fdb --- /dev/null +++ b/test/fixtures/WithoutRequireAssert/fixture.js @@ -0,0 +1,15 @@ +'use strict'; + +describe('Array#indexOf()', function () { + beforeEach(function () { + this.ary = [1,2,3]; + }); + it('should return index when the value is present', function () { + var who = 'ariya', two = 2; + assert(this.ary.indexOf(who) === two); + }); + it('should return -1 when the value is not present', function () { + var minusOne = -1, two = 2; + assert.ok(this.ary.indexOf(two) === minusOne, 'THIS IS AN ASSERTION MESSAGE'); + }); +}); diff --git a/test/fixtures/WithoutUseStrict/expected.js b/test/fixtures/WithoutUseStrict/expected.js new file mode 100644 index 0000000..bded0cc --- /dev/null +++ b/test/fixtures/WithoutUseStrict/expected.js @@ -0,0 +1,50 @@ +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +var assert = require('power-assert'); +describe('Array#indexOf()', function () { + beforeEach(function () { + this.ary = [ + 1, + 2, + 3 + ]; + }); + it('should return index when the value is present', function () { + var _rec1 = new _PowerAssertRecorder1(); + var who = 'ariya', two = 2; + assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec1._capt(who, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec1._capt(two, 'arguments/0/right'), 'arguments/0'), { + content: 'assert(this.ary.indexOf(who) === two)', + filepath: 'path/to/some_test.js', + line: 9 + })); + }); + it('should return -1 when the value is not present', function () { + var _rec2 = new _PowerAssertRecorder1(); + var minusOne = -1, two = 2; + assert.ok(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec2._capt(two, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec2._capt(minusOne, 'arguments/0/right'), 'arguments/0'), { + content: 'assert.ok(this.ary.indexOf(two) === minusOne, \'THIS IS AN ASSERTION MESSAGE\')', + filepath: 'path/to/some_test.js', + line: 13 + }), 'THIS IS AN ASSERTION MESSAGE'); + }); +}); diff --git a/test/fixtures/WithoutUseStrict/fixture.js b/test/fixtures/WithoutUseStrict/fixture.js new file mode 100644 index 0000000..1cf3562 --- /dev/null +++ b/test/fixtures/WithoutUseStrict/fixture.js @@ -0,0 +1,15 @@ +var assert = require('power-assert'); + +describe('Array#indexOf()', function () { + beforeEach(function () { + this.ary = [1,2,3]; + }); + it('should return index when the value is present', function () { + var who = 'ariya', two = 2; + assert(this.ary.indexOf(who) === two); + }); + it('should return -1 when the value is not present', function () { + var minusOne = -1, two = 2; + assert.ok(this.ary.indexOf(two) === minusOne, 'THIS IS AN ASSERTION MESSAGE'); + }); +}); diff --git a/test/fixtures/WithoutUseStrictNorRequireAssert/expected.js b/test/fixtures/WithoutUseStrictNorRequireAssert/expected.js new file mode 100644 index 0000000..c4f73d3 --- /dev/null +++ b/test/fixtures/WithoutUseStrictNorRequireAssert/expected.js @@ -0,0 +1,49 @@ +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); +describe('Array#indexOf()', function () { + beforeEach(function () { + this.ary = [ + 1, + 2, + 3 + ]; + }); + it('should return index when the value is present', function () { + var _rec1 = new _PowerAssertRecorder1(); + var who = 'ariya', two = 2; + assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec1._capt(who, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec1._capt(two, 'arguments/0/right'), 'arguments/0'), { + content: 'assert(this.ary.indexOf(who) === two)', + filepath: 'path/to/some_test.js', + line: 7 + })); + }); + it('should return -1 when the value is not present', function () { + var _rec2 = new _PowerAssertRecorder1(); + var minusOne = -1, two = 2; + assert.ok(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec2._capt(two, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec2._capt(minusOne, 'arguments/0/right'), 'arguments/0'), { + content: 'assert.ok(this.ary.indexOf(two) === minusOne, \'THIS IS AN ASSERTION MESSAGE\')', + filepath: 'path/to/some_test.js', + line: 11 + }), 'THIS IS AN ASSERTION MESSAGE'); + }); +}); diff --git a/test/fixtures/WithoutUseStrictNorRequireAssert/fixture.js b/test/fixtures/WithoutUseStrictNorRequireAssert/fixture.js new file mode 100644 index 0000000..95f5113 --- /dev/null +++ b/test/fixtures/WithoutUseStrictNorRequireAssert/fixture.js @@ -0,0 +1,13 @@ +describe('Array#indexOf()', function () { + beforeEach(function () { + this.ary = [1,2,3]; + }); + it('should return index when the value is present', function () { + var who = 'ariya', two = 2; + assert(this.ary.indexOf(who) === two); + }); + it('should return -1 when the value is not present', function () { + var minusOne = -1, two = 2; + assert.ok(this.ary.indexOf(two) === minusOne, 'THIS IS AN ASSERTION MESSAGE'); + }); +}); diff --git a/test/fixtures/YieldExpression/expected.js b/test/fixtures/YieldExpression/expected.js index 9755acb..f98d25c 100644 --- a/test/fixtures/YieldExpression/expected.js +++ b/test/fixtures/YieldExpression/expected.js @@ -1,6 +1,29 @@ 'use strict'; +var _PowerAssertRecorder1 = function () { + function PowerAssertRecorder() { + this.captured = []; + } + PowerAssertRecorder.prototype._capt = function _capt(value, espath) { + this.captured.push({ + value: value, + espath: espath + }); + return value; + }; + PowerAssertRecorder.prototype._expr = function _expr(value, source) { + return { + powerAssertContext: { + value: value, + events: this.captured + }, + source: source + }; + }; + return PowerAssertRecorder; +}(); function* gen(a) { - assert(assert._expr(assert._capt(assert._capt(yield a, 'arguments/0/left') === 3, 'arguments/0'), { + var _rec1 = new _PowerAssertRecorder1(); + assert(_rec1._expr(_rec1._capt(_rec1._capt(yield a, 'arguments/0/left') === 3, 'arguments/0'), { content: 'assert((yield a) === 3)', filepath: 'path/to/some_test.js', line: 4, diff --git a/test/instrumentation_test.js b/test/instrumentation_test.js index 04378a3..0d91f85 100644 --- a/test/instrumentation_test.js +++ b/test/instrumentation_test.js @@ -18,6 +18,17 @@ acornEs7Plugin(acorn); describe('instrumentation spec', function () { + function rec(num) { + return 'var _rec' + num + '=new _PowerAssertRecorder1();'; + } + function prelude(num) { + var decl = "var _PowerAssertRecorder1=function(){function PowerAssertRecorder(){this.captured=[];}PowerAssertRecorder.prototype._capt=function _capt(value,espath){this.captured.push({value:value,espath:espath});return value;};PowerAssertRecorder.prototype._expr=function _expr(value,source){return{powerAssertContext:{value:value,events:this.captured},source:source};};return PowerAssertRecorder;}();"; + for (var i = 1; i <= num; i+=1) { + decl += rec(i); + } + return decl; + } + function testWithParserOptions (jsCode, expected, options) { it(jsCode, function () { var jsAST = acorn.parse(jsCode, options); @@ -58,7 +69,7 @@ describe('instrumentation spec', function () { inst("assert.equal(1, 0);", "assert.equal(1,0);"); - + inst("assert(false, 'message');", "assert(false,'message');"); @@ -66,259 +77,259 @@ describe('instrumentation spec', function () { "assert(false,messageStr);"); inst("assert.equal(foo, 'bar', 'msg');", - "assert.equal(assert._expr(assert._capt(foo,'arguments/0'),{content:'assert.equal(foo, \\'bar\\', \\'msg\\')',filepath:'path/to/some_test.js',line:1}),'bar','msg');"); + prelude(1) + "assert.equal(_rec1._expr(_rec1._capt(foo,'arguments/0'),{content:'assert.equal(foo, \\'bar\\', \\'msg\\')',filepath:'path/to/some_test.js',line:1}),'bar','msg');"); }); describe('Identifier', function () { inst("assert(falsyStr);", - "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(falsyStr, messageStr);", - "assert(assert._expr(assert._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr, messageStr)',filepath:'path/to/some_test.js',line:1}),messageStr);"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr, messageStr)',filepath:'path/to/some_test.js',line:1}),messageStr);"); inst("assert.equal(str, anotherStr);", - "assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}),assert._expr(assert._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.equal(_rec1._expr(_rec1._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.equal(\nstr,\nanotherStr\n);", - "assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}),assert._expr(assert._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.equal(_rec1._expr(_rec1._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.equal(str, anotherStr, messageStr);", - "assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr, messageStr)',filepath:'path/to/some_test.js',line:1}),assert._expr(assert._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr, messageStr)',filepath:'path/to/some_test.js',line:1}),messageStr);"); + prelude(2) + "assert.equal(_rec1._expr(_rec1._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr, messageStr)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr, messageStr)',filepath:'path/to/some_test.js',line:1}),messageStr);"); }); describe('Identifier: multiline, multiassert', function () { inst("assert.equal(\nstr,\nanotherStr\n);\n\nassert.equal(\nstr,\nyetAnotherStr\n);", - "assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}),assert._expr(assert._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}));assert.equal(assert._expr(assert._capt(str,'arguments/0'),{content:'assert.equal(str, yetAnotherStr)',filepath:'path/to/some_test.js',line:6}),assert._expr(assert._capt(yetAnotherStr,'arguments/1'),{content:'assert.equal(str, yetAnotherStr)',filepath:'path/to/some_test.js',line:6}));"); + prelude(4) + "assert.equal(_rec1._expr(_rec1._capt(str,'arguments/0'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(anotherStr,'arguments/1'),{content:'assert.equal(str, anotherStr)',filepath:'path/to/some_test.js',line:1}));assert.equal(_rec3._expr(_rec3._capt(str,'arguments/0'),{content:'assert.equal(str, yetAnotherStr)',filepath:'path/to/some_test.js',line:6}),_rec4._expr(_rec4._capt(yetAnotherStr,'arguments/1'),{content:'assert.equal(str, yetAnotherStr)',filepath:'path/to/some_test.js',line:6}));"); }); describe('BinaryExpression', function () { inst("assert(4 !== 4);", - "assert(assert._expr(assert._capt(4!==4,'arguments/0'),{content:'assert(4 !== 4)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(4!==4,'arguments/0'),{content:'assert(4 !== 4)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(fuga !== 4);", - "assert(assert._expr(assert._capt(assert._capt(fuga,'arguments/0/left')!==4,'arguments/0'),{content:'assert(fuga !== 4)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(fuga,'arguments/0/left')!==4,'arguments/0'),{content:'assert(fuga !== 4)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(fuga === piyo);", - "assert(assert._expr(assert._capt(assert._capt(fuga,'arguments/0/left')===assert._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga === piyo)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(fuga,'arguments/0/left')===_rec1._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga === piyo)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(fuga\n ===\n piyo);", - "assert(assert._expr(assert._capt(assert._capt(fuga,'arguments/0/left')===assert._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga === piyo)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(fuga,'arguments/0/left')===_rec1._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga === piyo)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(fuga === piyo);", - "assert(assert._expr(assert._capt(assert._capt(fuga,'arguments/0/left')===assert._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga === piyo)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(fuga,'arguments/0/left')===_rec1._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga === piyo)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(fuga !== piyo);", - "assert(assert._expr(assert._capt(assert._capt(fuga,'arguments/0/left')!==assert._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga !== piyo)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(fuga,'arguments/0/left')!==_rec1._capt(piyo,'arguments/0/right'),'arguments/0'),{content:'assert(fuga !== piyo)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.ok(hoge === fuga, 'comment');", - "assert.ok(assert._expr(assert._capt(assert._capt(hoge,'arguments/0/left')===assert._capt(fuga,'arguments/0/right'),'arguments/0'),{content:'assert.ok(hoge === fuga, \\'comment\\')',filepath:'path/to/some_test.js',line:1}),'comment');"); + prelude(1) + "assert.ok(_rec1._expr(_rec1._capt(_rec1._capt(hoge,'arguments/0/left')===_rec1._capt(fuga,'arguments/0/right'),'arguments/0'),{content:'assert.ok(hoge === fuga, \\'comment\\')',filepath:'path/to/some_test.js',line:1}),'comment');"); inst("assert(ary1.length === ary2.length);", - "assert(assert._expr(assert._capt(assert._capt(assert._capt(ary1,'arguments/0/left/object').length,'arguments/0/left')===assert._capt(assert._capt(ary2,'arguments/0/right/object').length,'arguments/0/right'),'arguments/0'),{content:'assert(ary1.length === ary2.length)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(ary1,'arguments/0/left/object').length,'arguments/0/left')===_rec1._capt(_rec1._capt(ary2,'arguments/0/right/object').length,'arguments/0/right'),'arguments/0'),{content:'assert(ary1.length === ary2.length)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(foo instanceof Foo);", - "assert(assert._expr(assert._capt(assert._capt(foo,'arguments/0/left')instanceof assert._capt(Foo,'arguments/0/right'),'arguments/0'),{content:'assert(foo instanceof Foo)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/left')instanceof _rec1._capt(Foo,'arguments/0/right'),'arguments/0'),{content:'assert(foo instanceof Foo)',filepath:'path/to/some_test.js',line:1}));"); }); describe('UnaryExpression', function () { inst("assert(!truth);", - "assert(assert._expr(assert._capt(!assert._capt(truth,'arguments/0/argument'),'arguments/0'),{content:'assert(!truth)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(!_rec1._capt(truth,'arguments/0/argument'),'arguments/0'),{content:'assert(!truth)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(!!some);", - "assert(assert._expr(assert._capt(!assert._capt(!assert._capt(some,'arguments/0/argument/argument'),'arguments/0/argument'),'arguments/0'),{content:'assert(!!some)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(!_rec1._capt(!_rec1._capt(some,'arguments/0/argument/argument'),'arguments/0/argument'),'arguments/0'),{content:'assert(!!some)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(!!foo.bar);", - "assert(assert._expr(assert._capt(!assert._capt(!assert._capt(assert._capt(foo,'arguments/0/argument/argument/object').bar,'arguments/0/argument/argument'),'arguments/0/argument'),'arguments/0'),{content:'assert(!!foo.bar)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(!_rec1._capt(!_rec1._capt(_rec1._capt(foo,'arguments/0/argument/argument/object').bar,'arguments/0/argument/argument'),'arguments/0/argument'),'arguments/0'),{content:'assert(!!foo.bar)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(delete foo.bar);", - "assert(assert._expr(assert._capt(delete assert._capt(assert._capt(foo,'arguments/0/argument/object').bar,'arguments/0/argument'),'arguments/0'),{content:'assert(delete foo.bar)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(delete _rec1._capt(_rec1._capt(foo,'arguments/0/argument/object').bar,'arguments/0/argument'),'arguments/0'),{content:'assert(delete foo.bar)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(typeof foo !== 'undefined');", - "assert(assert._expr(assert._capt(assert._capt(typeof foo,'arguments/0/left')!=='undefined','arguments/0'),{content:'assert(typeof foo !== \\'undefined\\')',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(typeof foo,'arguments/0/left')!=='undefined','arguments/0'),{content:'assert(typeof foo !== \\'undefined\\')',filepath:'path/to/some_test.js',line:1}));"); inst("assert(typeof foo.bar !== 'undefined');", - "assert(assert._expr(assert._capt(assert._capt(typeof assert._capt(assert._capt(foo,'arguments/0/left/argument/object').bar,'arguments/0/left/argument'),'arguments/0/left')!=='undefined','arguments/0'),{content:'assert(typeof foo.bar !== \\'undefined\\')',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(typeof _rec1._capt(_rec1._capt(foo,'arguments/0/left/argument/object').bar,'arguments/0/left/argument'),'arguments/0/left')!=='undefined','arguments/0'),{content:'assert(typeof foo.bar !== \\'undefined\\')',filepath:'path/to/some_test.js',line:1}));"); inst("assert.strictEqual(typeof foo, typeof bar);", - "assert.strictEqual(assert._expr(assert._capt(typeof foo,'arguments/0'),{content:'assert.strictEqual(typeof foo, typeof bar)',filepath:'path/to/some_test.js',line:1}),assert._expr(assert._capt(typeof bar,'arguments/1'),{content:'assert.strictEqual(typeof foo, typeof bar)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.strictEqual(_rec1._expr(_rec1._capt(typeof foo,'arguments/0'),{content:'assert.strictEqual(typeof foo, typeof bar)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(typeof bar,'arguments/1'),{content:'assert.strictEqual(typeof foo, typeof bar)',filepath:'path/to/some_test.js',line:1}));"); }); describe('LogicalExpression', function () { inst("assert(5 < actual && actual < 13);", - "assert(assert._expr(assert._capt(assert._capt(5 actual && actual < 13);", - "assert(assert._expr(assert._capt(assert._capt(2>assert._capt(actual,'arguments/0/left/right'),'arguments/0/left')&&assert._capt(assert._capt(actual,'arguments/0/right/left')<13,'arguments/0/right'),'arguments/0'),{content:'assert(2 > actual && actual < 13)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(2>_rec1._capt(actual,'arguments/0/left/right'),'arguments/0/left')&&_rec1._capt(_rec1._capt(actual,'arguments/0/right/left')<13,'arguments/0/right'),'arguments/0'),{content:'assert(2 > actual && actual < 13)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(2 > actual && actual < 13);", - "assert(assert._expr(assert._capt(assert._capt(2>assert._capt(actual,'arguments/0/left/right'),'arguments/0/left')&&assert._capt(assert._capt(actual,'arguments/0/right/left')<13,'arguments/0/right'),'arguments/0'),{content:'assert(2 > actual && actual < 13)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(2>_rec1._capt(actual,'arguments/0/left/right'),'arguments/0/left')&&_rec1._capt(_rec1._capt(actual,'arguments/0/right/left')<13,'arguments/0/right'),'arguments/0'),{content:'assert(2 > actual && actual < 13)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.equal(5 < actual && actual < 13, falsy);", - "assert.equal(assert._expr(assert._capt(assert._capt(5 ({even: v, odd: v + 1}));", "assert(v=>({even:v,odd:v+1}));"); inst("assert(seven === ((v, i) => v + i)(four, five));", - "assert(assert._expr(assert._capt(assert._capt(seven,'arguments/0/left')===assert._capt(((v,i)=>v+i)(assert._capt(four,'arguments/0/right/arguments/0'),assert._capt(five,'arguments/0/right/arguments/1')),'arguments/0/right'),'arguments/0'),{content:'assert(seven === ((v, i) => v + i)(four, five))',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(seven,'arguments/0/left')===_rec1._capt(((v,i)=>v+i)(_rec1._capt(four,'arguments/0/right/arguments/0'),_rec1._capt(five,'arguments/0/right/arguments/1')),'arguments/0/right'),'arguments/0'),{content:'assert(seven === ((v, i) => v + i)(four, five))',filepath:'path/to/some_test.js',line:1}));"); }); describe('ClassExpression: body will not be instrumented', function () { @@ -377,9 +388,9 @@ describe('instrumentation spec', function () { describe('AssignmentExpression: left hand side of Destructuring will not be instrumented', function () { inst("assert([x] = [3]);", - "assert(assert._expr(assert._capt([x]=assert._capt([3],'arguments/0/right'),'arguments/0'),{content:'assert([x] = [3])',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt([x]=_rec1._capt([3],'arguments/0/right'),'arguments/0'),{content:'assert([x] = [3])',filepath:'path/to/some_test.js',line:1}));"); inst("assert([x] = [foo]);", - "assert(assert._expr(assert._capt([x]=assert._capt([assert._capt(foo,'arguments/0/right/elements/0')],'arguments/0/right'),'arguments/0'),{content:'assert([x] = [foo])',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt([x]=_rec1._capt([_rec1._capt(foo,'arguments/0/right/elements/0')],'arguments/0/right'),'arguments/0'),{content:'assert([x] = [foo])',filepath:'path/to/some_test.js',line:1}));"); }); describe('Literal: Binary and Octal Literals', function () { @@ -391,76 +402,76 @@ describe('instrumentation spec', function () { describe('SpreadElement', function () { inst("assert(hello(...names));", - "assert(assert._expr(assert._capt(hello(...assert._capt(names,'arguments/0/arguments/0/argument')),'arguments/0'),{content:'assert(hello(...names))',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(hello(..._rec1._capt(names,'arguments/0/arguments/0/argument')),'arguments/0'),{content:'assert(hello(...names))',filepath:'path/to/some_test.js',line:1}));"); inst("assert([head, ...tail].length);", - "assert(assert._expr(assert._capt(assert._capt([assert._capt(head,'arguments/0/object/elements/0'),...assert._capt(tail,'arguments/0/object/elements/1/argument')],'arguments/0/object').length,'arguments/0'),{content:'assert([head,...tail].length)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt([_rec1._capt(head,'arguments/0/object/elements/0'),..._rec1._capt(tail,'arguments/0/object/elements/1/argument')],'arguments/0/object').length,'arguments/0'),{content:'assert([head,...tail].length)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(f(head, ...iter(), ...[foo, bar]));", - "assert(assert._expr(assert._capt(f(assert._capt(head,'arguments/0/arguments/0'),...assert._capt(iter(),'arguments/0/arguments/1/argument'),...assert._capt([assert._capt(foo,'arguments/0/arguments/2/argument/elements/0'),assert._capt(bar,'arguments/0/arguments/2/argument/elements/1')],'arguments/0/arguments/2/argument')),'arguments/0'),{content:'assert(f(head, ...iter(), ...[foo,bar]))',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(f(_rec1._capt(head,'arguments/0/arguments/0'),..._rec1._capt(iter(),'arguments/0/arguments/1/argument'),..._rec1._capt([_rec1._capt(foo,'arguments/0/arguments/2/argument/elements/0'),_rec1._capt(bar,'arguments/0/arguments/2/argument/elements/1')],'arguments/0/arguments/2/argument')),'arguments/0'),{content:'assert(f(head, ...iter(), ...[foo,bar]))',filepath:'path/to/some_test.js',line:1}));"); }); describe('YieldExpression', function () { inst("function *gen() {assert((yield bigOrSmall(size)) === 'big')}", - "function*gen(){assert(assert._expr(assert._capt(assert._capt(yield bigOrSmall(assert._capt(size,'arguments/0/left/argument/arguments/0')),'arguments/0/left')==='big','arguments/0'),{content:'assert((yield bigOrSmall(size)) === \\'big\\')',filepath:'path/to/some_test.js',line:1,generator:true}));}"); + prelude(0) + "function*gen(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(yield bigOrSmall(_rec1._capt(size,'arguments/0/left/argument/arguments/0')),'arguments/0/left')==='big','arguments/0'),{content:'assert((yield bigOrSmall(size)) === \\'big\\')',filepath:'path/to/some_test.js',line:1,generator:true}));}"); }); - describe('YieldExpression vs FunctionCall disambiguation', function () { + describe('disambiguation: YieldExpression vs FunctionCall', function () { inst("function baz() {assert((yield (foo)) === bar)}", - "function baz(){assert(assert._expr(assert._capt(assert._capt(yield(assert._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(yield(foo) === bar)',filepath:'path/to/some_test.js',line:1}));}"); + prelude(0) + "function baz(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(yield(_rec1._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(yield(foo) === bar)',filepath:'path/to/some_test.js',line:1}));}"); inst("function *baz() {assert((yield (foo)) === bar)}", - "function*baz(){assert(assert._expr(assert._capt(assert._capt(yield foo,'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((yield foo) === bar)',filepath:'path/to/some_test.js',line:1,generator:true}));}"); + prelude(0) + "function*baz(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(yield foo,'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((yield foo) === bar)',filepath:'path/to/some_test.js',line:1,generator:true}));}"); inst("var baz = function () {assert((yield (foo)) === bar)}", - "var baz=function(){assert(assert._expr(assert._capt(assert._capt(yield(assert._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(yield(foo) === bar)',filepath:'path/to/some_test.js',line:1}));};"); + prelude(0) + "var baz=function(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(yield(_rec1._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(yield(foo) === bar)',filepath:'path/to/some_test.js',line:1}));};"); inst("var baz = function *() {assert((yield (foo)) === bar)}", - "var baz=function*(){assert(assert._expr(assert._capt(assert._capt(yield foo,'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((yield foo) === bar)',filepath:'path/to/some_test.js',line:1,generator:true}));};"); + prelude(0) + "var baz=function*(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(yield foo,'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((yield foo) === bar)',filepath:'path/to/some_test.js',line:1,generator:true}));};"); }); describe('AwaitExpression', function () { inst("async function gen() {assert((await bigOrSmall(size)) === 'big')}", - "async function gen(){assert(assert._expr(assert._capt(assert._capt(await bigOrSmall(assert._capt(size,'arguments/0/left/argument/arguments/0')),'arguments/0/left')==='big','arguments/0'),{content:'assert((await bigOrSmall(size)) === \\'big\\')',filepath:'path/to/some_test.js',line:1,async:true}));}"); + prelude(0) + "async function gen(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(await bigOrSmall(_rec1._capt(size,'arguments/0/left/argument/arguments/0')),'arguments/0/left')==='big','arguments/0'),{content:'assert((await bigOrSmall(size)) === \\'big\\')',filepath:'path/to/some_test.js',line:1,async:true}));}"); }); - describe('AwaitExpression vs FunctionCall disambiguation', function () { + describe('disambiguation: AwaitExpression vs FunctionCall', function () { inst("function baz() {assert((await (foo)) === bar)}", - "function baz(){assert(assert._expr(assert._capt(assert._capt(await(assert._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(await(foo) === bar)',filepath:'path/to/some_test.js',line:1}));}"); + prelude(0) + "function baz(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(await(_rec1._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(await(foo) === bar)',filepath:'path/to/some_test.js',line:1}));}"); inst("async function baz() {assert((await (foo)) === bar)}", - "async function baz(){assert(assert._expr(assert._capt(assert._capt(await foo,'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((await foo) === bar)',filepath:'path/to/some_test.js',line:1,async:true}));}"); + prelude(0) + "async function baz(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(await foo,'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((await foo) === bar)',filepath:'path/to/some_test.js',line:1,async:true}));}"); inst("var baz = function () {assert((await (foo)) === bar)}", - "var baz=function(){assert(assert._expr(assert._capt(assert._capt(await(assert._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(await(foo) === bar)',filepath:'path/to/some_test.js',line:1}));};"); + prelude(0) + "var baz=function(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(await(_rec1._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(await(foo) === bar)',filepath:'path/to/some_test.js',line:1}));};"); inst("var baz = async function () {assert((await (foo)) === bar)}", - "var baz=async function(){assert(assert._expr(assert._capt(assert._capt(await foo,'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((await foo) === bar)',filepath:'path/to/some_test.js',line:1,async:true}));};"); + prelude(0) + "var baz=async function(){" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(await foo,'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((await foo) === bar)',filepath:'path/to/some_test.js',line:1,async:true}));};"); inst("var baz = () => {assert((await (foo)) === bar)};", - "var baz=()=>{assert(assert._expr(assert._capt(assert._capt(await(assert._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(await(foo) === bar)',filepath:'path/to/some_test.js',line:1}));};"); + prelude(0) + "var baz=()=>{" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(await(_rec1._capt(foo,'arguments/0/left/arguments/0')),'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert(await(foo) === bar)',filepath:'path/to/some_test.js',line:1}));};"); inst("var baz = async () => {assert((await (foo)) === bar)}", - "var baz=async()=>{assert(assert._expr(assert._capt(assert._capt(await foo,'arguments/0/left')===assert._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((await foo) === bar)',filepath:'path/to/some_test.js',line:1,async:true}));};"); + prelude(0) + "var baz=async()=>{" + rec(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(await foo,'arguments/0/left')===_rec1._capt(bar,'arguments/0/right'),'arguments/0'),{content:'assert((await foo) === bar)',filepath:'path/to/some_test.js',line:1,async:true}));};"); }); describe('Enhanced Object Literals', function () { describe('Property: Computed (dynamic) property names', function () { inst("assert({[num]: foo});", - "assert(assert._expr(assert._capt({[assert._capt(num,'arguments/0/properties/0/key')]:assert._capt(foo,'arguments/0/properties/0/value')},'arguments/0'),{content:'assert({ [num]: foo })',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt({[_rec1._capt(num,'arguments/0/properties/0/key')]:_rec1._capt(foo,'arguments/0/properties/0/value')},'arguments/0'),{content:'assert({ [num]: foo })',filepath:'path/to/some_test.js',line:1}));"); inst("assert({[ 'prop_' + (() => bar())() ]: 42});", - "assert(assert._expr(assert._capt({[assert._capt('prop_'+assert._capt((()=>bar())(),'arguments/0/properties/0/key/right'),'arguments/0/properties/0/key')]:42},'arguments/0'),{content:'assert({ [\\'prop_\\' + (() => bar())()]: 42 })',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt({[_rec1._capt('prop_'+_rec1._capt((()=>bar())(),'arguments/0/properties/0/key/right'),'arguments/0/properties/0/key')]:42},'arguments/0'),{content:'assert({ [\\'prop_\\' + (() => bar())()]: 42 })',filepath:'path/to/some_test.js',line:1}));"); inst("assert({[`prop_${generate(seed)}`]: foo});", - "assert(assert._expr(assert._capt({[assert._capt(`prop_${assert._capt(generate(assert._capt(seed,'arguments/0/properties/0/key/expressions/0/arguments/0')),'arguments/0/properties/0/key/expressions/0')}`,'arguments/0/properties/0/key')]:assert._capt(foo,'arguments/0/properties/0/value')},'arguments/0'),{content:'assert({ [`prop_${ generate(seed) }`]: foo })',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt({[_rec1._capt(`prop_${_rec1._capt(generate(_rec1._capt(seed,'arguments/0/properties/0/key/expressions/0/arguments/0')),'arguments/0/properties/0/key/expressions/0')}`,'arguments/0/properties/0/key')]:_rec1._capt(foo,'arguments/0/properties/0/value')},'arguments/0'),{content:'assert({ [`prop_${ generate(seed) }`]: foo })',filepath:'path/to/some_test.js',line:1}));"); }); describe('Property: shorthand literal itself will not be instrumented', function () { inst("assert({foo});", - "assert(assert._expr(assert._capt({foo},'arguments/0'),{content:'assert({ foo })',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt({foo},'arguments/0'),{content:'assert({ foo })',filepath:'path/to/some_test.js',line:1}));"); inst("assert({foo, bar: baz});", - "assert(assert._expr(assert._capt({foo,bar:assert._capt(baz,'arguments/0/properties/1/value')},'arguments/0'),{content:'assert({foo,bar: baz})',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt({foo,bar:_rec1._capt(baz,'arguments/0/properties/1/value')},'arguments/0'),{content:'assert({foo,bar: baz})',filepath:'path/to/some_test.js',line:1}));"); }); }); });