avajs / ava-codemods Goto Github PK
View Code? Open in Web Editor NEWCodemods for AVA
Home Page: https://ava.li
License: MIT License
Codemods for AVA
Home Page: https://ava.li
License: MIT License
There exist a conversion from AVA to Jest, so would be nice to have the reverse too.
@skovhus Interested? Asking since you have some experience with the Jest API now.
Side question: I wonder if it would make more sense to have a separate project for each conversion? Not a big fan of bundling many binaries in one module.
I just tried using tape-to-ava and got this error on terminal.
➜ serializeJSON tape-to-ava serializeJSON.test.js -f
fatal: Not a git repository (or any of the parent directories): .git
WARNING: Unable to determine if git directory is clean. Forcibly continuing. Ensure you have a backup of your tests or commit the latest changes before continuing.
Executing command: jscodeshift -t /usr/local/lib/node_modules/ava-codemods/lib/tape.js serializeJSON.test.js
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
/usr/local/lib/node_modules/ava-codemods/lib/tape.js:115
export default function tapeToAva(fileInfo, api) {
^^^^^^
SyntaxError: Unexpected token export
at Object.exports.runInThisContext (vm.js:78:16)
at Module._compile (module.js:543:28)
at Module._extensions..js (module.js:580:10)
at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/ava-codemods/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at setup (/usr/local/lib/node_modules/ava-codemods/node_modules/jscodeshift/dist/Worker.js:67:18)
All done.
Results:
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 2.567seconds
I'm running on node 7.2.1.
It looks like #24 didn't add account for how the cli would be consumed by users doing npm install -g ava-codemods
.
That PR was commited to master a month after the last release, so the version in the npm registry is still ok. But, releasing a new version from master
would not work in it's current state.
How would you like me to address this @sindresorhus? Options being:
prepublish
to a dist
directory and ignore src files for publishbabel-register
when users run the CLI3 doesn't seem like the best idea for DX.
We need to have docs in place in time for the next AVA release so users can easily codemod their tests.
I want to reuse the command in many projects and don't want to go through the interactive interface each time.
We haven't maintained these codemods at all. This tool also tries to do a lot more than is necessary. For the latest throwsAsync
change I wrote a simple transform that can be applied by using jscodeshift
directly: https://gist.github.com/novemberborn/c2cdc94020083a1cafe3f41e8276f983
Perhaps we should instead host such transform files and explain how to use them, rather than trying to maintain a separate tool?
@sindresorhus what do you think?
From avajs/ava#644
@spudly has a start here: https://astexplorer.net/#/Uwl4f415pa
For completeness, here's a list of everything that I think would be needed for a complete mocha codemod:
- transform
it()
totest()
- add
t
parameter to aArrowFunctionExpression
passed totest()
- don't de-sync async functions (the codemod above will mess those up currently)
- add
t
parameter to aFunctionExpression
passed totest()
- transform
beforeEach()
totest.beforeEach()
- transform
afterEach()
totest.afterEach()
- transform
after()
totest.after()
- transform
before()
totest.before()
- remove
describe()
blocks, prepending their text to each test block's description- intelligently handle nested describe blocks if possible. how do we handle nested describe blocks with their own lifecycle hooks?
- if the test body
FunctionExpression
orArrowFunctionExpression
is async, it should usetest.serial
instead oftest
Also, it would be nice to have a separate codemod to transform chai assertions to ava assertions.
- Transform tests containing a callback (
it('foo', function (done) { ... })
) totest.cb(t => ... t.end();
Right now the CLI requires a clean git working directory. The only issue with that is, if you've just done npm i -D ava@latest
, your package.json
is modified, meaning you need to either commit the bump in package.json
first, or use the --force
flag every time.
IMO a --force
flag I'm deciding to use every time is kinda stupid. So I vote we make an exception for package.json
.
Automatically detect which test framework a user is currently using.
Scanning the require
statements should work for tap
and tape
.
Scanning for describe
/ it
, etc. Should work for mocha
.
We're gonna change the CWD in tests to the package root: avajs/ava#32
Should we have a codemod that ensures there's a {cwd: __dirname}
in childProcess
and not relative paths in fs
methods?
For codemods like same => deepEquals
, we should just examine the AVA config in package.json
to determine which files are test files, which are sources, etc.
We could do similar things for mocha
/tap
/etc by parsing their configs. (not sure we want to go down that road).
The jscodeshift CLI automatically loads babel/register
(it's still on babel@5
).
No reason we shouldn't be able to do the same for our tests, etc.
When using ava-codemods on:
test(t => {
t.same(fn.sync('1.tmp', {cwd: t.context.tmp}), [path.join(t.context.tmp, '1.tmp')]);
});
I get:
test(t => {
t.deepEqual(
fn.sync('1.tmp', {cwd: t.context.tmp}),
[path.join(t.context.tmp, '1.tmp')]
);
});
It should not change unrelated code.
And it doesn't even use the correct indentation. Source was tab indented, now it's 4 spaces.
We use jasmine extensively here at Redfin, and we're starting the long and tedious process of migrating to ava to simplify our babelification / es6, and to get our tests to run faster. It would significantly speed up our migration if we could use a codemod.
from avajs/ava#644
Follow-up to #28.
Commented by @skovhus:
My observations:
If you've tried it out and have some feedback. Comment below.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.