Skip to content

Commit

Permalink
feat: add an error to warn of calls() signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Sep 15, 2024
1 parent 62fc48c commit 5bf6f67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/codemods/src/__test__/method-codemods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,21 @@ fetchMock.unmockGlobal();`,
});
});

describe('converting lastCall()', () => {
it('single .lastUrl()', () => {
describe('warning about CallLog', () => {
it('lastCall()', () => {
expectCodemodResult(
'fetchMock.lastCall()',
`throw new Error("lastCall() now returns a CallLog object instead of an array. Refer to the documentation")
fetchMock.lastCall()`,
);
});
it('calls()', () => {
expectCodemodResult(
'fetchMock.calls()',
`throw new Error("calls() now returns an array of CallLog objects instead of an array of arrays. Refer to the documentation")
fetchMock.calls()`,
);
});
});

describe('converting lastOptions()', () => {
Expand Down Expand Up @@ -244,6 +251,4 @@ fetchMock.lastCall()`,
});

// .sandbox() => .fetchHandler(and maybe a comment about.createInstance())
// lastCall() => try to change uses of this to expect a callLog, but probably just insert a commemnt / error
// calls() => add error
});
21 changes: 21 additions & 0 deletions packages/codemods/src/codemods/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,25 @@ fetchMock.unmockGlobal();
.find(j.ThrowStatement)
.get().value,
);

root
.find(j.CallExpression, {
callee: {
object: {
type: 'Identifier',
name: fetchMockVariableName,
},
property: {
name: 'calls',
},
},
})
.closest(j.ExpressionStatement)
.insertBefore(
j(
'throw new Error("calls() now returns an array of CallLog objects instead of an array of arrays. Refer to the documentation")',
)
.find(j.ThrowStatement)
.get().value,
);
}

0 comments on commit 5bf6f67

Please sign in to comment.