sinon-codemod
sinon-codemod copied to clipboard
Codemod scripts that update Sinon APIs
trafficstars
sinon-codemod
This repository contains a collection of codemod scripts based for use with JSCodeshift that help update Sinon APIs.
Setup & Run
npm install -g jscodeshiftgit clone https://github.com/hurrymaplelad/sinon-codemod.gitor download a zip file fromhttps://github.com/hurrymaplelad/sinon-codemod/archive/master.zip- Run
npm installin the sinon-codemod directory- Alternatively, run
yarnto install in the sinon-codemod directory for a reliable dependency resolution
- Alternatively, run
jscodeshift -t <codemod-script> <path>- Use the
-doption for a dry-run and use-pto print the output for comparison
Included Scripts
extract-calls-fake
Converts 3-argument calls to sinon.stub(x,y,z) into sinon.stub(x,y).callsFake(z).
jscodeshift -t sinon-codemod/extract-calls-fake.js <path>
migrate-to-v5
Removes sandbox variable declaration
Removes sinon.sandbox.create();
Replaces sandbox.restore() with sinon.restore()
Replaces sandbox.stub() with sinon.stub()
Replaces sandbox.spy() with sinon.spy()
Replaces sandbox.mock() with sinon.mock()
jscodeshift -t sinon-codemod/migrate-to-v5.js <path>