Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
chai-jscodeshift
Advanced tools
Readme
chai-jscodeshift provides a custom assertion for jscodeshift to check whether a given input fixture matches an output fixture after being transformed by the transformer under test.
import chai from 'chai';
import chaiJSCodeShift from 'chai-jscodeshift';
chai.use(chaiJSCodeShift());
import myTransform from '../src/my-transform';
describe('myTransform', () => {
it('transforms properly', () => {
expect(myTransform).to.transform('my-fixture');
// or
assert.transforms(myTransform, 'my-fixture');
});
});
By default, this plugin will look for fixtures in the fixtures in the working directory. You will probably want to customize this by setting the directory in which your fixtures appear:
import path from 'path';
chai.use(chaiJSCodeShift({
fixtureDirectory: path.join(__dirname, 'fixtures')
}));
When you declare that you want a transformer to transform a particular fixture, this plugin will look for a file named <fixtureName>.input.js
, relative to the fixtureDirectory
declared above. It will read this file, transform the contents using your transformer, and compare it against a file named <fixtureName>.output.js
relative to the fixture directory. You can customize either of these paths by passing a custom inputFixturePath
or outputFixturePath
in your options (both of which take two arguments, the fixture name and the root of the fixture directory):
chai.use(chaiJSCodeShift({
fixtureDirectory: path.join(__dirname, 'fixtures'),
inputFixturePath(fixtureName, fixtureDirectory) {
return path.join(fixtureDirectory, 'input', `${fixtureName}.js`);
},
inputFixturePath(fixtureName, fixtureDirectory) {
return path.join(fixtureDirectory, 'output', `${fixtureName}.js`);
},
}));
You can also set custom options that will be passed as the third argument to your transformer on every call using the transformOptions
configuration option:
chai.use(chaiJSCodeShift({
transformOptions: {
printOptions: {space: 'single'},
},
}));
FAQs
Chai assertion utilities for writing JSCodeShift Codemods.
The npm package chai-jscodeshift receives a total of 6 weekly downloads. As such, chai-jscodeshift popularity was classified as not popular.
We found that chai-jscodeshift demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.