Skip to content

Commit 1541ac6

Browse files
committed
[refactor] Refactored tests to use QUnit (45m)
Also has happy byproduct of eliminating vulnerable dependency on rollup
1 parent 3a4af6f commit 1541ac6

File tree

9 files changed

+2917
-2013
lines changed

9 files changed

+2917
-2013
lines changed

config/ember-try.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module.exports = function() {
66
return Promise.all([
77
getChannelURL('release'),
88
getChannelURL('beta'),
9-
getChannelURL('canary')
109
]).then((urls) => {
1110
return {
1211
useYarn: true,
@@ -43,14 +42,6 @@ module.exports = function() {
4342
}
4443
}
4544
},
46-
{
47-
name: 'ember-canary',
48-
npm: {
49-
devDependencies: {
50-
'ember-source': urls[2]
51-
}
52-
}
53-
},
5445
// The default `.travis.yml` runs this scenario via `npm test`,
5546
// not via `ember try`. It's still included here so that running
5647
// `ember try:each` manually or from a customized CI config will run it

package.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,39 @@
2828
"@ember/render-modifiers": "^1.0.2",
2929
"@glimmer/component": "^1.0.0",
3030
"@glimmer/tracking": "^1.0.0",
31-
"ember-cli-babel": "^7.20.5",
31+
"ember-auto-import": "^1.11.3",
32+
"ember-cli-babel": "^7.26.11",
3233
"ember-cli-htmlbars": "^3.0.0",
33-
"ember-copy": "^1.0.0",
34+
"ember-copy": "^2.0.0",
3435
"ember-list-keyboard-navigator": "^0.1.1",
35-
"ember-truth-helpers": "^2.1.0"
36+
"ember-truth-helpers": "^3.1.1"
3637
},
3738
"devDependencies": {
39+
"@ember/test-helpers": "^2.8.1",
3840
"babel-eslint": "^10.1.0",
3941
"broccoli-asset-rev": "^2.7.0",
4042
"ember-cli": "~3.20.0",
41-
"ember-cli-chai": "^0.5.0",
4243
"ember-cli-dependency-checker": "^3.0.0",
4344
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
4445
"ember-cli-inject-live-reload": "^1.8.2",
4546
"ember-cli-sri": "^2.1.1",
4647
"ember-cli-template-lint": "^1.0.0-beta.1",
4748
"ember-cli-terser": "^4.0.1",
4849
"ember-disable-prototype-extensions": "^1.1.3",
49-
"ember-export-application-global": "^2.0.0",
50-
"ember-load-initializers": "^1.1.0",
51-
"ember-maybe-import-regenerator": "^0.1.6",
52-
"ember-mocha": "^0.16.2",
53-
"ember-resolver": "^5.0.1",
50+
"ember-load-initializers": "^2.1.2",
51+
"ember-qunit": "^5.1.5",
52+
"ember-resolver": "^8.0.3",
5453
"ember-source": "~3.28.0",
5554
"ember-source-channel-url": "^3.0.0",
56-
"ember-test-selectors": "^0.3.2",
57-
"ember-try": "^1.0.0",
55+
"ember-test-selectors": "^6.0.0",
56+
"ember-try": "^3.0.0",
5857
"eslint": "^7.1.0",
5958
"eslint-plugin-ember": "^8.6.0",
6059
"eslint-plugin-node": "^11.1.0",
6160
"loader.js": "^4.7.0",
62-
"npm-run-all": "^4.1.5"
61+
"npm-run-all": "^4.1.5",
62+
"qunit": "^2.22.0",
63+
"qunit-dom": "^2.0.0"
6364
},
6465
"engines": {
6566
"node": "16.* || >= 18"

tests/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,12 @@
2929

3030
{{content-for "body-footer"}}
3131
{{content-for "test-body-footer"}}
32+
33+
<div id="qunit"></div>
34+
<div id="qunit-fixture">
35+
<div id="ember-testing-container">
36+
<div id="ember-testing"></div>
37+
</div>
38+
</div>
3239
</body>
3340
</html>

tests/integration/components/search-with-modifiers/search-box/component-test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { assert } from 'chai';
2-
import { describe, it } from 'mocha';
3-
import { setupRenderingTest } from 'ember-mocha';
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
43
import { render, find } from '@ember/test-helpers';
54
import hbs from 'htmlbars-inline-precompile';
65
import { prepareConfig } from 'ember-search-with-modifiers/utils/search';
76

8-
describe('Integration | Component | SearchWithModifiers::SearchBox', function() {
9-
setupRenderingTest();
7+
module('Integration | Component | SearchWithModifiers::SearchBox', function(hooks) {
8+
setupRenderingTest(hooks);
109

1110
const configHash = {
1211
"category:": {
@@ -21,7 +20,7 @@ describe('Integration | Component | SearchWithModifiers::SearchBox', function()
2120
}
2221
};
2322

24-
it('highlights modifiers', async function() {
23+
test('highlights modifiers', async function(assert) {
2524
this.set('query', '');
2625
this.set('cursorLocation', -1);
2726
this.set('tokenConfig', prepareConfig(configHash));

tests/integration/components/search-with-modifiers/search-modifiers/component-test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { assert } from 'chai';
2-
import { it, describe } from 'mocha';
3-
import { setupRenderingTest } from 'ember-mocha';
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
43
import { render, findAll, find, triggerKeyEvent } from '@ember/test-helpers';
54
import hbs from 'htmlbars-inline-precompile';
65

@@ -12,17 +11,17 @@ const hintList = [
1211
{ category: 'Action Types', index: 1, position: 1, value: 'plant', label: 'plant' },
1312
{ category: 'Action Types', index: 2, position: 2, value: 'mineral', label: 'mineral' } ] } ];
1413

15-
describe('Integration | Component | SearchWithModifiers::SearchModifiers', function() {
16-
setupRenderingTest();
14+
module('Integration | Component | SearchWithModifiers::SearchModifiers', function(hooks) {
15+
setupRenderingTest(hooks);
1716

18-
it('renders', async function() {
17+
test('renders', async function(assert) {
1918
await render(hbs`
2019
<SearchWithModifiers::SearchModifiers />
2120
`);
22-
assert.exists(find('.search-modifiers'));
21+
assert.ok(find('.search-modifiers'));
2322
});
2423

25-
it('displays hintList', async function() {
24+
test('displays hintList', async function(assert) {
2625
this.set('hintList', hintList);
2726

2827
await render(hbs`
@@ -34,7 +33,7 @@ describe('Integration | Component | SearchWithModifiers::SearchModifiers', funct
3433
['animal', 'plant', 'mineral']);
3534
});
3635

37-
it('list current item works', async function() {
36+
test('list current item works', async function(assert) {
3837
this.set('hintList', hintList);
3938

4039
let model = null;
@@ -47,7 +46,7 @@ describe('Integration | Component | SearchWithModifiers::SearchModifiers', funct
4746
@hintList={{hintList}}/>
4847
`);
4948

50-
assert.isNull(find('.search-modifier.highlighted'), 'Expected nothing to be selected');
49+
assert.strictEqual(null, find('.search-modifier.highlighted'), 'Expected nothing to be selected');
5150

5251
let target = find('[data-test-list-keyboard-navigator]');
5352
target.focus();

tests/test-helper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import Application from '../app';
22
import config from '../config/environment';
3+
import * as QUnit from 'qunit';
34
import { setApplication } from '@ember/test-helpers';
4-
import { start } from 'ember-mocha';
5+
import { setup } from 'qunit-dom';
6+
import { start } from 'ember-qunit';
57

68
setApplication(Application.create(config.APP));
9+
setup(QUnit.assert);
710
start();

tests/unit/models/token-test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { assert } from 'chai';
2-
import { it, describe } from 'mocha';
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
33
import { prepareConfig } from 'ember-search-with-modifiers/utils/search';
44
import Token from 'ember-search-with-modifiers/models/token';
55

6-
describe('Unit | token', function() {
6+
module('Unit | token', function(hooks) {
7+
setupTest(hooks);
8+
79
const configHash = prepareConfig({
810
"before:": {
911
type: 'date',
@@ -24,7 +26,7 @@ describe('Unit | token', function() {
2426
}
2527
});
2628

27-
it('token list type works', function() {
29+
test('token list type works', function(assert) {
2830
let token = new Token({ configHash, fullText: 'category:plant' });
2931

3032
assert.equal(token.type, 'list');
@@ -60,7 +62,7 @@ describe('Unit | token', function() {
6062
]);
6163
});
6264

63-
it('token list type works with quoted tokens', function() {
65+
test('token list type works with quoted tokens', function(assert) {
6466
let token = new Token({ configHash, fullText: 'category:"quoted type"' });
6567

6668
assert.equal(token.type, 'list', 'should identify the type');

tests/unit/utils/search-test.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { assert } from 'chai';
2-
import { it, describe } from 'mocha';
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
33
import { tokenize } from 'ember-search-with-modifiers/utils/search';
44

5-
describe('Unit | Utility | search', function() {
5+
module('Unit | Utility | search', function(hooks) {
6+
setupTest(hooks);
7+
68
function tokenizeAndDescribe(text) {
79
let config = {
810
'#': {
@@ -24,56 +26,56 @@ describe('Unit | Utility | search', function() {
2426
}).join('');
2527
}
2628

27-
describe('tokenize', function() {
28-
it('treats words as spaces', function() {
29+
module('tokenize', function() {
30+
test('treats words as spaces', function(assert) {
2931
assert.equal(tokenizeAndDescribe('hello'), 'hello(space)');
3032
});
3133

32-
it('splits words', function() {
34+
test('splits words', function(assert) {
3335
assert.equal(tokenizeAndDescribe('hello world'), 'hello(space) (space)world(space)');
3436
});
3537

36-
it('consolidates spaces', function() {
38+
test('consolidates spaces', function(assert) {
3739
assert.equal(tokenizeAndDescribe('hello world'), 'hello(space) (space)world(space)');
3840
});
3941

40-
it('keeps quoted phrases together', function() {
42+
test('keeps quoted phrases together', function(assert) {
4143
assert.equal(tokenizeAndDescribe('"hello world"'), '"hello world"(space)');
4244
});
4345

44-
it('handles half-quoted phrases', function() {
46+
test('handles half-quoted phrases', function(assert) {
4547
assert.equal(tokenizeAndDescribe('"hello'), '"hello(space)');
4648
});
4749

48-
it('identifies field-modifiers', function() {
50+
test('identifies field-modifiers', function(assert) {
4951
assert.equal(tokenizeAndDescribe('hello fruit:'), 'hello(space) (space)fruit:(field)');
5052
});
5153

52-
it('identifies symbol-modifiers', function() {
54+
test('identifies symbol-modifiers', function(assert) {
5355
assert.equal(tokenizeAndDescribe('#fruits'), '#fruits(symbol)');
5456
});
5557

56-
it('treats completed modifiers as a single token', function() {
58+
test('treats completed modifiers as a single token', function(assert) {
5759
assert.equal(tokenizeAndDescribe('hello fruit:apple'), 'hello(space) (space)fruit:apple(field)');
5860
});
5961

60-
it('permits spaces between a field-modifier and its value', function() {
62+
test('permits spaces between a field-modifier and its value', function(assert) {
6163
assert.equal(tokenizeAndDescribe('hello fruit: apple'), 'hello(space) (space)fruit: apple(field)');
6264
});
6365

64-
it('does not permit spaces between a symbol-modifier and its value', function() {
66+
test('does not permit spaces between a symbol-modifier and its value', function(assert) {
6567
assert.equal(tokenizeAndDescribe('# fruits'), '#(symbol) (space)fruits(space)');
6668
});
6769

68-
it('accepts quoted phrases as values for modifiers', function() {
70+
test('accepts quoted phrases as values for modifiers', function(assert) {
6971
assert.equal(tokenizeAndDescribe('fruit: "apple"'), 'fruit: "apple"(field)');
7072
});
7173

72-
it('treats space after text after modifiers as a token break', function() {
74+
test('treats space after text after modifiers as a token break', function(assert) {
7375
assert.equal(tokenizeAndDescribe('fruit: apple hello'), 'fruit: apple(field) (space)hello(space)');
7476
});
7577

76-
it('treats broken modifiers as a single token', function() {
78+
test('treats broken modifiers as a single token', function(assert) {
7779
assert.equal(tokenizeAndDescribe('hello fruit:grape'), 'hello(space) (space)fruit:grape(field)');
7880
});
7981
});

0 commit comments

Comments
 (0)