Skip to content

Commit

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

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

describe('converting lastOptions()', () => {
it('single .lastOptions()', () => {
expectCodemodResult(
Expand Down Expand Up @@ -234,7 +244,6 @@ fetchMock.unmockGlobal();`,
});

// .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 @@ -115,4 +115,25 @@ fetchMock.unmockGlobal();
return builder.find(j.ExpressionStatement).get().value;
});
});

root
.find(j.CallExpression, {
callee: {
object: {
type: 'Identifier',
name: fetchMockVariableName,
},
property: {
name: 'lastCall',
},
},
})
.closest(j.ExpressionStatement)
.insertBefore(
j(
'throw new Error("lastCall() now returns a CallLog object instead of an array. Refer to the documentation")',
)
.find(j.ThrowStatement)
.get().value,
);
}
2 changes: 1 addition & 1 deletion packages/codemods/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ console.log(
codemod(
`
import fetchMock from 'fetch-mock';
fetchMock.resetBehavior();
fetchMock.lastCall();
`,
jscodeshift,
),
Expand Down

0 comments on commit 62fc48c

Please sign in to comment.