Skip to content

Commit

Permalink
Embedded AST is not required since espower 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
twada committed May 2, 2014
1 parent 3719829 commit c3a4586
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 87 deletions.
11 changes: 4 additions & 7 deletions lib/empower.js
Expand Up @@ -159,7 +159,7 @@
function _expr (value, args) {
var captured = events;
events = [];
return { powerAssertContext: {value: value, events: captured}, meta: {tree: args.tree, tokens: args.tokens}, source: {content: args.content, filepath: args.filepath} };
return { powerAssertContext: {value: value, events: captured}, source: {content: args.content, filepath: args.filepath, line: args.line} };
}

config.targetMethods.oneArg.forEach(function (methodName) {
Expand Down Expand Up @@ -197,8 +197,7 @@
};
context.args.push({
value: val1,
events: arg1.powerAssertContext.events,
meta: arg1.meta
events: arg1.powerAssertContext.events
});
return doPowerAssert(baseAssert, [val1], message, context);
};
Expand All @@ -219,8 +218,7 @@
};
context.args.push({
value: arg1.powerAssertContext.value,
events: arg1.powerAssertContext.events,
meta: arg1.meta
events: arg1.powerAssertContext.events
});
val1 = arg1.powerAssertContext.value;
} else {
Expand All @@ -236,8 +234,7 @@
}
context.args.push({
value: arg2.powerAssertContext.value,
events: arg2.powerAssertContext.events,
meta: arg2.meta
events: arg2.powerAssertContext.events
});
val2 = arg2.powerAssertContext.value;
} else {
Expand Down
20 changes: 10 additions & 10 deletions test/buster_assertions_test.js
Expand Up @@ -83,8 +83,8 @@
baseAssert.equal(e.name, 'AssertionError');
baseAssert.equal(e.message, [
'/path/to/some_test.js',
'assert(falsy);',
'[{"value":0,"espath":""}]'
'assert(falsy)',
'[{"value":0,"espath":"arguments/0"}]'
].join('\n'));
}
});
Expand All @@ -100,8 +100,8 @@
baseAssert.equal(e.name, 'AssertionError');
baseAssert.equal(e.message, [
'[assert.isNull] /path/to/some_test.js',
'assert.isNull(falsy);',
'[{"value":0,"espath":""}]: Expected 0 to be null'
'assert.isNull(falsy)',
'[{"value":0,"espath":"arguments/0"}]: Expected 0 to be null'
].join('\n'));
}
});
Expand All @@ -118,8 +118,8 @@
baseAssert.equal(e.name, 'AssertionError');
baseAssert.equal(e.message, [
'[assert.same] /path/to/some_test.js',
'assert.same(foo, bar);',
'[{"value":"foo","espath":""},{"value":"bar","espath":""}]: foo expected to be the same object as bar'
'assert.same(foo, bar)',
'[{"value":"foo","espath":"arguments/0"},{"value":"bar","espath":"arguments/1"}]: foo expected to be the same object as bar'
].join('\n'));
}
});
Expand All @@ -133,8 +133,8 @@
baseAssert.equal(e.name, 'AssertionError');
baseAssert.equal(e.message, [
'[assert.same] /path/to/some_test.js',
'assert.same("foo", bar);',
'[{"value":"bar","espath":""}]: foo expected to be the same object as bar'
'assert.same("foo", bar)',
'[{"value":"bar","espath":"arguments/1"}]: foo expected to be the same object as bar'
].join('\n'));
}
});
Expand All @@ -148,8 +148,8 @@
baseAssert.equal(e.name, 'AssertionError');
baseAssert.equal(e.message, [
'[assert.same] /path/to/some_test.js',
'assert.same(foo, "bar");',
'[{"value":"foo","espath":""}]: foo expected to be the same object as bar'
'assert.same(foo, "bar")',
'[{"value":"foo","espath":"arguments/0"}]: foo expected to be the same object as bar'
].join('\n'));
}
});
Expand Down
101 changes: 31 additions & 70 deletions test/empower_test.js
Expand Up @@ -68,35 +68,22 @@ test(JSON.stringify(option) + ' empowered function also acts like an assert func
if (option.modifyMessageOnFail) {
baseAssert.equal(e.message, [
'/path/to/some_test.js',
'assert(falsy);',
'[{"value":0,"espath":""}]'
'assert(falsy)',
'[{"value":0,"espath":"arguments/0"}]'
].join('\n'));
}
if (option.saveContextOnFail) {
baseAssert.deepEqual(e.powerAssertContext, {
"source":{
"content": "assert(falsy);",
"filepath": "/path/to/some_test.js"
"content": "assert(falsy)",
"filepath": "/path/to/some_test.js",
"line": 1
},
"args":[
{
"value": 0,
"meta": {
"tree": {
"type":"Identifier",
"name":"falsy",
"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":12}}
},
"tokens":[
{
"type":"Identifier",
"value":"falsy",
"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":12}}
}
]
},
"events": [
{"value":0,"espath":""}
{"value":0,"espath":"arguments/0"}
]
}
]
Expand All @@ -117,27 +104,22 @@ suite(JSON.stringify(option) + ' assertion method with one argument', function (
if (option.modifyMessageOnFail) {
baseAssert.equal(e.message, [
'/path/to/some_test.js',
'assert.ok(falsy);',
'[{"value":0,"espath":""}]'
'assert.ok(falsy)',
'[{"value":0,"espath":"arguments/0"}]'
].join('\n'));
}
if (option.saveContextOnFail) {
baseAssert.deepEqual(e.powerAssertContext, {
"source": {
"content":"assert.ok(falsy);",
"filepath":"/path/to/some_test.js"
"content":"assert.ok(falsy)",
"filepath":"/path/to/some_test.js",
"line": 1
},
"args":[
{
"value":0,
"meta":{
"tree":{"type":"Identifier","name":"falsy","loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":15}}},
"tokens":[
{"type":"Identifier","value":"falsy","loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":15}}}
]
},
"events":[
{"value":0,"espath":""}
{"value":0,"espath":"arguments/0"}
]
}
]
Expand All @@ -159,36 +141,25 @@ suite(JSON.stringify(option) + ' assertion method with two arguments', function
if (option.modifyMessageOnFail) {
baseAssert.equal(e.message, [
'/path/to/some_test.js',
'assert.equal(foo, bar);',
'[{"value":"foo","espath":""},{"value":"bar","espath":""}]'
'assert.equal(foo, bar)',
'[{"value":"foo","espath":"arguments/0"},{"value":"bar","espath":"arguments/1"}]'
].join('\n'));
}
if (option.saveContextOnFail) {
baseAssert.deepEqual(e.powerAssertContext, {
"source":{
"content":"assert.equal(foo, bar);",
"filepath":"/path/to/some_test.js"
"content":"assert.equal(foo, bar)",
"filepath":"/path/to/some_test.js",
"line": 1
},
"args":[
{
"value":"foo",
"meta":{
"tree":{"type":"Identifier","name":"foo","loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16}}},
"tokens":[
{"type":"Identifier","value":"foo","loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16}}}
]
},
"events":[{"value":"foo","espath":""}]
"events":[{"value":"foo","espath":"arguments/0"}]
},
{
"value":"bar",
"meta":{
"tree":{"type":"Identifier","name":"bar","loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":21}}},
"tokens":[
{"type":"Identifier","value":"bar","loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":21}}}
]
},
"events":[{"value":"bar","espath":""}]
"events":[{"value":"bar","espath":"arguments/1"}]
}
]
});
Expand All @@ -206,26 +177,21 @@ suite(JSON.stringify(option) + ' assertion method with two arguments', function
if (option.modifyMessageOnFail) {
baseAssert.equal(e.message, [
'/path/to/some_test.js',
'assert.equal("foo", bar);',
'[{"value":"bar","espath":""}]'
'assert.equal("foo", bar)',
'[{"value":"bar","espath":"arguments/1"}]'
].join('\n'));
}
if (option.saveContextOnFail) {
baseAssert.deepEqual(e.powerAssertContext, {
"source":{
"content":"assert.equal(\"foo\", bar);",
"filepath":"/path/to/some_test.js"
"content":"assert.equal(\"foo\", bar)",
"filepath":"/path/to/some_test.js",
"line": 1
},
"args": [
{
"value": "bar",
"meta": {
"tree": {"type":"Identifier","name":"bar","loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":23}}},
"tokens": [
{"type":"Identifier","value":"bar","loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":23}}}
]
},
"events": [{"value":"bar","espath":""}]
"events": [{"value":"bar","espath":"arguments/1"}]
}
]
});
Expand All @@ -243,26 +209,21 @@ suite(JSON.stringify(option) + ' assertion method with two arguments', function
if (option.modifyMessageOnFail) {
baseAssert.equal(e.message, [
'/path/to/some_test.js',
'assert.equal(foo, "bar");',
'[{"value":"foo","espath":""}]'
'assert.equal(foo, "bar")',
'[{"value":"foo","espath":"arguments/0"}]'
].join('\n'));
}
if (option.saveContextOnFail) {
baseAssert.deepEqual(e.powerAssertContext, {
"source":{
"content":"assert.equal(foo, \"bar\");",
"filepath":"/path/to/some_test.js"
"content":"assert.equal(foo, \"bar\")",
"filepath":"/path/to/some_test.js",
"line": 1
},
"args":[
{
"value":"foo",
"meta":{
"tree":{"type":"Identifier","name":"foo","loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16}}},
"tokens":[
{"type":"Identifier","value":"foo","loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16}}}
]
},
"events":[{"value":"foo","espath":""}]
"events":[{"value":"foo","espath":"arguments/0"}]
}
]
});
Expand Down

0 comments on commit c3a4586

Please sign in to comment.