Codemods to convert from custom-elements v0 to v1
npm install
Install jscodeshift
to run the
codemod scripts:
npm install -g jscodeshift
To run a single transform
jscodeshift -t ./src/[transform-name]/index.js path/to/files
To run all the transforms
jscodeshift -t ./src/index.js path/to/files
When working a new transform, it's suggested to use ASTExplorer
which offers the best development experience. Configure to use jscodeshift
as the transform.
Once you are happy with the result, you can transfer it over to this repo and follow the folder structure described below.
This repo comes with a testing setup to help with testing multiple scenarios using fixtures and Jest's snapshot testing.
Each transform should be placed in its own folder under ./src
and needs
to have the following folder structure:
#transform directory
./src/transform-name
| #the jscodeshift transform
| index.js
| #Jest's default test directory
| __tests__
| #the test entry
| transform-name-test.js
| #directory to place fixtures
| __fixtures__
| # fixture files are passed to your transform during testing
| # each one should cover one scenario
| scenario-one.fixture.js
| other-scenario.fixture.js
In the test entry, use ./util/defineSnapshotTests
to run the fixture tests
const defineSnapshotTests = require('../../../util/defineSnapshotTests');
describe('transform-name', function() {
//run fixture tests
defineSnapshotTests(__dirname);
//other tests
describe('other tests', function () {})
});
Each fixture file will be run against your transform twice in
To run the tests, simply run npm run test
or jest
Read Jest's documentation on snapshots