GithubHelp home page GithubHelp logo

ava-codemods's People

Contributors

dawsbot avatar doug-wade avatar drewml avatar forresst avatar jamestalmage avatar jfmengels avatar novemberborn avatar platy11 avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ava-codemods's Issues

Conversion for Mocha

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() to test()
  • add t parameter to a ArrowFunctionExpression passed to test()
  • don't de-sync async functions (the codemod above will mess those up currently)
  • add t parameter to a FunctionExpression passed to test()
  • transform beforeEach() to test.beforeEach()
  • transform afterEach() to test.afterEach()
  • transform after() to test.after()
  • transform before() to test.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 or ArrowFunctionExpression is async, it should use test.serial instead of test

Also, it would be nice to have a separate codemod to transform chai assertions to ava assertions.

@spudly - avajs/ava#644 (comment)

  • Transform tests containing a callback ( it('foo', function (done) { ... }) ) to test.cb(t => ... t.end();

@jfmengels - avajs/ava#644 (comment)

Conversion from Jasmine

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.

Current master branch won't work if released

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:

  1. Revert changes to use ES6
  2. Compile in prepublish to a dist directory and ignore src files for publish
  3. Run babel-register when users run the CLI

3 doesn't seem like the best idea for DX.

Improvements to Tape→AVA conversion

Follow-up to #28.

Commented by @skovhus:

  • if t.end is in the scope of the test function, we could remove it and not use cb style
  • rename first param in test callback function, if it is not t (and replace usage of identifier in block). Note: currently we just fail with a nice error message instead.

My observations:

  • Would be nice to convert some of the syntax to ES2015 too. Might be able to use an existing transform for that.

If you've tried it out and have some feedback. Comment below.

Automatic file detection

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).

ES6ify the code.

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.

Conversion from Jest

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.

Allow `package.json` to be dirty

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.

tape-to-ava - SyntaxError: Unexpected token export

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.

Docs

We need to have docs in place in time for the next AVA release so users can easily codemod their tests.

Automatic detection of existing test framework.

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.

Should not change code style

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.

Codemods for AVA cwd change

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.