Skip to content

Commit

Permalink
feat: codemod reset()
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Sep 15, 2024
1 parent 5f1203e commit a96f62b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/codemods/src/codemods/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ export function simpleMethods(fetchMockVariableName, root, j) {
});
});

root
.find(j.CallExpression, {
callee: {
object: {
type: 'Identifier',
name: fetchMockVariableName,
},
property: {
name: 'reset',
},
},
})
.forEach((path) => {
const newExpressions = j(`
fetchMock.clearHistory();
fetchMock.removeRoutes({
includeFallback: true,
});
fetchMock.unmockGlobal();
`)
.find(j.ExpressionStatement)
.paths();
const insertLocation = j(path)
.closest(j.ExpressionStatement)
.replaceWith(newExpressions.shift().value);
while (newExpressions.length) {
insertLocation.insertAfter(newExpressions.pop().value);
}
});

[
['lastUrl', 'url'],
['lastOptions', 'options'],
Expand Down
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.resetHistory()
fetchMock.reset();
`,
jscodeshift,
),
Expand Down

0 comments on commit a96f62b

Please sign in to comment.