Skip to content

Commit

Permalink
Updating sinon conversions to be more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
scalvert committed Jan 29, 2019
1 parent 3d0f924 commit 9482b78
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ test('foo test', async function (assert) {
sandbox.stub(Ember, 'onerror', () => {});
sandbox.stub(Ember, 'onerror', fn);

sandbox.stub(Ember, 'foo', function() {});
sandbox.stub(Ember, 'foo', () => {});
sandbox.stub(Ember, 'foo', fn);

this.sandbox.stub(Ember, 'onerror', function() {});
this.sandbox.stub(Ember, 'onerror', () => {});
this.sandbox.stub(Ember, 'onerror', fn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ test('foo test', async function (assert) {
setupOnerror(() => {});
setupOnerror(fn);

sandbox.stub(Ember, 'foo', function() {});
sandbox.stub(Ember, 'foo', () => {});
sandbox.stub(Ember, 'foo', fn);

setupOnerror(function() {});
setupOnerror(() => {});
setupOnerror(fn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ test('foo test', async function (assert) {
sinon.stub(Ember, 'onerror', () => {});
sinon.stub(Ember, 'onerror', fn);

sinon.stub(Ember, 'foo', function() {});
sinon.stub(Ember, 'foo', () => {});
sinon.stub(Ember, 'foo', fn);

this.sinon.stub(Ember, 'onerror', function() {});
this.sinon.stub(Ember, 'onerror', () => {});
this.sinon.stub(Ember, 'onerror', fn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ test('foo test', async function (assert) {
setupOnerror(() => {});
setupOnerror(fn);

sinon.stub(Ember, 'foo', function() {});
sinon.stub(Ember, 'foo', () => {});
sinon.stub(Ember, 'foo', fn);

setupOnerror(function() {});
setupOnerror(() => {});
setupOnerror(fn);
Expand Down
18 changes: 16 additions & 2 deletions transforms/remove-onerror-sinon-stubs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ module.exports = function transformer(file, api) {

const replacer = path => {
let node = path.node;
let onErrorArg = node.arguments.pop();
let emberArg = node.arguments[0];
let onerrorArg = node.arguments[1];
let onErrorFn = node.arguments[2];

return j.callExpression(j.identifier('setupOnerror'), [onErrorArg]);
if (emberArg.name !== 'Ember' || onerrorArg.value !== 'onerror') {
return node;
}

return j.callExpression(j.identifier('setupOnerror'), [onErrorFn]);
}

root.find(j.CallExpression, {
callee: {
type: 'MemberExpression',
property: {
type: 'Identifier',
name: 'stub'
}
},
arguments: {
length: 3
}
})
.replaceWith(replacer);


return root.toSource();
}

0 comments on commit 9482b78

Please sign in to comment.