Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add qunit/mocha tests conversion to async/await #112

Merged
merged 4 commits into from
Jun 27, 2017

Conversation

dwickern
Copy link
Contributor

Converts from the andThen style acceptance tests...

it('can visit subroutes', function(done) {
  visit('/');

  andThen(function() {
    expect(find('h2').text()).to.be.empty;
  });

  visit('/foo');

  andThen(function() {
    expect(find('h2').text()).to.be.equal('this is an acceptance test');
    done();
  });
});

... into cleaner async/await style:

it('can visit subroutes', async function() {
  await visit('/');

  expect(find('h2').text()).to.be.empty;

  await visit('/foo');

  expect(find('h2').text()).to.be.equal('this is an acceptance test');
});

I only implemented mocha since that's what I use, but qunit could be added (ember-power-select has some example qunit tests using async/await style).

It doesn't handle custom async test helpers which need to be awaited. Maybe there could be a config option to list the names of additional async helpers.

It doesn't handle naming/scoping conflicts when merging andThen blocks. Babel will catch them if the code is invalid (e.g. reassign to const), otherwise the linter will catch them. For example:

andThen(function() {
  let foo = 1;
});
andThen(function() {
  let foo = 2;
});

// will become:
let foo = 1;
let foo = 2;

\

@knownasilya
Copy link
Collaborator

I updated Travis and rebased this branch. Just waiting on Travis to finish its thing.

Would be nice to have this for QUnit, since that's probably more widely used since it's the default. Otherwise, this looks A+

@knownasilya
Copy link
Collaborator

@dwickern could you update the README.md with your command. Just follow how the other commands are documented. Once that's done, I'll be happy to merge. Thanks again!

@knownasilya knownasilya self-assigned this Jun 27, 2017
@dwickern
Copy link
Contributor Author

I updated the readme. It was easy to add qunit support too, although I haven't run it against an actual qunit project

@knownasilya
Copy link
Collaborator

Beautiful!

@knownasilya knownasilya merged commit 7d96ddd into abuiles:master Jun 27, 2017
@dwickern dwickern changed the title Add mocha tests conversion to async/await Add qunit/mocha tests conversion to async/await Jun 27, 2017
knownasilya pushed a commit that referenced this pull request Jun 27, 2017
- fix remove-k codemod path for windows users (see #111)
- add  mocha/qunit async/await command (see #112, thanks to @dwickern!)
@knownasilya
Copy link
Collaborator

Published as v0.9.0

@dwickern dwickern deleted the mocha-async branch November 3, 2017 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants