Skip to content

Use async/await for tests #793

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

Merged
merged 4 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/initializers/set-global-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import RSVP from 'rsvp';

export function initialize() {
// async/await is using window.Promise by default and we want async/await to
// use RSVP instead which is properly integrated with Ember's runloop
window.Promise = RSVP.Promise;
}

export default { initialize };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"ember-data": "2.12.1",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-moment": "^7.3.1",
"ember-page-title": "3.1.5",
"ember-resolver": "3.0.0",
Expand Down
2 changes: 0 additions & 2 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module.exports = {
embertest: true
},
globals: {
'hasText': true,
'matchesText': true,
'server': true,
'wait': true,
},
Expand Down
15 changes: 6 additions & 9 deletions tests/acceptance/categories-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | categories');

test('listing categories', function(assert) {
visit('/categories');
test('listing categories', async function(assert) {
await visit('/categories');

andThen(function() {
hasText(assert, '.row:eq(0) .desc .info span', '0 crates');

hasText(assert, '.row:eq(1) .desc .info span', '1 crate');

hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
});
hasText(assert, '.row:eq(0) .desc .info span', '0 crates');
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
});
48 changes: 21 additions & 27 deletions tests/acceptance/crate-test.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import matchesText from 'cargo/tests/helpers/matches-text';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | crate page');

test('visiting a crate page from the front page', function(assert) {
visit('/');
click('#just-updated ul > li:first a');
test('visiting a crate page from the front page', async function(assert) {
await visit('/');
await click('#just-updated ul > li:first a');

andThen(function() {
assert.equal(currentURL(), '/crates/nanomsg');
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
});
assert.equal(currentURL(), '/crates/nanomsg');
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
});

test('visiting a crate page directly', function(assert) {
visit('/crates/nanomsg');
test('visiting a crate page directly', async function(assert) {
await visit('/crates/nanomsg');

andThen(function() {
assert.equal(currentURL(), '/crates/nanomsg');
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
});
assert.equal(currentURL(), '/crates/nanomsg');
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
});

test('navigating to the all versions page', function(assert) {
visit('/crates/nanomsg');
click('#crate-versions span.small a');
test('navigating to the all versions page', async function(assert) {
await visit('/crates/nanomsg');
await click('#crate-versions span.small a');

andThen(function() {
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
});
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
});

test('navigating to the reverse dependencies page', function(assert) {
visit('/crates/nanomsg');
click('a:contains("Dependent crates")');
test('navigating to the reverse dependencies page', async function(assert) {
await visit('/crates/nanomsg');
await click('a:contains("Dependent crates")');

andThen(function() {
assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');
assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');

const $revDep = findWithAssert('a[href="/crates/unicorn-rpc"]:first');
const $revDep = findWithAssert('a[href="/crates/unicorn-rpc"]:first');

hasText(assert, $revDep, 'unicorn-rpc');
});
hasText(assert, $revDep, 'unicorn-rpc');
});

test('navigating to a user page', function(assert) {
Expand Down
39 changes: 19 additions & 20 deletions tests/acceptance/front-page-test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | front page');

test('visiting /', function(assert) {
visit('/');
test('visiting /', async function(assert) {
await visit('/');

andThen(function() {
assert.equal(currentURL(), '/');
assert.equal(document.title, 'Cargo: packages for Rust');
assert.equal(currentURL(), '/');
assert.equal(document.title, 'Cargo: packages for Rust');

findWithAssert('a[href="/install"]');
findWithAssert('a[href="/crates"]');
findWithAssert('a[href="/login"]');
findWithAssert('a[href="/install"]');
findWithAssert('a[href="/crates"]');
findWithAssert('a[href="/login"]');

hasText(assert, '.downloads .num', '13,534,453');
hasText(assert, '.crates .num', '3,430');
hasText(assert, '.downloads .num', '13,534,453');
hasText(assert, '.crates .num', '3,430');

const $newCrate = findWithAssert('#new-crates ul > li:first a');
hasText(assert, $newCrate, 'mkstemp (0.2.0)');
assert.equal($newCrate.attr('href').trim(), '/crates/mkstemp');
const $newCrate = findWithAssert('#new-crates ul > li:first a');
hasText(assert, $newCrate, 'mkstemp (0.2.0)');
assert.equal($newCrate.attr('href').trim(), '/crates/mkstemp');

const $mostDownloaded = findWithAssert('#most-downloaded ul > li:first a');
hasText(assert, $mostDownloaded, 'libc (0.2.2)');
assert.equal($mostDownloaded.attr('href').trim(), '/crates/libc');
const $mostDownloaded = findWithAssert('#most-downloaded ul > li:first a');
hasText(assert, $mostDownloaded, 'libc (0.2.2)');
assert.equal($mostDownloaded.attr('href').trim(), '/crates/libc');

const $justUpdated = findWithAssert('#just-updated ul > li:first a');
hasText(assert, $justUpdated, 'nanomsg (0.4.2)');
assert.equal($justUpdated.attr('href').trim(), '/crates/nanomsg');
});
const $justUpdated = findWithAssert('#just-updated ul > li:first a');
hasText(assert, $justUpdated, 'nanomsg (0.4.2)');
assert.equal($justUpdated.attr('href').trim(), '/crates/nanomsg');
});
135 changes: 66 additions & 69 deletions tests/acceptance/search-test.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,63 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | search');

test('searching for "rust"', function(assert) {
visit('/');
fillIn('input.search', 'rust');
andThen(function() {
findWithAssert('form.search').submit();
});
wait();

andThen(function() {
assert.equal(currentURL(), '/search?q=rust');
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');

findWithAssert('a[href="/search?page=2&q=rust"]');
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);

hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
hasText(assert, '#results', 'Displaying 1-10 of 18 total results Sort by Relevance Relevance Downloads');

hasText(assert, '#crates .row:first .desc .info', 'rust_mixin');
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.1"]');

findWithAssert('#crates .row:first .desc .info .badge:first a[href="https://ci.appveyor.com/project/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:first a img[src="https://ci.appveyor.com/api/projects/status/github/huonw/external_mixin?svg=true&branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a[href="https://codecov.io/github/huonw/external_mixin?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a img[src="https://codecov.io/github/huonw/external_mixin/coverage.svg?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a[href="https://coveralls.io/github/huonw/external_mixin?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a img[src="https://coveralls.io/repos/github/huonw/external_mixin/badge.svg?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a[href="https://gitlab.com/huonw/external_mixin/pipelines"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a img[src="https://gitlab.com/huonw/external_mixin/badges/master/build.svg"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a img[src="https://isitmaintained.com/badge/resolution/huonw/external_mixin.svg"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a img[src="https://isitmaintained.com/badge/open/huonw/external_mixin.svg"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a[href="https://travis-ci.org/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a img[src="https://travis-ci.org/huonw/external_mixin.svg?branch=master"]');

hasText(assert, '#crates .row:first .desc .summary', 'Yo dawg, use Rust to generate Rust, right in your Rust. (See `external_mixin` to use scripting languages.)');
hasText(assert, '#crates .row:first .downloads', '477');
});
click('a[href="/search?page=2&q=rust"]');

andThen(function() {
assert.equal(currentURL(), '/search?page=2&q=rust');
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');

findWithAssert('a[href="/search?q=rust"]');
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);

hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
hasText(assert, '#results', 'Displaying 11-18 of 18 total results Sort by Relevance Relevance Downloads');

hasText(assert, '#crates .row:first .desc .info', 'rusted_cypher');
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.7.1"]');
});
test('searching for "rust"', async function(assert) {
await visit('/');
await fillIn('input.search', 'rust');

findWithAssert('form.search').submit();

await wait();

assert.equal(currentURL(), '/search?q=rust');
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');

findWithAssert('a[href="/search?page=2&q=rust"]');
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);

hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
hasText(assert, '#results', 'Displaying 1-10 of 18 total results Sort by Relevance Relevance Downloads');

hasText(assert, '#crates .row:first .desc .info', 'rust_mixin');
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.1"]');

findWithAssert('#crates .row:first .desc .info .badge:first a[href="https://ci.appveyor.com/project/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:first a img[src="https://ci.appveyor.com/api/projects/status/github/huonw/external_mixin?svg=true&branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a[href="https://codecov.io/github/huonw/external_mixin?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a img[src="https://codecov.io/github/huonw/external_mixin/coverage.svg?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a[href="https://coveralls.io/github/huonw/external_mixin?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a img[src="https://coveralls.io/repos/github/huonw/external_mixin/badge.svg?branch=master"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a[href="https://gitlab.com/huonw/external_mixin/pipelines"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a img[src="https://gitlab.com/huonw/external_mixin/badges/master/build.svg"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a img[src="https://isitmaintained.com/badge/resolution/huonw/external_mixin.svg"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a img[src="https://isitmaintained.com/badge/open/huonw/external_mixin.svg"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a[href="https://travis-ci.org/huonw/external_mixin"]');
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a img[src="https://travis-ci.org/huonw/external_mixin.svg?branch=master"]');

hasText(assert, '#crates .row:first .desc .summary', 'Yo dawg, use Rust to generate Rust, right in your Rust. (See `external_mixin` to use scripting languages.)');
hasText(assert, '#crates .row:first .downloads', '477');

await click('a[href="/search?page=2&q=rust"]');

assert.equal(currentURL(), '/search?page=2&q=rust');
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');

findWithAssert('a[href="/search?q=rust"]');
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);

hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
hasText(assert, '#results', 'Displaying 11-18 of 18 total results Sort by Relevance Relevance Downloads');

hasText(assert, '#crates .row:first .desc .info', 'rusted_cypher');
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.7.1"]');
});

test('pressing S key to focus the search bar', function(assert) {
test('pressing S key to focus the search bar', async function(assert) {
const KEYCODE_S = 83;
const KEYCODE_A = 65;

Expand All @@ -69,20 +67,19 @@ test('pressing S key to focus the search bar', function(assert) {
$searchBar.blur();
}

visit('/');
andThen(function() {
findWithAssert('#cargo-desktop-search').blur();
});
await visit('/');

keyEvent(document, 'keypress', KEYCODE_A);
andThen(function assertSearchBarIsNotFocused() {
const $searchBar = find('#cargo-desktop-search');
assert.notEqual($searchBar[0], document.activeElement);
$searchBar.blur();
});
findWithAssert('#cargo-desktop-search').blur();

await keyEvent(document, 'keypress', KEYCODE_A);

const $searchBar = find('#cargo-desktop-search');
assert.notEqual($searchBar[0], document.activeElement);
$searchBar.blur();

await keyEvent(document, 'keypress', KEYCODE_S);
assertSearchBarIsFocused();

keyEvent(document, 'keypress', KEYCODE_S);
andThen(assertSearchBarIsFocused);
keyEvent(document, 'keydown', KEYCODE_S);
andThen(assertSearchBarIsFocused);
await keyEvent(document, 'keydown', KEYCODE_S);
assertSearchBarIsFocused();
});
42 changes: 17 additions & 25 deletions tests/acceptance/team-page-test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | team page');

test('has team organization display', function(assert) {
visit('/teams/github:org:thehydroimpulse');
test('has team organization display', async function(assert) {
await visit('/teams/github:org:thehydroimpulse');

andThen(function() {
hasText(assert, '.team-info h1', 'org_test');
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
});
hasText(assert, '.team-info h1', 'org_test');
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
});

test('has link to github in team header', function(assert) {
visit('/teams/github:org:thehydroimpulse');

andThen(function() {
const $githubLink = findWithAssert('.info a');
assert.equal($githubLink.attr('href').trim(), 'https://github.com/org_test');
});
test('has link to github in team header', async function(assert) {
await visit('/teams/github:org:thehydroimpulse');

const $githubLink = findWithAssert('.info a');
assert.equal($githubLink.attr('href').trim(), 'https://github.com/org_test');
});

test('github link has image in team header', function(assert) {
visit('/teams/github:org:thehydroimpulse');
test('github link has image in team header', async function(assert) {
await visit('/teams/github:org:thehydroimpulse');

andThen(function() {
const $githubImg = findWithAssert('.info a img');
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
});
const $githubImg = findWithAssert('.info a img');
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
});

test('team organization details has github profile icon', function(assert) {
visit('/teams/github:org:thehydroimpulse');
test('team organization details has github profile icon', async function(assert) {
await visit('/teams/github:org:thehydroimpulse');

andThen(function() {
const $githubProfileImg = findWithAssert('.info img');
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
});
const $githubProfileImg = findWithAssert('.info img');
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
});
Loading