Skip to content

Commit 5194d62

Browse files
authored
Merge pull request #793 from Turbo87/tests
Use async/await for tests
2 parents dff16c7 + 85bc7c4 commit 5194d62

File tree

12 files changed

+173
-184
lines changed

12 files changed

+173
-184
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import RSVP from 'rsvp';
2+
3+
export function initialize() {
4+
// async/await is using window.Promise by default and we want async/await to
5+
// use RSVP instead which is properly integrated with Ember's runloop
6+
window.Promise = RSVP.Promise;
7+
}
8+
9+
export default { initialize };

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"ember-data": "2.12.1",
5050
"ember-export-application-global": "^2.0.0",
5151
"ember-load-initializers": "^1.0.0",
52+
"ember-maybe-import-regenerator": "^0.1.6",
5253
"ember-moment": "^7.3.1",
5354
"ember-page-title": "3.1.5",
5455
"ember-resolver": "3.0.0",

tests/.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module.exports = {
33
embertest: true
44
},
55
globals: {
6-
'hasText': true,
7-
'matchesText': true,
86
'server': true,
97
'wait': true,
108
},

tests/acceptance/categories-test.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3+
import hasText from 'cargo/tests/helpers/has-text';
34

45
moduleForAcceptance('Acceptance | categories');
56

6-
test('listing categories', function(assert) {
7-
visit('/categories');
7+
test('listing categories', async function(assert) {
8+
await visit('/categories');
89

9-
andThen(function() {
10-
hasText(assert, '.row:eq(0) .desc .info span', '0 crates');
11-
12-
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
13-
14-
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
15-
});
10+
hasText(assert, '.row:eq(0) .desc .info span', '0 crates');
11+
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
12+
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
1613
});

tests/acceptance/crate-test.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3+
import matchesText from 'cargo/tests/helpers/matches-text';
4+
import hasText from 'cargo/tests/helpers/has-text';
35

46
moduleForAcceptance('Acceptance | crate page');
57

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

10-
andThen(function() {
11-
assert.equal(currentURL(), '/crates/nanomsg');
12-
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
13-
});
12+
assert.equal(currentURL(), '/crates/nanomsg');
13+
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
1414
});
1515

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

19-
andThen(function() {
20-
assert.equal(currentURL(), '/crates/nanomsg');
21-
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
22-
});
19+
assert.equal(currentURL(), '/crates/nanomsg');
20+
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
2321
});
2422

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

29-
andThen(function() {
30-
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
31-
});
27+
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
3228
});
3329

34-
test('navigating to the reverse dependencies page', function(assert) {
35-
visit('/crates/nanomsg');
36-
click('a:contains("Dependent crates")');
30+
test('navigating to the reverse dependencies page', async function(assert) {
31+
await visit('/crates/nanomsg');
32+
await click('a:contains("Dependent crates")');
3733

38-
andThen(function() {
39-
assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');
34+
assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');
4035

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

43-
hasText(assert, $revDep, 'unicorn-rpc');
44-
});
38+
hasText(assert, $revDep, 'unicorn-rpc');
4539
});
4640

4741
test('navigating to a user page', function(assert) {

tests/acceptance/front-page-test.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3+
import hasText from 'cargo/tests/helpers/has-text';
34

45
moduleForAcceptance('Acceptance | front page');
56

6-
test('visiting /', function(assert) {
7-
visit('/');
7+
test('visiting /', async function(assert) {
8+
await visit('/');
89

9-
andThen(function() {
10-
assert.equal(currentURL(), '/');
11-
assert.equal(document.title, 'Cargo: packages for Rust');
10+
assert.equal(currentURL(), '/');
11+
assert.equal(document.title, 'Cargo: packages for Rust');
1212

13-
findWithAssert('a[href="/install"]');
14-
findWithAssert('a[href="/crates"]');
15-
findWithAssert('a[href="/login"]');
13+
findWithAssert('a[href="/install"]');
14+
findWithAssert('a[href="/crates"]');
15+
findWithAssert('a[href="/login"]');
1616

17-
hasText(assert, '.downloads .num', '13,534,453');
18-
hasText(assert, '.crates .num', '3,430');
17+
hasText(assert, '.downloads .num', '13,534,453');
18+
hasText(assert, '.crates .num', '3,430');
1919

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

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

28-
const $justUpdated = findWithAssert('#just-updated ul > li:first a');
29-
hasText(assert, $justUpdated, 'nanomsg (0.4.2)');
30-
assert.equal($justUpdated.attr('href').trim(), '/crates/nanomsg');
31-
});
28+
const $justUpdated = findWithAssert('#just-updated ul > li:first a');
29+
hasText(assert, $justUpdated, 'nanomsg (0.4.2)');
30+
assert.equal($justUpdated.attr('href').trim(), '/crates/nanomsg');
3231
});

tests/acceptance/search-test.js

Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,63 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3+
import hasText from 'cargo/tests/helpers/has-text';
34

45
moduleForAcceptance('Acceptance | search');
56

6-
test('searching for "rust"', function(assert) {
7-
visit('/');
8-
fillIn('input.search', 'rust');
9-
andThen(function() {
10-
findWithAssert('form.search').submit();
11-
});
12-
wait();
13-
14-
andThen(function() {
15-
assert.equal(currentURL(), '/search?q=rust');
16-
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
17-
18-
findWithAssert('a[href="/search?page=2&q=rust"]');
19-
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
20-
21-
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
22-
hasText(assert, '#results', 'Displaying 1-10 of 18 total results Sort by Relevance Relevance Downloads');
23-
24-
hasText(assert, '#crates .row:first .desc .info', 'rust_mixin');
25-
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.1"]');
26-
27-
findWithAssert('#crates .row:first .desc .info .badge:first a[href="https://ci.appveyor.com/project/huonw/external_mixin"]');
28-
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"]');
29-
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a[href="https://codecov.io/github/huonw/external_mixin?branch=master"]');
30-
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a img[src="https://codecov.io/github/huonw/external_mixin/coverage.svg?branch=master"]');
31-
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a[href="https://coveralls.io/github/huonw/external_mixin?branch=master"]');
32-
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a img[src="https://coveralls.io/repos/github/huonw/external_mixin/badge.svg?branch=master"]');
33-
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a[href="https://gitlab.com/huonw/external_mixin/pipelines"]');
34-
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a img[src="https://gitlab.com/huonw/external_mixin/badges/master/build.svg"]');
35-
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
36-
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a img[src="https://isitmaintained.com/badge/resolution/huonw/external_mixin.svg"]');
37-
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
38-
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a img[src="https://isitmaintained.com/badge/open/huonw/external_mixin.svg"]');
39-
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a[href="https://travis-ci.org/huonw/external_mixin"]');
40-
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a img[src="https://travis-ci.org/huonw/external_mixin.svg?branch=master"]');
41-
42-
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.)');
43-
hasText(assert, '#crates .row:first .downloads', '477');
44-
});
45-
click('a[href="/search?page=2&q=rust"]');
46-
47-
andThen(function() {
48-
assert.equal(currentURL(), '/search?page=2&q=rust');
49-
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
50-
51-
findWithAssert('a[href="/search?q=rust"]');
52-
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
53-
54-
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
55-
hasText(assert, '#results', 'Displaying 11-18 of 18 total results Sort by Relevance Relevance Downloads');
56-
57-
hasText(assert, '#crates .row:first .desc .info', 'rusted_cypher');
58-
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.7.1"]');
59-
});
7+
test('searching for "rust"', async function(assert) {
8+
await visit('/');
9+
await fillIn('input.search', 'rust');
10+
11+
findWithAssert('form.search').submit();
12+
13+
await wait();
14+
15+
assert.equal(currentURL(), '/search?q=rust');
16+
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
17+
18+
findWithAssert('a[href="/search?page=2&q=rust"]');
19+
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
20+
21+
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
22+
hasText(assert, '#results', 'Displaying 1-10 of 18 total results Sort by Relevance Relevance Downloads');
23+
24+
hasText(assert, '#crates .row:first .desc .info', 'rust_mixin');
25+
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.1"]');
26+
27+
findWithAssert('#crates .row:first .desc .info .badge:first a[href="https://ci.appveyor.com/project/huonw/external_mixin"]');
28+
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"]');
29+
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a[href="https://codecov.io/github/huonw/external_mixin?branch=master"]');
30+
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a img[src="https://codecov.io/github/huonw/external_mixin/coverage.svg?branch=master"]');
31+
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a[href="https://coveralls.io/github/huonw/external_mixin?branch=master"]');
32+
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a img[src="https://coveralls.io/repos/github/huonw/external_mixin/badge.svg?branch=master"]');
33+
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a[href="https://gitlab.com/huonw/external_mixin/pipelines"]');
34+
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a img[src="https://gitlab.com/huonw/external_mixin/badges/master/build.svg"]');
35+
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
36+
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a img[src="https://isitmaintained.com/badge/resolution/huonw/external_mixin.svg"]');
37+
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
38+
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a img[src="https://isitmaintained.com/badge/open/huonw/external_mixin.svg"]');
39+
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a[href="https://travis-ci.org/huonw/external_mixin"]');
40+
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a img[src="https://travis-ci.org/huonw/external_mixin.svg?branch=master"]');
41+
42+
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.)');
43+
hasText(assert, '#crates .row:first .downloads', '477');
44+
45+
await click('a[href="/search?page=2&q=rust"]');
46+
47+
assert.equal(currentURL(), '/search?page=2&q=rust');
48+
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
49+
50+
findWithAssert('a[href="/search?q=rust"]');
51+
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
52+
53+
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
54+
hasText(assert, '#results', 'Displaying 11-18 of 18 total results Sort by Relevance Relevance Downloads');
55+
56+
hasText(assert, '#crates .row:first .desc .info', 'rusted_cypher');
57+
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.7.1"]');
6058
});
6159

62-
test('pressing S key to focus the search bar', function(assert) {
60+
test('pressing S key to focus the search bar', async function(assert) {
6361
const KEYCODE_S = 83;
6462
const KEYCODE_A = 65;
6563

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

72-
visit('/');
73-
andThen(function() {
74-
findWithAssert('#cargo-desktop-search').blur();
75-
});
70+
await visit('/');
7671

77-
keyEvent(document, 'keypress', KEYCODE_A);
78-
andThen(function assertSearchBarIsNotFocused() {
79-
const $searchBar = find('#cargo-desktop-search');
80-
assert.notEqual($searchBar[0], document.activeElement);
81-
$searchBar.blur();
82-
});
72+
findWithAssert('#cargo-desktop-search').blur();
73+
74+
await keyEvent(document, 'keypress', KEYCODE_A);
75+
76+
const $searchBar = find('#cargo-desktop-search');
77+
assert.notEqual($searchBar[0], document.activeElement);
78+
$searchBar.blur();
79+
80+
await keyEvent(document, 'keypress', KEYCODE_S);
81+
assertSearchBarIsFocused();
8382

84-
keyEvent(document, 'keypress', KEYCODE_S);
85-
andThen(assertSearchBarIsFocused);
86-
keyEvent(document, 'keydown', KEYCODE_S);
87-
andThen(assertSearchBarIsFocused);
83+
await keyEvent(document, 'keydown', KEYCODE_S);
84+
assertSearchBarIsFocused();
8885
});

tests/acceptance/team-page-test.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3+
import hasText from 'cargo/tests/helpers/has-text';
34

45
moduleForAcceptance('Acceptance | team page');
56

6-
test('has team organization display', function(assert) {
7-
visit('/teams/github:org:thehydroimpulse');
7+
test('has team organization display', async function(assert) {
8+
await visit('/teams/github:org:thehydroimpulse');
89

9-
andThen(function() {
10-
hasText(assert, '.team-info h1', 'org_test');
11-
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
12-
});
10+
hasText(assert, '.team-info h1', 'org_test');
11+
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
1312
});
1413

15-
test('has link to github in team header', function(assert) {
16-
visit('/teams/github:org:thehydroimpulse');
17-
18-
andThen(function() {
19-
const $githubLink = findWithAssert('.info a');
20-
assert.equal($githubLink.attr('href').trim(), 'https://github.com/org_test');
21-
});
14+
test('has link to github in team header', async function(assert) {
15+
await visit('/teams/github:org:thehydroimpulse');
2216

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

25-
test('github link has image in team header', function(assert) {
26-
visit('/teams/github:org:thehydroimpulse');
21+
test('github link has image in team header', async function(assert) {
22+
await visit('/teams/github:org:thehydroimpulse');
2723

28-
andThen(function() {
29-
const $githubImg = findWithAssert('.info a img');
30-
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
31-
});
24+
const $githubImg = findWithAssert('.info a img');
25+
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
3226
});
3327

34-
test('team organization details has github profile icon', function(assert) {
35-
visit('/teams/github:org:thehydroimpulse');
28+
test('team organization details has github profile icon', async function(assert) {
29+
await visit('/teams/github:org:thehydroimpulse');
3630

37-
andThen(function() {
38-
const $githubProfileImg = findWithAssert('.info img');
39-
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
40-
});
31+
const $githubProfileImg = findWithAssert('.info img');
32+
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
4133
});

0 commit comments

Comments
 (0)