From 9faf9bf0203b80b29fc06fa93302fde835d51349 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 1 Feb 2016 14:28:53 +0900 Subject: [PATCH 01/39] feat(espower): spike implementation of per-argument value recorder --- lib/assertion-visitor.js | 70 ++++++++++++++++++++++++++++++++- lib/instrumentor.js | 30 +++++++++++++- test/fixture_test.js | 4 ++ test/fixtures/Mocha/expected.js | 2 + 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 5024d5f..0084ed5 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -23,7 +23,8 @@ var canonicalCodeOptions = { 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; @@ -52,6 +53,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; @@ -61,12 +64,49 @@ AssertionVisitor.prototype.leave = function (controller) { // nothing to do now }; +AssertionVisitor.prototype.createNewRecorder = function (controller) { + var _this = this; + var found = findEnclosingBlockStatement(controller.parents(), controller.path()); + var argumentEspath = found.path.join('/'); + // var helperNameNode = this.getRecordHelperNameNode(controller); + + var currentNode = controller.current(); + var n = newNodeWithLocationCopyOf(currentNode); + this.options.storage.transformation.register(argumentEspath, function (matchNode) { + var init = _this.createNewExpression(n, '_powerAssertRecorder'); + matchNode.body.unshift(_this.createVariableDeclaration(n, '_rec', init)); + }); +}; + +function findEnclosingBlockStatement (parents, initialPath) { + // iterate child to root + var child, parent, path = initialPath; + for (var i = parents.length - 1; i >= 0; i--) { + parent = parents[i]; + if (child) { + function popUntilParent (key) { + if (parent[key] !== undefined) { + return; + } + popUntilParent(path.pop()); + } + popUntilParent(path.pop()); + } + if (parent.type === syntax.BlockStatement) { + return {node: parent, path: path}; + } + child = parent; + } + return null; +} + AssertionVisitor.prototype.leaveArgument = function (resultTree) { try { return this.argumentModified ? this.captureArgument(resultTree) : resultTree; } finally { this.currentArgumentPath = null; this.argumentModified = false; + this.valueRecorder = null; } }; @@ -209,6 +249,34 @@ AssertionVisitor.prototype.guessPowerAssertCalleeObjectFor = function (node) { return null; }; +AssertionVisitor.prototype.createVariableDeclaration = function (createNode, varName, init) { + return createNode({ + type: syntax.VariableDeclaration, + declarations: [ + createNode({ + type: syntax.VariableDeclarator, + id: createNode({ + type: syntax.Identifier, + name: varName + }), + 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) { if (typeof value !== 'undefined') { addToProps(props, createNode, name, createNode({ diff --git a/lib/instrumentor.js b/lib/instrumentor.js index ad851d0..22e6ecf 100644 --- a/lib/instrumentor.js +++ b/lib/instrumentor.js @@ -8,6 +8,25 @@ 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 = {}; +} +Transformation.prototype.register = function (espath, callback) { + if (!this.mutations[espath]) { + this.mutations[espath] = []; + } + this.mutations[espath].push(callback); +}; +Transformation.prototype.apply = function (espath, node) { + this.mutations[espath].forEach(function (callback) { + callback(node); + }); +}; +Transformation.prototype.isTarget = function (espath) { + return !!this.mutations[espath]; +}; function Instrumentor (options) { verifyOptionPrerequisites(options); @@ -19,6 +38,9 @@ Instrumentor.prototype.instrument = function (ast) { verifyAstPrerequisites(ast, this.options); var that = this; var assertionVisitor; + var storage = { + transformation: new Transformation() + }; var skipping = false; var result = (this.options.destructive) ? ast : cloneAst(ast); var visitor = { @@ -38,7 +60,7 @@ 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}, that.options)); assertionVisitor.enter(controller); return undefined; } @@ -48,6 +70,12 @@ Instrumentor.prototype.instrument = function (ast) { leave: function (currentNode, parentNode) { var controller = this; var resultTree = currentNode; + var path = controller.path(); + var espath = path ? path.join('/') : ''; + if (storage.transformation.isTarget(espath)) { + storage.transformation.apply(espath, resultTree); + return resultTree; + } if (!assertionVisitor) { return undefined; } diff --git a/test/fixture_test.js b/test/fixture_test.js index c5b189e..08eb696 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -54,3 +54,7 @@ describe('espower', function () { testTransform('Property'); testTransform('YieldExpression'); }); + +describe.only('recorder per argument', function () { + testTransform('Mocha'); +}); diff --git a/test/fixtures/Mocha/expected.js b/test/fixtures/Mocha/expected.js index dadaa4c..6c02e3a 100644 --- a/test/fixtures/Mocha/expected.js +++ b/test/fixtures/Mocha/expected.js @@ -9,6 +9,7 @@ describe('Array#indexOf()', function () { ]; }); it('should return index when the value is present', function () { + var _rec = new _powerAssertRecorder(); 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'), { content: 'assert(this.ary.indexOf(who) === two)', @@ -17,6 +18,7 @@ describe('Array#indexOf()', function () { })); }); it('should return -1 when the value is not present', function () { + var _rec = new _powerAssertRecorder(); 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'), { content: 'assert.ok(this.ary.indexOf(two) === minusOne, \'THIS IS AN ASSERTION MESSAGE\')', From b2b4ae2e0575acb94fe8507f01ee21b91e2a404e Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 1 Feb 2016 15:17:59 +0900 Subject: [PATCH 02/39] test(espower): case when assertions are not enclosed in functions --- test/fixture_test.js | 1 + test/fixtures/Identifier/expected.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/test/fixture_test.js b/test/fixture_test.js index 08eb696..f346195 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -57,4 +57,5 @@ describe('espower', function () { describe.only('recorder per argument', function () { testTransform('Mocha'); + testTransform('Identifier'); }); diff --git a/test/fixtures/Identifier/expected.js b/test/fixtures/Identifier/expected.js index 98107bb..2610a65 100644 --- a/test/fixtures/Identifier/expected.js +++ b/test/fixtures/Identifier/expected.js @@ -1,3 +1,15 @@ +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); +var _rec = new _powerAssertRecorder(); 'use strict'; assert(assert._expr(assert._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr)', From 2c9c762d47afa7deb91da486e59395018c1d5746 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 1 Feb 2016 15:25:11 +0900 Subject: [PATCH 03/39] refactor(espower): introduce escope for more accurate scope detection --- lib/assertion-visitor.js | 20 +++++++---- lib/instrumentor.js | 73 ++++++++++++++++++++++++---------------- package.json | 1 + 3 files changed, 58 insertions(+), 36 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 0084ed5..1f156a9 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -65,20 +65,26 @@ AssertionVisitor.prototype.leave = function (controller) { }; AssertionVisitor.prototype.createNewRecorder = function (controller) { - var _this = this; - var found = findEnclosingBlockStatement(controller.parents(), controller.path()); + var currentScope = this.options.currentScope; + var found = findEnclosingScopeEspath(controller.parents(), controller.path(), currentScope.block); var argumentEspath = found.path.join('/'); // var helperNameNode = this.getRecordHelperNameNode(controller); var currentNode = controller.current(); - var n = newNodeWithLocationCopyOf(currentNode); + var createNode = newNodeWithLocationCopyOf(currentNode); + var init = this.createNewExpression(createNode, '_powerAssertRecorder'); + var decl = this.createVariableDeclaration(createNode, '_rec', init); this.options.storage.transformation.register(argumentEspath, function (matchNode) { - var init = _this.createNewExpression(n, '_powerAssertRecorder'); - matchNode.body.unshift(_this.createVariableDeclaration(n, '_rec', init)); + if (/Function/.test(matchNode.type)) { + var blockStatement = matchNode.body; + blockStatement.body.unshift(decl); + } else { + matchNode.body.unshift(decl); + } }); }; -function findEnclosingBlockStatement (parents, initialPath) { +function findEnclosingScopeEspath (parents, initialPath, scopeNode) { // iterate child to root var child, parent, path = initialPath; for (var i = parents.length - 1; i >= 0; i--) { @@ -92,7 +98,7 @@ function findEnclosingBlockStatement (parents, initialPath) { } popUntilParent(path.pop()); } - if (parent.type === syntax.BlockStatement) { + if (parent === scopeNode) { return {node: parent, path: path}; } child = parent; diff --git a/lib/instrumentor.js b/lib/instrumentor.js index 22e6ecf..3f1b956 100644 --- a/lib/instrumentor.js +++ b/lib/instrumentor.js @@ -2,6 +2,7 @@ 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'); @@ -43,8 +44,13 @@ Instrumentor.prototype.instrument = function (ast) { }; var skipping = false; var result = (this.options.destructive) ? ast : cloneAst(ast); + var scopeManager = escope.analyze(result); + var currentScope = scopeManager.acquire(result); 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; @@ -60,7 +66,10 @@ 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, extend({storage: storage}, that.options)); + assertionVisitor = new AssertionVisitor(matcher, extend({ + storage: storage, + currentScope: currentScope + }, that.options)); assertionVisitor.enter(controller); return undefined; } @@ -68,36 +77,42 @@ Instrumentor.prototype.instrument = function (ast) { return undefined; }, leave: function (currentNode, parentNode) { - var controller = this; - var resultTree = currentNode; - var path = controller.path(); - var espath = path ? path.join('/') : ''; - if (storage.transformation.isTarget(espath)) { - storage.transformation.apply(espath, resultTree); + try { + var controller = this; + var resultTree = currentNode; + var path = controller.path(); + var espath = path ? path.join('/') : ''; + if (storage.transformation.isTarget(espath)) { + storage.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; + } } - 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; } }; if (this.options.visitorKeys) { diff --git a/package.json b/package.json index a3e114e..1c5bf5c 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "deep-equal": "^1.0.0", "escallmatch": "^1.4.2", "escodegen": "^1.7.0", + "escope": "^3.3.0", "espower-location-detector": "^0.1.1", "espurify": "^1.3.0", "estraverse": "^4.1.0", From 100201b73eb36f551b42a84c884313695f0f5f60 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 1 Feb 2016 15:35:20 +0900 Subject: [PATCH 04/39] refactor(espower): refactor to findEspathOfAncestorNode function --- lib/assertion-visitor.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 1f156a9..b4d44b7 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -66,15 +66,14 @@ AssertionVisitor.prototype.leave = function (controller) { AssertionVisitor.prototype.createNewRecorder = function (controller) { var currentScope = this.options.currentScope; - var found = findEnclosingScopeEspath(controller.parents(), controller.path(), currentScope.block); - var argumentEspath = found.path.join('/'); + var scopeBlockEspath = findEspathOfAncestorNode(currentScope.block, controller); // var helperNameNode = this.getRecordHelperNameNode(controller); var currentNode = controller.current(); var createNode = newNodeWithLocationCopyOf(currentNode); var init = this.createNewExpression(createNode, '_powerAssertRecorder'); var decl = this.createVariableDeclaration(createNode, '_rec', init); - this.options.storage.transformation.register(argumentEspath, function (matchNode) { + this.options.storage.transformation.register(scopeBlockEspath, function (matchNode) { if (/Function/.test(matchNode.type)) { var blockStatement = matchNode.body; blockStatement.body.unshift(decl); @@ -84,9 +83,11 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { }); }; -function findEnclosingScopeEspath (parents, initialPath, scopeNode) { +function findEspathOfAncestorNode (targetNode, controller) { // iterate child to root - var child, parent, path = initialPath; + var child, parent; + var path = controller.path(); + var parents = controller.parents(); for (var i = parents.length - 1; i >= 0; i--) { parent = parents[i]; if (child) { @@ -98,8 +99,8 @@ function findEnclosingScopeEspath (parents, initialPath, scopeNode) { } popUntilParent(path.pop()); } - if (parent === scopeNode) { - return {node: parent, path: path}; + if (parent === targetNode) { + return path.join('/'); } child = parent; } From 5fa4e96c428ea4c7b92c01b75f3ee3f85ca0dc21 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 1 Feb 2016 17:30:03 +0900 Subject: [PATCH 05/39] feat(espower): use generated identifier for per-argument value recorder --- lib/assertion-visitor.js | 20 ++++++++++---------- test/fixtures/Identifier/expected.js | 24 ++++++++++++------------ test/fixtures/Mocha/expected.js | 4 ++-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index b4d44b7..c8e93da 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -71,8 +71,12 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { var currentNode = controller.current(); var createNode = newNodeWithLocationCopyOf(currentNode); + var ident = createNode({ + type: syntax.Identifier, + name: '_rec' + }); var init = this.createNewExpression(createNode, '_powerAssertRecorder'); - var decl = this.createVariableDeclaration(createNode, '_rec', init); + var decl = this.createVariableDeclaration(createNode, ident, init); this.options.storage.transformation.register(scopeBlockEspath, function (matchNode) { if (/Function/.test(matchNode.type)) { var blockStatement = matchNode.body; @@ -81,6 +85,7 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { matchNode.body.unshift(decl); } }); + return ident; }; function findEspathOfAncestorNode (targetNode, controller) { @@ -123,13 +128,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' @@ -199,7 +203,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); @@ -214,7 +217,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' @@ -256,16 +259,13 @@ AssertionVisitor.prototype.guessPowerAssertCalleeObjectFor = function (node) { return null; }; -AssertionVisitor.prototype.createVariableDeclaration = function (createNode, varName, init) { +AssertionVisitor.prototype.createVariableDeclaration = function (createNode, ident, init) { return createNode({ type: syntax.VariableDeclaration, declarations: [ createNode({ type: syntax.VariableDeclarator, - id: createNode({ - type: syntax.Identifier, - name: varName - }), + id: ident, init: init }) ], diff --git a/test/fixtures/Identifier/expected.js b/test/fixtures/Identifier/expected.js index 2610a65..59744db 100644 --- a/test/fixtures/Identifier/expected.js +++ b/test/fixtures/Identifier/expected.js @@ -11,57 +11,57 @@ var _rec = new _powerAssertRecorder(); var _rec = new _powerAssertRecorder(); var _rec = new _powerAssertRecorder(); 'use strict'; -assert(assert._expr(assert._capt(falsyStr, 'arguments/0'), { +assert(_rec._expr(_rec._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr)', filepath: 'path/to/some_test.js', line: 3 })); -assert(assert._expr(assert._capt(falsyStr, 'arguments/0'), { +assert(_rec._expr(_rec._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(_rec._expr(_rec._capt(str, 'arguments/0'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 7 -}), assert._expr(assert._capt(anotherStr, 'arguments/1'), { +}), _rec._expr(_rec._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(_rec._expr(_rec._capt(str, 'arguments/0'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 9 -}), assert._expr(assert._capt(anotherStr, 'arguments/1'), { +}), _rec._expr(_rec._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(_rec._expr(_rec._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'), { +}), _rec._expr(_rec._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(_rec._expr(_rec._capt(str, 'arguments/0'), { content: 'assert.equal(str, anotherStr)', filepath: 'path/to/some_test.js', line: 16 -}), assert._expr(assert._capt(anotherStr, 'arguments/1'), { +}), _rec._expr(_rec._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(_rec._expr(_rec._capt(str, 'arguments/0'), { content: 'assert.equal(str, yetAnotherStr)', filepath: 'path/to/some_test.js', line: 21 -}), assert._expr(assert._capt(yetAnotherStr, 'arguments/1'), { +}), _rec._expr(_rec._capt(yetAnotherStr, 'arguments/1'), { content: 'assert.equal(str, yetAnotherStr)', filepath: 'path/to/some_test.js', line: 21 diff --git a/test/fixtures/Mocha/expected.js b/test/fixtures/Mocha/expected.js index 6c02e3a..0ad1511 100644 --- a/test/fixtures/Mocha/expected.js +++ b/test/fixtures/Mocha/expected.js @@ -11,7 +11,7 @@ describe('Array#indexOf()', function () { it('should return index when the value is present', function () { var _rec = new _powerAssertRecorder(); 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(_rec._expr(_rec._capt(_rec._capt(_rec._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec._capt(who, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec._capt(two, 'arguments/0/right'), 'arguments/0'), { content: 'assert(this.ary.indexOf(who) === two)', filepath: 'path/to/some_test.js', line: 11 @@ -20,7 +20,7 @@ describe('Array#indexOf()', function () { it('should return -1 when the value is not present', function () { var _rec = new _powerAssertRecorder(); 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(_rec._expr(_rec._capt(_rec._capt(_rec._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec._capt(two, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec._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 From 96b39a435c68f08e2134a30953ee8e061820c706 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 1 Feb 2016 17:46:51 +0900 Subject: [PATCH 06/39] feat(espower): generate unique recorder variable name --- lib/assertion-visitor.js | 3 +- lib/instrumentor.js | 8 +++++ test/fixtures/Identifier/expected.js | 48 ++++++++++++++-------------- test/fixtures/Mocha/expected.js | 8 ++--- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index c8e93da..0875e23 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -68,12 +68,13 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { var currentScope = this.options.currentScope; var scopeBlockEspath = findEspathOfAncestorNode(currentScope.block, controller); // var helperNameNode = this.getRecordHelperNameNode(controller); + var recorderVariableName = this.options.storage.transformation.generateUniqueName('rec'); var currentNode = controller.current(); var createNode = newNodeWithLocationCopyOf(currentNode); var ident = createNode({ type: syntax.Identifier, - name: '_rec' + name: recorderVariableName }); var init = this.createNewExpression(createNode, '_powerAssertRecorder'); var decl = this.createVariableDeclaration(createNode, ident, init); diff --git a/lib/instrumentor.js b/lib/instrumentor.js index 3f1b956..5a996ce 100644 --- a/lib/instrumentor.js +++ b/lib/instrumentor.js @@ -13,6 +13,7 @@ var extend = require('xtend'); function Transformation () { this.mutations = {}; + this.nameCounts = {}; } Transformation.prototype.register = function (espath, callback) { if (!this.mutations[espath]) { @@ -28,6 +29,13 @@ Transformation.prototype.apply = function (espath, 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); diff --git a/test/fixtures/Identifier/expected.js b/test/fixtures/Identifier/expected.js index 59744db..1d4e77f 100644 --- a/test/fixtures/Identifier/expected.js +++ b/test/fixtures/Identifier/expected.js @@ -1,67 +1,67 @@ -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); -var _rec = new _powerAssertRecorder(); +var _rec12 = new _powerAssertRecorder(); +var _rec11 = new _powerAssertRecorder(); +var _rec10 = new _powerAssertRecorder(); +var _rec9 = new _powerAssertRecorder(); +var _rec8 = new _powerAssertRecorder(); +var _rec7 = new _powerAssertRecorder(); +var _rec6 = new _powerAssertRecorder(); +var _rec5 = new _powerAssertRecorder(); +var _rec4 = new _powerAssertRecorder(); +var _rec3 = new _powerAssertRecorder(); +var _rec2 = new _powerAssertRecorder(); +var _rec1 = new _powerAssertRecorder(); 'use strict'; -assert(_rec._expr(_rec._capt(falsyStr, 'arguments/0'), { +assert(_rec1._expr(_rec1._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr)', filepath: 'path/to/some_test.js', line: 3 })); -assert(_rec._expr(_rec._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(_rec._expr(_rec._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 -}), _rec._expr(_rec._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(_rec._expr(_rec._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 -}), _rec._expr(_rec._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(_rec._expr(_rec._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 -}), _rec._expr(_rec._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(_rec._expr(_rec._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 -}), _rec._expr(_rec._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(_rec._expr(_rec._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 -}), _rec._expr(_rec._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/Mocha/expected.js b/test/fixtures/Mocha/expected.js index 0ad1511..cbbadee 100644 --- a/test/fixtures/Mocha/expected.js +++ b/test/fixtures/Mocha/expected.js @@ -9,18 +9,18 @@ describe('Array#indexOf()', function () { ]; }); it('should return index when the value is present', function () { - var _rec = new _powerAssertRecorder(); + var _rec1 = new _powerAssertRecorder(); var who = 'ariya', two = 2; - assert(_rec._expr(_rec._capt(_rec._capt(_rec._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec._capt(who, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec._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 _rec = new _powerAssertRecorder(); + var _rec2 = new _powerAssertRecorder(); var minusOne = -1, two = 2; - assert.ok(_rec._expr(_rec._capt(_rec._capt(_rec._capt(this.ary, 'arguments/0/left/callee/object').indexOf(_rec._capt(two, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec._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 From c0e32ef6a19ee67bfbdb413b72c6c1a6da880162 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 1 Feb 2016 18:00:05 +0900 Subject: [PATCH 07/39] refactor(espower): prepare for embedding recorder class --- lib/assertion-visitor.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 0875e23..cd09bae 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -67,7 +67,7 @@ AssertionVisitor.prototype.leave = function (controller) { AssertionVisitor.prototype.createNewRecorder = function (controller) { var currentScope = this.options.currentScope; var scopeBlockEspath = findEspathOfAncestorNode(currentScope.block, controller); - // var helperNameNode = this.getRecordHelperNameNode(controller); + var recorderConstructorName = this.getRecorderConstructorName(controller); var recorderVariableName = this.options.storage.transformation.generateUniqueName('rec'); var currentNode = controller.current(); @@ -76,7 +76,7 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { type: syntax.Identifier, name: recorderVariableName }); - var init = this.createNewExpression(createNode, '_powerAssertRecorder'); + var init = this.createNewExpression(createNode, recorderConstructorName); var decl = this.createVariableDeclaration(createNode, ident, init); this.options.storage.transformation.register(scopeBlockEspath, function (matchNode) { if (/Function/.test(matchNode.type)) { @@ -89,6 +89,19 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { return ident; }; +AssertionVisitor.prototype.getRecorderConstructorName = function (controller) { + var ctorName = this.options.storage.powerAssertRecorderConstructorName; + if (!ctorName) { + ctorName = this.createRecorderClass(controller); + } + return ctorName; +}; + +AssertionVisitor.prototype.createRecorderClass = function (controller) { + this.options.storage.powerAssertRecorderConstructorName = '_powerAssertRecorder'; + return '_powerAssertRecorder'; +}; + function findEspathOfAncestorNode (targetNode, controller) { // iterate child to root var child, parent; From d0fe35169da98b447ace9e969b8d395d41e3c6df Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Tue, 2 Feb 2016 01:23:17 +0900 Subject: [PATCH 08/39] feat(espower): embed recorder class at top level --- lib/assertion-visitor.js | 22 +- lib/instrumentor.js | 12 +- lib/power-assert-recorder.json | 303 +++++++++++++++++++++++++++ test/fixtures/Identifier/expected.js | 46 ++-- test/fixtures/Mocha/expected.js | 26 ++- 5 files changed, 386 insertions(+), 23 deletions(-) create mode 100644 lib/power-assert-recorder.json diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index cd09bae..322ad5a 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -20,6 +20,7 @@ var canonicalCodeOptions = { }, verbatim: 'x-verbatim-espower' }; +var recorderClassAst = require('./power-assert-recorder.json'); function AssertionVisitor (matcher, options) { this.matcher = matcher; @@ -68,7 +69,7 @@ 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.storage.transformation.generateUniqueName('rec'); + var recorderVariableName = this.options.transformation.generateUniqueName('rec'); var currentNode = controller.current(); var createNode = newNodeWithLocationCopyOf(currentNode); @@ -78,7 +79,7 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { }); var init = this.createNewExpression(createNode, recorderConstructorName); var decl = this.createVariableDeclaration(createNode, ident, init); - this.options.storage.transformation.register(scopeBlockEspath, function (matchNode) { + this.options.transformation.register(scopeBlockEspath, function (matchNode) { if (/Function/.test(matchNode.type)) { var blockStatement = matchNode.body; blockStatement.body.unshift(decl); @@ -98,8 +99,21 @@ AssertionVisitor.prototype.getRecorderConstructorName = function (controller) { }; AssertionVisitor.prototype.createRecorderClass = function (controller) { - this.options.storage.powerAssertRecorderConstructorName = '_powerAssertRecorder'; - return '_powerAssertRecorder'; + 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(recorderClassAst, createNode, this.options.visitorKeys); + var decl = this.createVariableDeclaration(createNode, ident, classDef); + this.options.transformation.register(globalScopeBlockEspath, function (matchNode) { + matchNode.body.unshift(decl); + }); + this.options.storage.powerAssertRecorderConstructorName = ctorName; + return ctorName; }; function findEspathOfAncestorNode (targetNode, controller) { diff --git a/lib/instrumentor.js b/lib/instrumentor.js index 5a996ce..74231ed 100644 --- a/lib/instrumentor.js +++ b/lib/instrumentor.js @@ -47,13 +47,13 @@ Instrumentor.prototype.instrument = function (ast) { verifyAstPrerequisites(ast, this.options); var that = this; var assertionVisitor; - var storage = { - transformation: new Transformation() - }; + 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)) { @@ -76,6 +76,8 @@ Instrumentor.prototype.instrument = function (ast) { // entering target assertion assertionVisitor = new AssertionVisitor(matcher, extend({ storage: storage, + transformation: transformation, + globalScope: globalScope, currentScope: currentScope }, that.options)); assertionVisitor.enter(controller); @@ -90,8 +92,8 @@ Instrumentor.prototype.instrument = function (ast) { var resultTree = currentNode; var path = controller.path(); var espath = path ? path.join('/') : ''; - if (storage.transformation.isTarget(espath)) { - storage.transformation.apply(espath, resultTree); + if (transformation.isTarget(espath)) { + transformation.apply(espath, resultTree); return resultTree; } if (!assertionVisitor) { diff --git a/lib/power-assert-recorder.json b/lib/power-assert-recorder.json new file mode 100644 index 0000000..d432872 --- /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": [] +} diff --git a/test/fixtures/Identifier/expected.js b/test/fixtures/Identifier/expected.js index 1d4e77f..6e6967b 100644 --- a/test/fixtures/Identifier/expected.js +++ b/test/fixtures/Identifier/expected.js @@ -1,15 +1,37 @@ -var _rec12 = new _powerAssertRecorder(); -var _rec11 = new _powerAssertRecorder(); -var _rec10 = new _powerAssertRecorder(); -var _rec9 = new _powerAssertRecorder(); -var _rec8 = new _powerAssertRecorder(); -var _rec7 = new _powerAssertRecorder(); -var _rec6 = new _powerAssertRecorder(); -var _rec5 = new _powerAssertRecorder(); -var _rec4 = new _powerAssertRecorder(); -var _rec3 = new _powerAssertRecorder(); -var _rec2 = new _powerAssertRecorder(); -var _rec1 = new _powerAssertRecorder(); +var _rec12 = new _PowerAssertRecorder1(); +var _rec11 = new _PowerAssertRecorder1(); +var _rec10 = new _PowerAssertRecorder1(); +var _rec9 = new _PowerAssertRecorder1(); +var _rec8 = new _PowerAssertRecorder1(); +var _rec7 = new _PowerAssertRecorder1(); +var _rec6 = new _PowerAssertRecorder1(); +var _rec5 = new _PowerAssertRecorder1(); +var _rec4 = new _PowerAssertRecorder1(); +var _rec3 = new _PowerAssertRecorder1(); +var _rec2 = new _PowerAssertRecorder1(); +var _rec1 = new _PowerAssertRecorder1(); +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; +}(); 'use strict'; assert(_rec1._expr(_rec1._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr)', diff --git a/test/fixtures/Mocha/expected.js b/test/fixtures/Mocha/expected.js index cbbadee..d9ecd8e 100644 --- a/test/fixtures/Mocha/expected.js +++ b/test/fixtures/Mocha/expected.js @@ -1,3 +1,25 @@ +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; +}(); 'use strict'; var assert = require('power-assert'); describe('Array#indexOf()', function () { @@ -9,7 +31,7 @@ describe('Array#indexOf()', function () { ]; }); it('should return index when the value is present', function () { - var _rec1 = new _powerAssertRecorder(); + 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)', @@ -18,7 +40,7 @@ describe('Array#indexOf()', function () { })); }); it('should return -1 when the value is not present', function () { - var _rec2 = new _powerAssertRecorder(); + 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\')', From fa304ebffa264b5dce0b8068e7133d1513864c9b Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Tue, 2 Feb 2016 01:30:38 +0900 Subject: [PATCH 09/39] chore(espower): unshift node insertion callback --- lib/instrumentor.js | 2 +- test/fixtures/Identifier/expected.js | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/instrumentor.js b/lib/instrumentor.js index 74231ed..f813d7c 100644 --- a/lib/instrumentor.js +++ b/lib/instrumentor.js @@ -19,7 +19,7 @@ Transformation.prototype.register = function (espath, callback) { if (!this.mutations[espath]) { this.mutations[espath] = []; } - this.mutations[espath].push(callback); + this.mutations[espath].unshift(callback); }; Transformation.prototype.apply = function (espath, node) { this.mutations[espath].forEach(function (callback) { diff --git a/test/fixtures/Identifier/expected.js b/test/fixtures/Identifier/expected.js index 6e6967b..04a6385 100644 --- a/test/fixtures/Identifier/expected.js +++ b/test/fixtures/Identifier/expected.js @@ -1,15 +1,3 @@ -var _rec12 = new _PowerAssertRecorder1(); -var _rec11 = new _PowerAssertRecorder1(); -var _rec10 = new _PowerAssertRecorder1(); -var _rec9 = new _PowerAssertRecorder1(); -var _rec8 = new _PowerAssertRecorder1(); -var _rec7 = new _PowerAssertRecorder1(); -var _rec6 = new _PowerAssertRecorder1(); -var _rec5 = new _PowerAssertRecorder1(); -var _rec4 = new _PowerAssertRecorder1(); -var _rec3 = new _PowerAssertRecorder1(); -var _rec2 = new _PowerAssertRecorder1(); -var _rec1 = new _PowerAssertRecorder1(); var _PowerAssertRecorder1 = function () { function PowerAssertRecorder() { this.captured = []; @@ -32,6 +20,18 @@ var _PowerAssertRecorder1 = function () { }; 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(); 'use strict'; assert(_rec1._expr(_rec1._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr)', From c6497bff283600df61616326c511568775d87e97 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Tue, 2 Feb 2016 02:01:04 +0900 Subject: [PATCH 10/39] refactor(espower): insert after 'use strict' directive --- lib/assertion-visitor.js | 19 ++++++++++++++++--- test/fixtures/Identifier/expected.js | 2 +- test/fixtures/Mocha/expected.js | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 322ad5a..b35716a 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -80,12 +80,14 @@ AssertionVisitor.prototype.createNewRecorder = function (controller) { 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; - blockStatement.body.unshift(decl); + body = blockStatement.body; } else { - matchNode.body.unshift(decl); + body = matchNode.body; } + insertAfterUseStrictDirective(decl, body); }); return ident; }; @@ -110,12 +112,23 @@ AssertionVisitor.prototype.createRecorderClass = function (controller) { var classDef = updateLocRecursively(recorderClassAst, createNode, this.options.visitorKeys); var decl = this.createVariableDeclaration(createNode, ident, classDef); this.options.transformation.register(globalScopeBlockEspath, function (matchNode) { - matchNode.body.unshift(decl); + insertAfterUseStrictDirective(decl, matchNode.body); }); this.options.storage.powerAssertRecorderConstructorName = ctorName; return ctorName; }; +function insertAfterUseStrictDirective (decl, body) { + var firstBody = body[0]; + if (firstBody.type === syntax.ExpressionStatement) { + if (astEqual(firstBody.expression, { type: syntax.Literal, value: 'use strict' })) { + body.splice(1,0, decl); + } + } else { + body.unshift(decl); + } +} + function findEspathOfAncestorNode (targetNode, controller) { // iterate child to root var child, parent; diff --git a/test/fixtures/Identifier/expected.js b/test/fixtures/Identifier/expected.js index 04a6385..00c2ef4 100644 --- a/test/fixtures/Identifier/expected.js +++ b/test/fixtures/Identifier/expected.js @@ -1,3 +1,4 @@ +'use strict'; var _PowerAssertRecorder1 = function () { function PowerAssertRecorder() { this.captured = []; @@ -32,7 +33,6 @@ var _rec9 = new _PowerAssertRecorder1(); var _rec10 = new _PowerAssertRecorder1(); var _rec11 = new _PowerAssertRecorder1(); var _rec12 = new _PowerAssertRecorder1(); -'use strict'; assert(_rec1._expr(_rec1._capt(falsyStr, 'arguments/0'), { content: 'assert(falsyStr)', filepath: 'path/to/some_test.js', diff --git a/test/fixtures/Mocha/expected.js b/test/fixtures/Mocha/expected.js index d9ecd8e..6cc9200 100644 --- a/test/fixtures/Mocha/expected.js +++ b/test/fixtures/Mocha/expected.js @@ -1,3 +1,4 @@ +'use strict'; var _PowerAssertRecorder1 = function () { function PowerAssertRecorder() { this.captured = []; @@ -20,7 +21,6 @@ var _PowerAssertRecorder1 = function () { }; return PowerAssertRecorder; }(); -'use strict'; var assert = require('power-assert'); describe('Array#indexOf()', function () { beforeEach(function () { From c701b01d8f0acf6bb65093bbefa9a4fa8b4bfe71 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Tue, 2 Feb 2016 17:16:19 +0900 Subject: [PATCH 11/39] refactor(espower): reorder methods by visibility --- lib/assertion-visitor.js | 176 +++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index b35716a..034e961 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -65,94 +65,6 @@ AssertionVisitor.prototype.leave = function (controller) { // nothing to do now }; -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 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(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; -}; - -function insertAfterUseStrictDirective (decl, body) { - var firstBody = body[0]; - if (firstBody.type === syntax.ExpressionStatement) { - if (astEqual(firstBody.expression, { type: syntax.Literal, value: 'use strict' })) { - body.splice(1,0, decl); - } - } else { - body.unshift(decl); - } -} - -function findEspathOfAncestorNode (targetNode, controller) { - // iterate child to root - var child, parent; - var path = controller.path(); - var parents = controller.parents(); - for (var i = parents.length - 1; i >= 0; i--) { - parent = parents[i]; - if (child) { - function popUntilParent (key) { - if (parent[key] !== undefined) { - return; - } - popUntilParent(path.pop()); - } - popUntilParent(path.pop()); - } - if (parent === targetNode) { - return path.join('/'); - } - child = parent; - } - return null; -} - AssertionVisitor.prototype.leaveArgument = function (resultTree) { try { return this.argumentModified ? this.captureArgument(resultTree) : resultTree; @@ -290,6 +202,59 @@ AssertionVisitor.prototype.verifyNotInstrumented = function (currentNode) { } }; +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 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(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.guessPowerAssertCalleeObjectFor = function (node) { switch(node.type) { case syntax.Identifier: @@ -398,6 +363,41 @@ 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(); + for (var i = parents.length - 1; i >= 0; i--) { + parent = parents[i]; + if (child) { + function popUntilParent (key) { + if (parent[key] !== undefined) { + return; + } + popUntilParent(path.pop()); + } + 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) { + if (astEqual(firstBody.expression, { type: syntax.Literal, value: 'use strict' })) { + body.splice(1,0, decl); + } + } else { + body.unshift(decl); + } +} + function isFunction (node) { switch(node.type) { case syntax.FunctionDeclaration: From 8ec2c2bebe656381ab42b18986e64516f5734043 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Tue, 2 Feb 2016 17:22:23 +0900 Subject: [PATCH 12/39] refactor(espower): remove callee guessing logic since callees are now generated --- lib/assertion-visitor.js | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 034e961..d4d1538 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -35,7 +35,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; @@ -192,13 +191,11 @@ 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); } }; @@ -255,16 +252,6 @@ AssertionVisitor.prototype.createRecorderClass = function (controller) { return ctorName; }; -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) - } - return null; -}; - AssertionVisitor.prototype.createVariableDeclaration = function (createNode, ident, init) { return createNode({ type: syntax.VariableDeclaration, From 7f107e62f59d367c53a21e234704e099ce9ccd0b Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Tue, 2 Feb 2016 17:28:07 +0900 Subject: [PATCH 13/39] refactor(espower): don't make functions within a loop --- lib/assertion-visitor.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index d4d1538..a45d74e 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -355,15 +355,15 @@ function findEspathOfAncestorNode (targetNode, controller) { 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) { - function popUntilParent (key) { - if (parent[key] !== undefined) { - return; - } - popUntilParent(path.pop()); - } popUntilParent(path.pop()); } if (parent === targetNode) { From e0376863c2288d367552970215adf5a82c966fbe Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Tue, 2 Feb 2016 18:59:51 +0900 Subject: [PATCH 14/39] chore(espower): clone recorder AST to be embedded before updating locations --- lib/assertion-visitor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index a45d74e..3a5d4a6 100644 --- a/lib/assertion-visitor.js +++ b/lib/assertion-visitor.js @@ -243,7 +243,7 @@ AssertionVisitor.prototype.createRecorderClass = function (controller) { type: syntax.Identifier, name: ctorName }); - var classDef = updateLocRecursively(recorderClassAst, createNode, this.options.visitorKeys); + 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); From 158807105b1feb424da4e49c23b0e433ebaa04f6 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Thu, 4 Feb 2016 11:42:20 +0900 Subject: [PATCH 15/39] test(espower): testing BinaryExpression --- test/fixture_test.js | 1 + test/fixtures/BinaryExpression/expected.js | 52 ++++++++++++++++++---- test/fixtures/BinaryExpression/fixture.js | 2 + 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index f346195..6cf0cd6 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -58,4 +58,5 @@ describe('espower', function () { describe.only('recorder per argument', function () { testTransform('Mocha'); testTransform('Identifier'); + testTransform('BinaryExpression'); }); 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); From 61abcecda4727115da9df9a5d4c2c3710fefac7e Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Thu, 4 Feb 2016 11:43:05 +0900 Subject: [PATCH 16/39] test(espower): testing UnaryExpression --- test/fixture_test.js | 1 + test/fixtures/UnaryExpression/expected.js | 46 +++++++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index 6cf0cd6..42e7718 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -59,4 +59,5 @@ describe.only('recorder per argument', function () { testTransform('Mocha'); testTransform('Identifier'); testTransform('BinaryExpression'); + testTransform('UnaryExpression'); }); 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 From bb29f050f7bb7d24fd6f265168b3c439dbe9a95b Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 11:11:59 +0900 Subject: [PATCH 17/39] test(espower): testing MemberExpression --- test/fixture_test.js | 1 + test/fixtures/MemberExpression/expected.js | 58 +++++++++++++++++----- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index 42e7718..62cd630 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -60,4 +60,5 @@ describe.only('recorder per argument', function () { testTransform('Identifier'); testTransform('BinaryExpression'); testTransform('UnaryExpression'); + testTransform('MemberExpression'); }); 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 From 7865585792d1bcf52d062dbaace26da6bda7b811 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 11:14:32 +0900 Subject: [PATCH 18/39] test(espower): testing CallExpression --- test/fixture_test.js | 1 + test/fixtures/CallExpression/expected.js | 58 +++++++++++++++++++----- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index 62cd630..d83b341 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -61,4 +61,5 @@ describe.only('recorder per argument', function () { testTransform('BinaryExpression'); testTransform('UnaryExpression'); testTransform('MemberExpression'); + testTransform('CallExpression'); }); 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 From a7ee2ffba9bc69b658c0e98be3095193f2f2f70d Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 11:25:00 +0900 Subject: [PATCH 19/39] test(espower): testing ArrayExpression, ObjectExpression and Property --- test/fixture_test.js | 3 ++ test/fixtures/ArrayExpression/expected.js | 56 ++++++++++++++++------ test/fixtures/ObjectExpression/expected.js | 54 +++++++++++++++------ test/fixtures/Property/expected.js | 39 ++++++++++++--- 4 files changed, 117 insertions(+), 35 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index d83b341..21540f5 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -62,4 +62,7 @@ describe.only('recorder per argument', function () { testTransform('UnaryExpression'); testTransform('MemberExpression'); testTransform('CallExpression'); + testTransform('ArrayExpression'); + testTransform('ObjectExpression'); + testTransform('Property'); }); 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/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', From d96651d5626763bf7108a81f765aa07153cf67cc Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 11:39:57 +0900 Subject: [PATCH 20/39] test(espower): testing LogicalExpression and ConditionalExpression --- test/fixture_test.js | 2 + .../ConditionalExpression/expected.js | 37 ++++++++++++++--- test/fixtures/LogicalExpression/expected.js | 40 ++++++++++++++++--- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index 21540f5..fd41659 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -65,4 +65,6 @@ describe.only('recorder per argument', function () { testTransform('ArrayExpression'); testTransform('ObjectExpression'); testTransform('Property'); + testTransform('LogicalExpression'); + testTransform('ConditionalExpression'); }); 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/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 From 9708273cffd4969f2e9a1114c43f912cb9c32d57 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 11:43:10 +0900 Subject: [PATCH 21/39] test(espower): testing AssignmentExpression and UpdateExpression --- test/fixture_test.js | 2 + .../fixtures/AssignmentExpression/expected.js | 43 ++++++++++++++++--- test/fixtures/UpdateExpression/expected.js | 34 +++++++++++++-- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index fd41659..bb36af3 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -67,4 +67,6 @@ describe.only('recorder per argument', function () { testTransform('Property'); testTransform('LogicalExpression'); testTransform('ConditionalExpression'); + testTransform('AssignmentExpression'); + testTransform('UpdateExpression'); }); 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/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 From f897aa93f667a18c315afb2793c105dbb5dc9e99 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 11:49:28 +0900 Subject: [PATCH 22/39] test(espower): testing FunctionExpression and ArrowFunctionExpression --- test/fixture_test.js | 2 ++ .../ArrowFunctionExpression/expected.js | 25 ++++++++++++++++- test/fixtures/FunctionExpression/expected.js | 27 +++++++++++++++++-- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index bb36af3..b169b35 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -69,4 +69,6 @@ describe.only('recorder per argument', function () { testTransform('ConditionalExpression'); testTransform('AssignmentExpression'); testTransform('UpdateExpression'); + testTransform('FunctionExpression'); + testTransform('ArrowFunctionExpression'); }); 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/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 From c62b1c92d4f4e660c984aa6392bba04f13a5f17d Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 16:15:11 +0900 Subject: [PATCH 23/39] test(espower): testing ClassExpression and other non-target patterns --- test/fixture_test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fixture_test.js b/test/fixture_test.js index b169b35..ca02a3a 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -57,6 +57,7 @@ describe('espower', function () { describe.only('recorder per argument', function () { testTransform('Mocha'); + testTransform('NonTarget'); testTransform('Identifier'); testTransform('BinaryExpression'); testTransform('UnaryExpression'); @@ -71,4 +72,5 @@ describe.only('recorder per argument', function () { testTransform('UpdateExpression'); testTransform('FunctionExpression'); testTransform('ArrowFunctionExpression'); + testTransform('ClassExpression'); }); From 03741b4190fd275fec388122641122bc93733a6b Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 16:16:23 +0900 Subject: [PATCH 24/39] test(espower): testing Literal and NewExpression --- test/fixture_test.js | 2 ++ test/fixtures/Literal/expected.js | 34 ++++++++++++++++++++--- test/fixtures/NewExpression/expected.js | 37 +++++++++++++++++++++---- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index ca02a3a..ae517ba 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -58,11 +58,13 @@ describe('espower', function () { describe.only('recorder per argument', function () { testTransform('Mocha'); testTransform('NonTarget'); + testTransform('Literal'); testTransform('Identifier'); testTransform('BinaryExpression'); testTransform('UnaryExpression'); testTransform('MemberExpression'); testTransform('CallExpression'); + testTransform('NewExpression'); testTransform('ArrayExpression'); testTransform('ObjectExpression'); testTransform('Property'); 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/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 From 5befa5c00e7bdfbe4148bc87366f64bacab69d59 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 16:25:08 +0900 Subject: [PATCH 25/39] test(espower): testing TemplateLiteral and TaggedTemplateExpression --- test/fixture_test.js | 2 ++ .../TaggedTemplateExpression/expected.js | 31 +++++++++++++++++-- test/fixtures/TemplateLiteral/expected.js | 31 +++++++++++++++++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index ae517ba..5afb435 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -75,4 +75,6 @@ describe.only('recorder per argument', function () { testTransform('FunctionExpression'); testTransform('ArrowFunctionExpression'); testTransform('ClassExpression'); + testTransform('TemplateLiteral'); + testTransform('TaggedTemplateExpression'); }); 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 From 0f86f1642abe53f0d4dd58eb7c1bf7005c2d0a0e Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 16:27:46 +0900 Subject: [PATCH 26/39] test(espower): testing SpreadElement --- test/fixture_test.js | 1 + test/fixtures/SpreadElement/expected.js | 39 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index 5afb435..de2bc24 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -77,4 +77,5 @@ describe.only('recorder per argument', function () { testTransform('ClassExpression'); testTransform('TemplateLiteral'); testTransform('TaggedTemplateExpression'); + testTransform('SpreadElement'); }); 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', From 421cf790e4f3221394d6122ac076e3a16a2d3a66 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 16:28:36 +0900 Subject: [PATCH 27/39] test(espower): testing YieldExpression --- test/fixture_test.js | 1 + test/fixtures/YieldExpression/expected.js | 24 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/test/fixture_test.js b/test/fixture_test.js index de2bc24..e7387c3 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -78,4 +78,5 @@ describe.only('recorder per argument', function () { testTransform('TemplateLiteral'); testTransform('TaggedTemplateExpression'); testTransform('SpreadElement'); + testTransform('YieldExpression'); }); diff --git a/test/fixtures/YieldExpression/expected.js b/test/fixtures/YieldExpression/expected.js index 9755acb..41a1d46 100644 --- a/test/fixtures/YieldExpression/expected.js +++ b/test/fixtures/YieldExpression/expected.js @@ -1,6 +1,28 @@ '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'), { + 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, From 197be558557f5ca029555d2257a9da2f84c13ca3 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 16:31:42 +0900 Subject: [PATCH 28/39] test(espower): testing AwaitExpression --- test/fixture_test.js | 1 + test/fixtures/AwaitExpression/expected.js | 31 +++++++++++++++++++++++ test/fixtures/AwaitExpression/fixture.js | 9 +++++++ 3 files changed, 41 insertions(+) create mode 100644 test/fixtures/AwaitExpression/expected.js create mode 100644 test/fixtures/AwaitExpression/fixture.js diff --git a/test/fixture_test.js b/test/fixture_test.js index e7387c3..abf0604 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -79,4 +79,5 @@ describe.only('recorder per argument', function () { testTransform('TaggedTemplateExpression'); testTransform('SpreadElement'); testTransform('YieldExpression'); + testTransform('AwaitExpression'); }); diff --git a/test/fixtures/AwaitExpression/expected.js b/test/fixtures/AwaitExpression/expected.js new file mode 100644 index 0000000..15c6e16 --- /dev/null +++ b/test/fixtures/AwaitExpression/expected.js @@ -0,0 +1,31 @@ +'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) { + 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); +// } From 079bfc6273cc472132083776e6d3d8f067b3bf7c Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Fri, 5 Feb 2016 17:03:39 +0900 Subject: [PATCH 29/39] test(espower): back to all green --- test/espower_option_test.js | 21 ++-- test/fixture_test.js | 28 +---- test/instrumentation_test.js | 212 ++++++++++++++++++----------------- 3 files changed, 119 insertions(+), 142 deletions(-) diff --git a/test/espower_option_test.js b/test/espower_option_test.js index b146e7a..2e2b6ee 100644 --- a/test/espower_option_test.js +++ b/test/espower_option_test.js @@ -121,7 +121,7 @@ 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, "refute(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'refute(falsyStr)',line:1}));"); }); it('matches method call', function () { @@ -130,7 +130,7 @@ 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, "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 +139,7 @@ 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, "browser.assert.element(_rec1._expr(_rec1._capt(foo,'arguments/0'),{content:'browser.assert.element(foo)',line:1}));"); }); }); @@ -147,11 +147,11 @@ 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, "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, "assert(_rec1._expr(_rec1._capt(falsyStr,'arguments/0'),{content:'assert(falsyStr)',filepath:'path/to/baz_test.js',line:1}));"); }); }); }); @@ -221,7 +221,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 +236,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(browser._rec1._expr(browser._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 +274,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 +336,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 +437,7 @@ 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, "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 abf0604..b8d3e9d 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -29,33 +29,7 @@ function testTransform (fixtureName, extraOptions) { }); } -describe('espower', function () { - testTransform('Mocha'); - testTransform('NonTarget'); - testTransform('Literal'); - testTransform('Identifier'); - testTransform('BinaryExpression'); - testTransform('UnaryExpression'); - testTransform('LogicalExpression'); - testTransform('MemberExpression'); - testTransform('CallExpression'); - testTransform('AssignmentExpression'); - testTransform('ArrayExpression'); - testTransform('UpdateExpression'); - testTransform('ConditionalExpression'); - testTransform('ObjectExpression'); - testTransform('NewExpression'); - testTransform('FunctionExpression'); - testTransform('TemplateLiteral'); - testTransform('TaggedTemplateExpression'); - testTransform('ArrowFunctionExpression'); - testTransform('ClassExpression'); - testTransform('SpreadElement'); - testTransform('Property'); - testTransform('YieldExpression'); -}); - -describe.only('recorder per argument', function () { +describe('fixtures', function () { testTransform('Mocha'); testTransform('NonTarget'); testTransform('Literal'); diff --git a/test/instrumentation_test.js b/test/instrumentation_test.js index 04378a3..f35c2fb 100644 --- a/test/instrumentation_test.js +++ b/test/instrumentation_test.js @@ -66,259 +66,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');"); + "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}));"); + "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);"); + "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}));"); + "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}));"); + "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);"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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');"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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 +377,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}));"); + "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}));"); + "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 +391,78 @@ 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}));"); + "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}));"); + "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}));"); + "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}));"); }); + var prelude = "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('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 + "function*gen(){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 + "function baz(){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 + "function*baz(){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 + "var baz=function(){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 + "var baz=function*(){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 + "async function gen(){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 + "function baz(){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 + "async function baz(){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 + "var baz=function(){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 + "var baz=async function(){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 + "var baz=()=>{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 + "var baz=async()=>{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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); + "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}));"); }); }); }); From 7efe94cc5253e171e63d31119b21ce1a713ab0f9 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Sat, 6 Feb 2016 11:32:01 +0900 Subject: [PATCH 30/39] test(espower): fix callee --- test/espower_option_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/espower_option_test.js b/test/espower_option_test.js index 2e2b6ee..1324738 100644 --- a/test/espower_option_test.js +++ b/test/espower_option_test.js @@ -236,7 +236,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._rec1._expr(browser._rec1._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, { From c38cee27133be26abe916a4ced64e7e2cfd7aebb Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Mon, 8 Feb 2016 16:19:08 +0900 Subject: [PATCH 31/39] refactor(espower): automate recorder AST generation --- gulpfile.js | 13 ++++++++++++- lib/power-assert-recorder.json | 2 +- power-assert-recorder.js | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 power-assert-recorder.js diff --git a/gulpfile.js b/gulpfile.js index b391f41..e6747fd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,12 +7,15 @@ 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 dereserve = require('gulp-dereserve'); var derequire = require('gulp-derequire'); +var acorn = require('acorn'); +var espurify = require('espurify'); var config = { jshint: { src: './lib/**/*.js' @@ -175,7 +178,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/power-assert-recorder.json b/lib/power-assert-recorder.json index d432872..c6fae0b 100644 --- a/lib/power-assert-recorder.json +++ b/lib/power-assert-recorder.json @@ -300,4 +300,4 @@ "generator": false }, "arguments": [] -} +} \ No newline at end of file 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; +})(); From 9c495c1963c23cf0d5aa8f05d71e97feed0c8539 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 10 Feb 2016 17:04:02 +0900 Subject: [PATCH 32/39] test(espower): test with esprima too --- package.json | 1 + test/fixture_test.js | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1c5bf5c..940e7a3 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "blanket": "^1.1.7", "browserify": "^13.0.0", "del": "^2.0.2", + "esprima": "^2.7.2", "gulp": "^3.9.0", "gulp-derequire": "^2.1.0", "gulp-dereserve": "^0.2.1", diff --git a/test/fixture_test.js b/test/fixture_test.js index b8d3e9d..16efcfe 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,6 +30,19 @@ function testTransform (fixtureName, extraOptions) { }); } +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('Mocha'); testTransform('NonTarget'); From 90168b6c2b4b6168e5a3cfdf6d9980d370881030 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 10 Feb 2016 17:39:21 +0900 Subject: [PATCH 33/39] test(espower): add failing test for case without 'use strict' directive or assert variable declaration --- test/fixture_test.js | 3 ++ .../fixtures/WithoutRequireAssert/expected.js | 50 +++++++++++++++++++ test/fixtures/WithoutRequireAssert/fixture.js | 15 ++++++ test/fixtures/WithoutUseStrict/expected.js | 50 +++++++++++++++++++ test/fixtures/WithoutUseStrict/fixture.js | 15 ++++++ .../expected.js | 49 ++++++++++++++++++ .../fixture.js | 13 +++++ 7 files changed, 195 insertions(+) create mode 100644 test/fixtures/WithoutRequireAssert/expected.js create mode 100644 test/fixtures/WithoutRequireAssert/fixture.js create mode 100644 test/fixtures/WithoutUseStrict/expected.js create mode 100644 test/fixtures/WithoutUseStrict/fixture.js create mode 100644 test/fixtures/WithoutUseStrictNorRequireAssert/expected.js create mode 100644 test/fixtures/WithoutUseStrictNorRequireAssert/fixture.js diff --git a/test/fixture_test.js b/test/fixture_test.js index 16efcfe..cdc0498 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -44,6 +44,9 @@ function testTransform (fixtureName, extraOptions) { } describe('fixtures', function () { + testTransform('WithoutUseStrict'); + testTransform('WithoutRequireAssert'); + testTransform('WithoutUseStrictNorRequireAssert'); testTransform('Mocha'); testTransform('NonTarget'); testTransform('Literal'); 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'); + }); +}); From bc2d99c21c731b08718b38a0557719a1a6c4f50b Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 10 Feb 2016 17:44:05 +0900 Subject: [PATCH 34/39] fix(espower): insert declaration correctly if target body begins with ExpressionStatement but not 'use strict' directive --- lib/assertion-visitor.js | 12 ++++-------- package.json | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/assertion-visitor.js b/lib/assertion-visitor.js index 3a5d4a6..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'); @@ -346,10 +345,6 @@ function newNodeWithLocationCopyOf (original) { }; } -function astEqual (ast1, ast2) { - return deepEqual(espurify(ast1), espurify(ast2)); -} - function findEspathOfAncestorNode (targetNode, controller) { // iterate child to root var child, parent; @@ -377,12 +372,13 @@ function findEspathOfAncestorNode (targetNode, controller) { function insertAfterUseStrictDirective (decl, body) { var firstBody = body[0]; if (firstBody.type === syntax.ExpressionStatement) { - if (astEqual(firstBody.expression, { type: syntax.Literal, value: 'use strict' })) { + var expression = firstBody.expression; + if (expression.type === syntax.Literal && expression.value === 'use strict') { body.splice(1,0, decl); + return; } - } else { - body.unshift(decl); } + body.unshift(decl); } function isFunction (node) { diff --git a/package.json b/package.json index 940e7a3..21c6185 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ ], "dependencies": { "array-find": "^1.0.0", - "deep-equal": "^1.0.0", "escallmatch": "^1.4.2", "escodegen": "^1.7.0", "escope": "^3.3.0", From 5a55aa8fe8c120db07fd542fa318e2c952ec39dd Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 10 Feb 2016 18:17:11 +0900 Subject: [PATCH 35/39] test(espower): fix failing tests --- test/espower_option_test.js | 28 ++- test/fixtures/AwaitExpression/expected.js | 1 + test/fixtures/YieldExpression/expected.js | 1 + test/instrumentation_test.js | 221 +++++++++++----------- 4 files changed, 139 insertions(+), 112 deletions(-) diff --git a/test/espower_option_test.js b/test/espower_option_test.js index 1324738..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(_rec1._expr(_rec1._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(_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}));"); + 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(_rec1._expr(_rec1._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(_rec1._expr(_rec1._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(_rec1._expr(_rec1._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}));"); }); }); }); @@ -437,7 +452,8 @@ describe('sourceRoot option', function () { sourceRoot: config.espowerSourceRoot }); var instrumentedCode = escodegen.generate(espoweredAST, {format: {compact: true}}); - assert.equal(instrumentedCode, "assert(_rec1._expr(_rec1._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/fixtures/AwaitExpression/expected.js b/test/fixtures/AwaitExpression/expected.js index 15c6e16..7523641 100644 --- a/test/fixtures/AwaitExpression/expected.js +++ b/test/fixtures/AwaitExpression/expected.js @@ -22,6 +22,7 @@ var _PowerAssertRecorder1 = function () { 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', diff --git a/test/fixtures/YieldExpression/expected.js b/test/fixtures/YieldExpression/expected.js index 41a1d46..f98d25c 100644 --- a/test/fixtures/YieldExpression/expected.js +++ b/test/fixtures/YieldExpression/expected.js @@ -22,6 +22,7 @@ var _PowerAssertRecorder1 = function () { return PowerAssertRecorder; }(); function* gen(a) { + 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', diff --git a/test/instrumentation_test.js b/test/instrumentation_test.js index f35c2fb..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(_rec1._expr(_rec1._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(_rec1._expr(_rec1._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(_rec1._expr(_rec1._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(_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}));"); + 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(_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}));"); + 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(_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);"); + 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(_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}));"); + 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(_rec1._expr(_rec1._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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_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');"); + 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(_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}));"); + 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(_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}));"); + 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(_rec1._expr(_rec1._capt(!_rec1._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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_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:1}));"); + prelude(1) + "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:1}));"); inst("assert.ok(actual < 5 || 13 < actual);", - "assert.ok(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(actual,'arguments/0/left/left')<5,'arguments/0/left')||_rec1._capt(13<_rec1._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:1}));"); + prelude(1) + "assert.ok(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(actual,'arguments/0/left/left')<5,'arguments/0/left')||_rec1._capt(13<_rec1._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:1}));"); inst("assert(2 > actual && actual < 13);", - "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}));"); + 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(_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}));"); + 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(_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.equal(5 < actual && actual < 13, falsy)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(falsy,'arguments/1'),{content:'assert.equal(5 < actual && actual < 13, falsy)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.equal(_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.equal(5 < actual && actual < 13, falsy)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(falsy,'arguments/1'),{content:'assert.equal(5 < actual && actual < 13, falsy)',filepath:'path/to/some_test.js',line:1}));"); }); describe('MemberExpression', function () { inst("assert(foo.bar);", - "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:1}));"); + prelude(1) + "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:1}));"); inst("assert(foo.bar.baz);", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._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:1}));"); inst("assert(foo['bar']);", - "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:1}));"); + prelude(1) + "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:1}));"); inst("assert(foo[propName]);", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object')[_rec1._capt(propName,'arguments/0/property')],'arguments/0'),{content:'assert(foo[propName])',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object')[_rec1._capt(propName,'arguments/0/property')],'arguments/0'),{content:'assert(foo[propName])',filepath:'path/to/some_test.js',line:1}));"); inst("assert(foo [ propName ] );", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object')[_rec1._capt(propName,'arguments/0/property')],'arguments/0'),{content:'assert(foo[propName])',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object')[_rec1._capt(propName,'arguments/0/property')],'arguments/0'),{content:'assert(foo[propName])',filepath:'path/to/some_test.js',line:1}));"); inst("assert(foo[func(key)]);", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object')[_rec1._capt(func(_rec1._capt(key,'arguments/0/property/arguments/0')),'arguments/0/property')],'arguments/0'),{content:'assert(foo[func(key)])',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object')[_rec1._capt(func(_rec1._capt(key,'arguments/0/property/arguments/0')),'arguments/0/property')],'arguments/0'),{content:'assert(foo[func(key)])',filepath:'path/to/some_test.js',line:1}));"); inst("assert(foo[propName]['key'][keys()['name']]);", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(_rec1._capt(foo,'arguments/0/object/object/object')[_rec1._capt(propName,'arguments/0/object/object/property')],'arguments/0/object/object')['key'],'arguments/0/object')[_rec1._capt(_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(_rec1._capt(foo,'arguments/0/object/object/object')[_rec1._capt(propName,'arguments/0/object/object/property')],'arguments/0/object/object')['key'],'arguments/0/object')[_rec1._capt(_rec1._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:1}));"); inst("assert( foo [ propName ] [ 'key' ] [ keys ( ) [ 'name' ] ] );", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(_rec1._capt(foo,'arguments/0/object/object/object')[_rec1._capt(propName,'arguments/0/object/object/property')],'arguments/0/object/object')['key'],'arguments/0/object')[_rec1._capt(_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(_rec1._capt(foo,'arguments/0/object/object/object')[_rec1._capt(propName,'arguments/0/object/object/property')],'arguments/0/object/object')['key'],'arguments/0/object')[_rec1._capt(_rec1._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:1}));"); inst("assert.equal(ary1.length, ary2.length);", - "assert.equal(_rec1._expr(_rec1._capt(_rec1._capt(ary1,'arguments/0/object').length,'arguments/0'),{content:'assert.equal(ary1.length, ary2.length)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(_rec2._capt(ary2,'arguments/1/object').length,'arguments/1'),{content:'assert.equal(ary1.length, ary2.length)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.equal(_rec1._expr(_rec1._capt(_rec1._capt(ary1,'arguments/0/object').length,'arguments/0'),{content:'assert.equal(ary1.length, ary2.length)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(_rec2._capt(ary2,'arguments/1/object').length,'arguments/1'),{content:'assert.equal(ary1.length, ary2.length)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.deepEqual(foo.propName, foo[key]);", - "assert.deepEqual(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object').propName,'arguments/0'),{content:'assert.deepEqual(foo.propName, foo[key])',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(_rec2._capt(foo,'arguments/1/object')[_rec2._capt(key,'arguments/1/property')],'arguments/1'),{content:'assert.deepEqual(foo.propName, foo[key])',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.deepEqual(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/object').propName,'arguments/0'),{content:'assert.deepEqual(foo.propName, foo[key])',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(_rec2._capt(foo,'arguments/1/object')[_rec2._capt(key,'arguments/1/property')],'arguments/1'),{content:'assert.deepEqual(foo.propName, foo[key])',filepath:'path/to/some_test.js',line:1}));"); }); describe('CallExpression', function () { inst("assert(func());", - "assert(_rec1._expr(_rec1._capt(func(),'arguments/0'),{content:'assert(func())',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(func(),'arguments/0'),{content:'assert(func())',filepath:'path/to/some_test.js',line:1}));"); inst("assert(obj.age());", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(obj,'arguments/0/callee/object').age(),'arguments/0'),{content:'assert(obj.age())',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(obj,'arguments/0/callee/object').age(),'arguments/0'),{content:'assert(obj.age())',filepath:'path/to/some_test.js',line:1}));"); inst("assert(isFalsy(positiveInt));", - "assert(_rec1._expr(_rec1._capt(isFalsy(_rec1._capt(positiveInt,'arguments/0/arguments/0')),'arguments/0'),{content:'assert(isFalsy(positiveInt))',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(isFalsy(_rec1._capt(positiveInt,'arguments/0/arguments/0')),'arguments/0'),{content:'assert(isFalsy(positiveInt))',filepath:'path/to/some_test.js',line:1}));"); inst("assert(foo[propName]());", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/callee/object')[_rec1._capt(propName,'arguments/0/callee/property')](),'arguments/0'),{content:'assert(foo[propName]())',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/callee/object')[_rec1._capt(propName,'arguments/0/callee/property')](),'arguments/0'),{content:'assert(foo[propName]())',filepath:'path/to/some_test.js',line:1}));"); inst("assert(foo[hoge[fuga[piyo]]]());", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/callee/object')[_rec1._capt(_rec1._capt(hoge,'arguments/0/callee/property/object')[_rec1._capt(_rec1._capt(fuga,'arguments/0/callee/property/property/object')[_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(foo,'arguments/0/callee/object')[_rec1._capt(_rec1._capt(hoge,'arguments/0/callee/property/object')[_rec1._capt(_rec1._capt(fuga,'arguments/0/callee/property/property/object')[_rec1._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:1}));"); inst("assert(sum(one, two, three) === seven);", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(sum(_rec1._capt(one,'arguments/0/left/arguments/0'),_rec1._capt(two,'arguments/0/left/arguments/1'),_rec1._capt(three,'arguments/0/left/arguments/2')),'arguments/0/left')===_rec1._capt(seven,'arguments/0/right'),'arguments/0'),{content:'assert(sum(one, two, three) === seven)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(sum(_rec1._capt(one,'arguments/0/left/arguments/0'),_rec1._capt(two,'arguments/0/left/arguments/1'),_rec1._capt(three,'arguments/0/left/arguments/2')),'arguments/0/left')===_rec1._capt(seven,'arguments/0/right'),'arguments/0'),{content:'assert(sum(one, two, three) === seven)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(sum(sum(one, two), three) === sum(sum(two, three), seven));", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(sum(_rec1._capt(sum(_rec1._capt(one,'arguments/0/left/arguments/0/arguments/0'),_rec1._capt(two,'arguments/0/left/arguments/0/arguments/1')),'arguments/0/left/arguments/0'),_rec1._capt(three,'arguments/0/left/arguments/1')),'arguments/0/left')===_rec1._capt(sum(_rec1._capt(sum(_rec1._capt(two,'arguments/0/right/arguments/0/arguments/0'),_rec1._capt(three,'arguments/0/right/arguments/0/arguments/1')),'arguments/0/right/arguments/0'),_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(sum(_rec1._capt(sum(_rec1._capt(one,'arguments/0/left/arguments/0/arguments/0'),_rec1._capt(two,'arguments/0/left/arguments/0/arguments/1')),'arguments/0/left/arguments/0'),_rec1._capt(three,'arguments/0/left/arguments/1')),'arguments/0/left')===_rec1._capt(sum(_rec1._capt(sum(_rec1._capt(two,'arguments/0/right/arguments/0/arguments/0'),_rec1._capt(three,'arguments/0/right/arguments/0/arguments/1')),'arguments/0/right/arguments/0'),_rec1._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:1}));"); inst("assert(math.calc.sum(one, two, three) === seven);", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(_rec1._capt(math,'arguments/0/left/callee/object/object').calc,'arguments/0/left/callee/object').sum(_rec1._capt(one,'arguments/0/left/arguments/0'),_rec1._capt(two,'arguments/0/left/arguments/1'),_rec1._capt(three,'arguments/0/left/arguments/2')),'arguments/0/left')===_rec1._capt(seven,'arguments/0/right'),'arguments/0'),{content:'assert(math.calc.sum(one, two, three) === seven)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(_rec1._capt(math,'arguments/0/left/callee/object/object').calc,'arguments/0/left/callee/object').sum(_rec1._capt(one,'arguments/0/left/arguments/0'),_rec1._capt(two,'arguments/0/left/arguments/1'),_rec1._capt(three,'arguments/0/left/arguments/2')),'arguments/0/left')===_rec1._capt(seven,'arguments/0/right'),'arguments/0'),{content:'assert(math.calc.sum(one, two, three) === seven)',filepath:'path/to/some_test.js',line:1}));"); inst("assert((three * (seven * ten)) === three);", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(three,'arguments/0/left/left')*_rec1._capt(_rec1._capt(seven,'arguments/0/left/right/left')*_rec1._capt(ten,'arguments/0/left/right/right'),'arguments/0/left/right'),'arguments/0/left')===_rec1._capt(three,'arguments/0/right'),'arguments/0'),{content:'assert(three * (seven * ten) === three)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(_rec1._capt(three,'arguments/0/left/left')*_rec1._capt(_rec1._capt(seven,'arguments/0/left/right/left')*_rec1._capt(ten,'arguments/0/left/right/right'),'arguments/0/left/right'),'arguments/0/left')===_rec1._capt(three,'arguments/0/right'),'arguments/0'),{content:'assert(three * (seven * ten) === three)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(!concat(fuga, piyo));", - "assert(_rec1._expr(_rec1._capt(!_rec1._capt(concat(_rec1._capt(fuga,'arguments/0/argument/arguments/0'),_rec1._capt(piyo,'arguments/0/argument/arguments/1')),'arguments/0/argument'),'arguments/0'),{content:'assert(!concat(fuga, piyo))',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(!_rec1._capt(concat(_rec1._capt(fuga,'arguments/0/argument/arguments/0'),_rec1._capt(piyo,'arguments/0/argument/arguments/1')),'arguments/0/argument'),'arguments/0'),{content:'assert(!concat(fuga, piyo))',filepath:'path/to/some_test.js',line:1}));"); inst("assert.strictEqual((three * (seven * ten)), math.calc.sum(one, two, three));", - "assert.strictEqual(_rec1._expr(_rec1._capt(_rec1._capt(three,'arguments/0/left')*_rec1._capt(_rec1._capt(seven,'arguments/0/right/left')*_rec1._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:1}),_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(math,'arguments/1/callee/object/object').calc,'arguments/1/callee/object').sum(_rec2._capt(one,'arguments/1/arguments/0'),_rec2._capt(two,'arguments/1/arguments/1'),_rec2._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:1}));"); + prelude(2) + "assert.strictEqual(_rec1._expr(_rec1._capt(_rec1._capt(three,'arguments/0/left')*_rec1._capt(_rec1._capt(seven,'arguments/0/right/left')*_rec1._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:1}),_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(math,'arguments/1/callee/object/object').calc,'arguments/1/callee/object').sum(_rec2._capt(one,'arguments/1/arguments/0'),_rec2._capt(two,'arguments/1/arguments/1'),_rec2._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:1}));"); }); describe('AssignmentExpression', function () { inst("assert(counter += 1);", - "assert(_rec1._expr(_rec1._capt(counter+=1,'arguments/0'),{content:'assert(counter += 1)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(counter+=1,'arguments/0'),{content:'assert(counter += 1)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(dog.age += 1);", - "assert(_rec1._expr(_rec1._capt(dog.age+=1,'arguments/0'),{content:'assert(dog.age += 1)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(dog.age+=1,'arguments/0'),{content:'assert(dog.age += 1)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(dog.age += 1);", - "assert(_rec1._expr(_rec1._capt(dog.age+=1,'arguments/0'),{content:'assert(dog.age += 1)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(dog.age+=1,'arguments/0'),{content:'assert(dog.age += 1)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.strictEqual(dog.age += 1, three);", - "assert.strictEqual(_rec1._expr(_rec1._capt(dog.age+=1,'arguments/0'),{content:'assert.strictEqual(dog.age += 1, three)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(three,'arguments/1'),{content:'assert.strictEqual(dog.age += 1, three)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.strictEqual(_rec1._expr(_rec1._capt(dog.age+=1,'arguments/0'),{content:'assert.strictEqual(dog.age += 1, three)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(three,'arguments/1'),{content:'assert.strictEqual(dog.age += 1, three)',filepath:'path/to/some_test.js',line:1}));"); }); describe('ArrayExpression', function () { inst("assert([foo, bar]);", - "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:1}));"); + prelude(1) + "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:1}));"); inst("assert(typeof [[foo.bar, baz(moo)], + fourStr] === 'number');", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(typeof _rec1._capt([_rec1._capt([_rec1._capt(_rec1._capt(foo,'arguments/0/left/argument/elements/0/elements/0/object').bar,'arguments/0/left/argument/elements/0/elements/0'),_rec1._capt(baz(_rec1._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'),_rec1._capt(+_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(typeof _rec1._capt([_rec1._capt([_rec1._capt(_rec1._capt(foo,'arguments/0/left/argument/elements/0/elements/0/object').bar,'arguments/0/left/argument/elements/0/elements/0'),_rec1._capt(baz(_rec1._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'),_rec1._capt(+_rec1._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:1}));"); inst("assert.notDeepEqual([foo, bar], [hoge, fuga, piyo]);", - "assert.notDeepEqual(_rec1._expr(_rec1._capt([_rec1._capt(foo,'arguments/0/elements/0'),_rec1._capt(bar,'arguments/0/elements/1')],'arguments/0'),{content:'assert.notDeepEqual([foo,bar], [hoge,fuga,piyo])',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt([_rec2._capt(hoge,'arguments/1/elements/0'),_rec2._capt(fuga,'arguments/1/elements/1'),_rec2._capt(piyo,'arguments/1/elements/2')],'arguments/1'),{content:'assert.notDeepEqual([foo,bar], [hoge,fuga,piyo])',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.notDeepEqual(_rec1._expr(_rec1._capt([_rec1._capt(foo,'arguments/0/elements/0'),_rec1._capt(bar,'arguments/0/elements/1')],'arguments/0'),{content:'assert.notDeepEqual([foo,bar], [hoge,fuga,piyo])',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt([_rec2._capt(hoge,'arguments/1/elements/0'),_rec2._capt(fuga,'arguments/1/elements/1'),_rec2._capt(piyo,'arguments/1/elements/2')],'arguments/1'),{content:'assert.notDeepEqual([foo,bar], [hoge,fuga,piyo])',filepath:'path/to/some_test.js',line:1}));"); }); describe('UpdateExpression', function () { inst("assert(++foo);", - "assert(_rec1._expr(_rec1._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(bar--);", - "assert(_rec1._expr(_rec1._capt(bar--,'arguments/0'),{content:'assert(bar--)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(bar--,'arguments/0'),{content:'assert(bar--)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.strictEqual(++foo, bar--);", - "assert.strictEqual(_rec1._expr(_rec1._capt(++foo,'arguments/0'),{content:'assert.strictEqual(++foo, bar--)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(bar--,'arguments/1'),{content:'assert.strictEqual(++foo, bar--)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.strictEqual(_rec1._expr(_rec1._capt(++foo,'arguments/0'),{content:'assert.strictEqual(++foo, bar--)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(bar--,'arguments/1'),{content:'assert.strictEqual(++foo, bar--)',filepath:'path/to/some_test.js',line:1}));"); }); describe('ConditionalExpression', function () { inst("assert(foo ? bar : baz);", - "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:1}));"); + prelude(1) + "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:1}));"); inst("assert(falsy ? truthy : truthy ? anotherFalsy : truthy);", - "assert(_rec1._expr(_rec1._capt(falsy,'arguments/0/test')?_rec1._capt(truthy,'arguments/0/consequent'):_rec1._capt(truthy,'arguments/0/alternate/test')?_rec1._capt(anotherFalsy,'arguments/0/alternate/consequent'):_rec1._capt(truthy,'arguments/0/alternate/alternate'),{content:'assert(falsy ? truthy : truthy ? anotherFalsy : truthy)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(falsy,'arguments/0/test')?_rec1._capt(truthy,'arguments/0/consequent'):_rec1._capt(truthy,'arguments/0/alternate/test')?_rec1._capt(anotherFalsy,'arguments/0/alternate/consequent'):_rec1._capt(truthy,'arguments/0/alternate/alternate'),{content:'assert(falsy ? truthy : truthy ? anotherFalsy : truthy)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(foo() ? bar.baz : (typeof goo));", - "assert(_rec1._expr(_rec1._capt(foo(),'arguments/0/test')?_rec1._capt(_rec1._capt(bar,'arguments/0/consequent/object').baz,'arguments/0/consequent'):_rec1._capt(typeof goo,'arguments/0/alternate'),{content:'assert(foo() ? bar.baz : typeof goo)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(foo(),'arguments/0/test')?_rec1._capt(_rec1._capt(bar,'arguments/0/consequent/object').baz,'arguments/0/consequent'):_rec1._capt(typeof goo,'arguments/0/alternate'),{content:'assert(foo() ? bar.baz : typeof goo)',filepath:'path/to/some_test.js',line:1}));"); inst("assert.equal((foo ? bar : baz), (falsy ? truthy : truthy ? anotherFalsy : truthy));", - "assert.equal(_rec1._expr(_rec1._capt(foo,'arguments/0/test')?_rec1._capt(bar,'arguments/0/consequent'):_rec1._capt(baz,'arguments/0/alternate'),{content:'assert.equal(foo ? bar : baz, falsy ? truthy : truthy ? anotherFalsy : truthy)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(falsy,'arguments/1/test')?_rec2._capt(truthy,'arguments/1/consequent'):_rec2._capt(truthy,'arguments/1/alternate/test')?_rec2._capt(anotherFalsy,'arguments/1/alternate/consequent'):_rec2._capt(truthy,'arguments/1/alternate/alternate'),{content:'assert.equal(foo ? bar : baz, falsy ? truthy : truthy ? anotherFalsy : truthy)',filepath:'path/to/some_test.js',line:1}));"); + prelude(2) + "assert.equal(_rec1._expr(_rec1._capt(foo,'arguments/0/test')?_rec1._capt(bar,'arguments/0/consequent'):_rec1._capt(baz,'arguments/0/alternate'),{content:'assert.equal(foo ? bar : baz, falsy ? truthy : truthy ? anotherFalsy : truthy)',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt(falsy,'arguments/1/test')?_rec2._capt(truthy,'arguments/1/consequent'):_rec2._capt(truthy,'arguments/1/alternate/test')?_rec2._capt(anotherFalsy,'arguments/1/alternate/consequent'):_rec2._capt(truthy,'arguments/1/alternate/alternate'),{content:'assert.equal(foo ? bar : baz, falsy ? truthy : truthy ? anotherFalsy : truthy)',filepath:'path/to/some_test.js',line:1}));"); }); describe('Literal: regular expression will not be instrumented', function () { inst("assert(/^not/.exec(str));", - "assert(_rec1._expr(_rec1._capt(/^not/.exec(_rec1._capt(str,'arguments/0/arguments/0')),'arguments/0'),{content:'assert(/^not/.exec(str))',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(/^not/.exec(_rec1._capt(str,'arguments/0/arguments/0')),'arguments/0'),{content:'assert(/^not/.exec(str))',filepath:'path/to/some_test.js',line:1}));"); }); describe('ObjectExpression', function () { inst("assert({foo: bar, hoge: fuga});", - "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:1}));"); + prelude(1) + "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:1}));"); inst("assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));", - "assert(_rec1._expr(_rec1._capt(!_rec1._capt({foo:_rec1._capt(_rec1._capt(bar,'arguments/0/argument/properties/0/value/object').baz,'arguments/0/argument/properties/0/value'),name:_rec1._capt(nameOf(_rec1._capt({firstName:_rec1._capt(first,'arguments/0/argument/properties/1/value/arguments/0/properties/0/value'),lastName:_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(!_rec1._capt({foo:_rec1._capt(_rec1._capt(bar,'arguments/0/argument/properties/0/value/object').baz,'arguments/0/argument/properties/0/value'),name:_rec1._capt(nameOf(_rec1._capt({firstName:_rec1._capt(first,'arguments/0/argument/properties/1/value/arguments/0/properties/0/value'),lastName:_rec1._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:1}));"); inst("assert.deepEqual({foo: bar, hoge: fuga}, {hoge: fuga, foo: bar});", - "assert.deepEqual(_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.deepEqual({foo: bar,hoge: fuga}, {hoge: fuga,foo: bar})',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt({hoge:_rec2._capt(fuga,'arguments/1/properties/0/value'),foo:_rec2._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',line:1}));"); + prelude(2) + "assert.deepEqual(_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.deepEqual({foo: bar,hoge: fuga}, {hoge: fuga,foo: bar})',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._capt({hoge:_rec2._capt(fuga,'arguments/1/properties/0/value'),foo:_rec2._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',line:1}));"); }); describe('NewExpression', function () { inst("assert(new Date());", - "assert(_rec1._expr(_rec1._capt(new Date(),'arguments/0'),{content:'assert(new Date())',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(new Date(),'arguments/0'),{content:'assert(new Date())',filepath:'path/to/some_test.js',line:1}));"); inst("assert(new foo.bar.Baz());", - "assert(_rec1._expr(_rec1._capt(new(_rec1._capt(_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(new(_rec1._capt(_rec1._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:1}));"); inst("assert(!(new Array(foo, bar, baz)));", - "assert(_rec1._expr(_rec1._capt(!_rec1._capt(new Array(_rec1._capt(foo,'arguments/0/argument/arguments/0'),_rec1._capt(bar,'arguments/0/argument/arguments/1'),_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(!_rec1._capt(new Array(_rec1._capt(foo,'arguments/0/argument/arguments/0'),_rec1._capt(bar,'arguments/0/argument/arguments/1'),_rec1._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:1}));"); inst("assert.notEqual(new Date(), new Date('2013-01-12'));", - "assert.notEqual(_rec1._expr(_rec1._capt(new Date(),'arguments/0'),{content:'assert.notEqual(new Date(), new Date(\\'2013-01-12\\'))',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._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:1}));"); + prelude(2) + "assert.notEqual(_rec1._expr(_rec1._capt(new Date(),'arguments/0'),{content:'assert.notEqual(new Date(), new Date(\\'2013-01-12\\'))',filepath:'path/to/some_test.js',line:1}),_rec2._expr(_rec2._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:1}));"); }); @@ -326,16 +337,16 @@ describe('instrumentation spec', function () { inst("assert(function (a, b) { return a + b; });", "assert(function(a,b){return a+b;});"); inst("assert(baz === (function (a, b) { return a + b; })(foo, bar));", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(baz,'arguments/0/left')===_rec1._capt(function(a,b){return a+b;}(_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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(baz,'arguments/0/left')===_rec1._capt(function(a,b){return a+b;}(_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:1}));"); }); describe('Literal: multibyte string literal', function () { inst("assert(fuga !== 'ふが');", - "assert(_rec1._expr(_rec1._capt(_rec1._capt(fuga,'arguments/0/left')!=='ふが','arguments/0'),{content:'assert(fuga !== \\'ふが\\')',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(_rec1._capt(fuga,'arguments/0/left')!=='ふが','arguments/0'),{content:'assert(fuga !== \\'ふが\\')',filepath:'path/to/some_test.js',line:1}));"); inst("assert('ほげ' !== 'ふが');", - "assert(_rec1._expr(_rec1._capt('ほげ'!=='ふが','arguments/0'),{content:'assert(\\'ほげ\\' !== \\'ふが\\')',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt('ほげ'!=='ふが','arguments/0'),{content:'assert(\\'ほげ\\' !== \\'ふが\\')',filepath:'path/to/some_test.js',line:1}));"); }); @@ -343,20 +354,20 @@ describe('instrumentation spec', function () { describe('TemplateLiteral', function () { inst("assert(`Hello`);", - "assert(_rec1._expr(_rec1._capt(`Hello`,'arguments/0'),{content:'assert(`Hello`)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(`Hello`,'arguments/0'),{content:'assert(`Hello`)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(`Hello, ${nickname}`);", - "assert(_rec1._expr(_rec1._capt(`Hello, ${_rec1._capt(nickname,'arguments/0/expressions/0')}`,'arguments/0'),{content:'assert(`Hello, ${ nickname }`)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(`Hello, ${_rec1._capt(nickname,'arguments/0/expressions/0')}`,'arguments/0'),{content:'assert(`Hello, ${ nickname }`)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(`Hello, ${user.nickname}`);", - "assert(_rec1._expr(_rec1._capt(`Hello, ${_rec1._capt(_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(`Hello, ${_rec1._capt(_rec1._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:1}));"); }); describe('TaggedTemplateExpression', function () { inst("assert(fn`a${1}`);", - "assert(_rec1._expr(_rec1._capt(fn`a${1}`,'arguments/0'),{content:'assert(fn`a${ 1 }`)',filepath:'path/to/some_test.js',line:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(fn`a${1}`,'arguments/0'),{content:'assert(fn`a${ 1 }`)',filepath:'path/to/some_test.js',line:1}));"); inst("assert(fn`a${foo}b${bar}c${baz}`);", - "assert(_rec1._expr(_rec1._capt(fn`a${_rec1._capt(foo,'arguments/0/quasi/expressions/0')}b${_rec1._capt(bar,'arguments/0/quasi/expressions/1')}c${_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(fn`a${_rec1._capt(foo,'arguments/0/quasi/expressions/0')}b${_rec1._capt(bar,'arguments/0/quasi/expressions/1')}c${_rec1._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:1}));"); inst("assert(fn`driver ${bob.name}, navigator ${alice.getName()}`);", - "assert(_rec1._expr(_rec1._capt(fn`driver ${_rec1._capt(_rec1._capt(bob,'arguments/0/quasi/expressions/0/object').name,'arguments/0/quasi/expressions/0')}, navigator ${_rec1._capt(_rec1._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:1}));"); + prelude(1) + "assert(_rec1._expr(_rec1._capt(fn`driver ${_rec1._capt(_rec1._capt(bob,'arguments/0/quasi/expressions/0/object').name,'arguments/0/quasi/expressions/0')}, navigator ${_rec1._capt(_rec1._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:1}));"); }); describe('ArrowFunctionExpression: body will not be instrumented', function () { @@ -367,7 +378,7 @@ describe('instrumentation spec', function () { inst("assert(v => ({even: v, odd: v + 1}));", "assert(v=>({even:v,odd:v+1}));"); inst("assert(seven === ((v, i) => v + i)(four, five));", - "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}));"); + 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(_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}));"); + 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(_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}));"); + 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,78 +402,76 @@ describe('instrumentation spec', function () { describe('SpreadElement', function () { inst("assert(hello(...names));", - "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}));"); + 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(_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}));"); + 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(_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}));"); + 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}));"); }); - var prelude = "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('YieldExpression', function () { inst("function *gen() {assert((yield bigOrSmall(size)) === 'big')}", - prelude + "function*gen(){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}));}"); + 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('disambiguation: YieldExpression vs FunctionCall', function () { inst("function baz() {assert((yield (foo)) === bar)}", - prelude + "function baz(){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}));}"); + 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)}", - prelude + "function*baz(){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}));}"); + 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)}", - prelude + "var baz=function(){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}));};"); + 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)}", - prelude + "var baz=function*(){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}));};"); + 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')}", - prelude + "async function gen(){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}));}"); + 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('disambiguation: AwaitExpression vs FunctionCall', function () { inst("function baz() {assert((await (foo)) === bar)}", - prelude + "function baz(){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}));}"); + 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)}", - prelude + "async function baz(){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}));}"); + 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)}", - prelude + "var baz=function(){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}));};"); + 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)}", - prelude + "var baz=async function(){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}));};"); + 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)};", - prelude + "var baz=()=>{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}));};"); + 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)}", - prelude + "var baz=async()=>{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}));};"); + 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(_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}));"); + 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(_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}));"); + 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(_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}));"); + 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(_rec1._expr(_rec1._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(_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}));"); + 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}));"); }); }); }); From 5a94f4ee0c1db4d438ea0ce9f0c70ff4be8cedc8 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Thu, 11 Feb 2016 00:20:16 +0900 Subject: [PATCH 36/39] chore(package): update espower-location-detector to 0.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 21c6185..fdd79f5 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "escallmatch": "^1.4.2", "escodegen": "^1.7.0", "escope": "^3.3.0", - "espower-location-detector": "^0.1.1", + "espower-location-detector": "^0.1.2", "espurify": "^1.3.0", "estraverse": "^4.1.0", "is-url": "^1.2.1", From a7c27a509a40a61bb37767cededa40c8bf464356 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Sun, 8 May 2016 01:16:49 +0900 Subject: [PATCH 37/39] chore(package): pin down blanket version for now due to `_$jscoverage is not defined` Error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fdd79f5..7c2cd71 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "acorn": "^2.4.0", "acorn-es7-plugin": "^1.0.7", "amdefine": "^1.0.0", - "blanket": "^1.1.7", + "blanket": "1.1.9", "browserify": "^13.0.0", "del": "^2.0.2", "esprima": "^2.7.2", From 63b5177d710f15397a7c511548faeacf9c0647ec Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 22 Jun 2016 21:23:55 +0900 Subject: [PATCH 38/39] Merge branch 'master' into embedded-recorder --- CHANGELOG.md | 24 +++++++++++++++++ gulpfile.js | 3 +++ lib/rules/supported-node-types.js | 1 + package.json | 3 ++- test/fixture_test.js | 1 + test/fixtures/SequenceExpression/expected.js | 27 ++++++++++++++++++++ test/fixtures/SequenceExpression/fixture.js | 13 ++++++++++ 7 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/SequenceExpression/expected.js create mode 100644 test/fixtures/SequenceExpression/fixture.js 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 e6747fd..63e55e0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -12,6 +12,7 @@ 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'); @@ -149,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)) @@ -163,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); } 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 06ee077..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", @@ -52,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/test/fixture_test.js b/test/fixture_test.js index cdc0498..13924ae 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -63,6 +63,7 @@ describe('fixtures', function () { testTransform('ConditionalExpression'); testTransform('AssignmentExpression'); testTransform('UpdateExpression'); + testTransform('SequenceExpression'); testTransform('FunctionExpression'); testTransform('ArrowFunctionExpression'); testTransform('ClassExpression'); diff --git a/test/fixtures/SequenceExpression/expected.js b/test/fixtures/SequenceExpression/expected.js new file mode 100644 index 0000000..b16fdf9 --- /dev/null +++ b/test/fixtures/SequenceExpression/expected.js @@ -0,0 +1,27 @@ +'use strict'; +assert((2, 1, 0)); +assert(assert._expr(assert._capt((assert._capt(foo, 'arguments/0/left/expressions/0'), assert._capt(bar, 'arguments/0/left/expressions/1')) === assert._capt(baz, 'arguments/0/right'), 'arguments/0'), { + content: 'assert((foo, bar) === baz)', + filepath: 'path/to/some_test.js', + line: 5 +})); +assert(assert._expr(assert._capt(toto((assert._capt(tata, 'arguments/0/arguments/0/expressions/0'), assert._capt(titi, 'arguments/0/arguments/0/expressions/1'))), 'arguments/0'), { + content: 'assert(toto((tata, titi)))', + filepath: 'path/to/some_test.js', + line: 7 +})); +assert(assert._expr((assert._capt(foo, 'arguments/0/expressions/0'), (assert._capt(bar, 'arguments/0/expressions/1/expressions/0'), assert._capt(baz, 'arguments/0/expressions/1/expressions/1'))), { + content: 'assert((foo, (bar, baz)))', + filepath: 'path/to/some_test.js', + line: 9 +})); +assert(assert._expr((((((assert._capt(foo, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/0/expressions/0'), assert._capt(bar, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/0/expressions/1')), assert._capt(baz, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/1')), assert._capt(toto, 'arguments/0/expressions/0/expressions/0/expressions/1')), assert._capt(tata, 'arguments/0/expressions/0/expressions/1')), assert._capt(titi, 'arguments/0/expressions/1')), { + content: 'assert((((((foo, bar), baz), toto), tata), titi))', + filepath: 'path/to/some_test.js', + line: 11 +})); +assert(assert._expr((assert._capt(y = assert._capt(x, 'arguments/0/expressions/0/right'), 'arguments/0/expressions/0'), assert._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)); From 8b8935ae8e21fe6c2704e01666b3ad73c3a10505 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 22 Jun 2016 21:28:39 +0900 Subject: [PATCH 39/39] test(espower): maint expected output for SequenceExpression --- test/fixtures/SequenceExpression/expected.js | 38 +++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/test/fixtures/SequenceExpression/expected.js b/test/fixtures/SequenceExpression/expected.js index b16fdf9..19b97f0 100644 --- a/test/fixtures/SequenceExpression/expected.js +++ b/test/fixtures/SequenceExpression/expected.js @@ -1,26 +1,54 @@ '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(assert._expr(assert._capt((assert._capt(foo, 'arguments/0/left/expressions/0'), assert._capt(bar, 'arguments/0/left/expressions/1')) === assert._capt(baz, 'arguments/0/right'), 'arguments/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(assert._expr(assert._capt(toto((assert._capt(tata, 'arguments/0/arguments/0/expressions/0'), assert._capt(titi, 'arguments/0/arguments/0/expressions/1'))), 'arguments/0'), { +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(assert._expr((assert._capt(foo, 'arguments/0/expressions/0'), (assert._capt(bar, 'arguments/0/expressions/1/expressions/0'), assert._capt(baz, 'arguments/0/expressions/1/expressions/1'))), { +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(assert._expr((((((assert._capt(foo, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/0/expressions/0'), assert._capt(bar, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/0/expressions/1')), assert._capt(baz, 'arguments/0/expressions/0/expressions/0/expressions/0/expressions/1')), assert._capt(toto, 'arguments/0/expressions/0/expressions/0/expressions/1')), assert._capt(tata, 'arguments/0/expressions/0/expressions/1')), assert._capt(titi, 'arguments/0/expressions/1')), { +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(assert._expr((assert._capt(y = assert._capt(x, 'arguments/0/expressions/0/right'), 'arguments/0/expressions/0'), assert._capt(z, 'arguments/0/expressions/1')), { +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