Skip to content

Commit 8896149

Browse files
authored
Merge pull request ember-learn#349 from scalvert/mocha-node-tests
Converts node tests to use mocha instead of qunit.
2 parents b7224c3 + a772937 commit 8896149

File tree

7 files changed

+353
-69
lines changed

7 files changed

+353
-69
lines changed

.eslintrc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ module.exports = {
6969

7070
// node test files
7171
{
72+
globals: {
73+
describe: true,
74+
it: true,
75+
beforeEach: true,
76+
afterEach: true,
77+
},
7278
files: ['tests-node/**/*.js'],
7379
rules: {
7480
'node/no-unpublished-require': 'off'
75-
}
81+
},
7682
}
7783
]
7884
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"start": "ember serve",
2121
"test": "ember try:each",
2222
"test:browser": "ember test --test-port=0",
23-
"test:node": "qunit tests-node",
23+
"test:node": "mocha tests-node/**/*-test.js",
2424
"test:test-apps": "cd test-apps/new-addon && yarn test",
2525
"prepare": "./scripts/link-them.sh"
2626
},
@@ -90,6 +90,7 @@
9090
"@ember/optional-features": "^0.7.0",
9191
"babel-eslint": "^10.0.1",
9292
"broccoli-asset-rev": "^3.0.0",
93+
"chai": "^4.2.0",
9394
"common-tags": "^1.8.0",
9495
"ember-classy-page-object": "^0.5.0",
9596
"ember-cli": "~3.4.3",
@@ -120,6 +121,7 @@
120121
"eslint-plugin-ember": "^5.2.0",
121122
"eslint-plugin-node": "^7.0.1",
122123
"loader.js": "^4.7.0",
124+
"mocha": "^6.0.2",
123125
"qunit": "^2.6.2",
124126
"qunit-dom": "^0.8.4"
125127
},

tests-node/unit/deploy/plugin-test.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
'use strict';
22

3-
const QUnit = require('qunit');
3+
const assert = require('chai').assert;
44
const AddonDocsDeployPlugin = require('../../../lib/deploy/plugin');
55

6-
const qModule = QUnit.module;
7-
const test = QUnit.test;
8-
9-
qModule('`deploy` | plugin test', hooks => {
10-
hooks.beforeEach(function() {
6+
describe('`deploy` | plugin test', function() {
7+
beforeEach(function() {
118
this.pluginInstance = new AddonDocsDeployPlugin();
129
});
1310

14-
test('_macroReplaceIndexContent', function(assert) {
11+
it('_macroReplaceIndexContent', function() {
1512
const contents = `
1613
<!DOCTYPE html>
1714
<html>

tests-node/unit/navigation-index-generator/test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
22

3-
const QUnit = require('qunit'), test = QUnit.test;
3+
const assert = require('chai').assert;
44
const NavigationIndexGenerator = require('../../../lib/broccoli/docs-compiler/navigation-index-generator');
55

66
let generator = new NavigationIndexGenerator();
77

8-
QUnit.module('Unit | NavigationIndexGenerator', function(hooks) {
8+
describe('Unit | NavigationIndexGenerator', function(hooks) {
99

10-
test('the correct navigation is generated for a component', function(assert) {
10+
it('the correct navigation is generated for a component', function() {
1111
let modulesWithComponent = require('./examples/one-component.json');
1212
let navigationIndex = generator.generate(modulesWithComponent);
1313

@@ -25,7 +25,7 @@ QUnit.module('Unit | NavigationIndexGenerator', function(hooks) {
2525
]);
2626
});
2727

28-
test('it sorts modules by path', function(assert) {
28+
it('it sorts modules by path', function() {
2929
let modulesWithComponent = require('./examples/multiple-components.json');
3030
let navigationIndex = generator.generate(modulesWithComponent);
3131

@@ -48,7 +48,7 @@ QUnit.module('Unit | NavigationIndexGenerator', function(hooks) {
4848
]);
4949
});
5050

51-
test('the correct navigation is generated for a generic module with multiple classes', function(assert) {
51+
it('the correct navigation is generated for a generic module with multiple classes', function() {
5252
let modulesWithComponent = require('./examples/generic-module-multiple-classes.json');
5353
let navigationIndex = generator.generate(modulesWithComponent);
5454

@@ -66,7 +66,7 @@ QUnit.module('Unit | NavigationIndexGenerator', function(hooks) {
6666
]);
6767
});
6868

69-
test('it correctly handles modules with a single type', function(assert) {
69+
it('it correctly handles modules with a single type', function() {
7070
let modulesWithComponent = require('./examples/generic-module-one-class.json');
7171
let navigationIndex = generator.generate(modulesWithComponent);
7272

@@ -84,7 +84,7 @@ QUnit.module('Unit | NavigationIndexGenerator', function(hooks) {
8484
]);
8585
});
8686

87-
test('sanity check: it handles addon-docs', function(assert) {
87+
it('sanity check: it handles addon-docs', function() {
8888
let modules = require('./examples/addon-docs.json');
8989
let navigationIndex = generator.generate(modules);
9090

@@ -157,7 +157,7 @@ QUnit.module('Unit | NavigationIndexGenerator', function(hooks) {
157157
]);
158158
});
159159

160-
test('sanity check: it handles sandbox', function(assert) {
160+
it('sanity check: it handles sandbox', function() {
161161
let modules = require('./examples/sandbox.json');
162162
let navigationIndex = generator.generate(modules);
163163

@@ -228,7 +228,7 @@ QUnit.module('Unit | NavigationIndexGenerator', function(hooks) {
228228
]);
229229
});
230230

231-
test('correctly handle _resolvedTypeForModule for module names containing type itself', function(assert) {
231+
it('correctly handle _resolvedTypeForModule for module names containing type itself', function() {
232232
let testcases = [
233233
[ 'ember-addon-helpers/unresolved-type', false ],
234234
[ 'ember-addon-helpers/helpers', 'helpers' ],

tests-node/unit/utils/compile-markdown-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
const QUnit = require('qunit'), test = QUnit.test;
3+
const assert = require('chai').assert;
44
const stripIndent = require('common-tags').stripIndent;
55
const compileMarkdown = require('../../../lib/utils/compile-markdown');
66

7-
QUnit.module('Unit | compile-markdown', function(hooks) {
8-
test('compacting curly paragraphs', function(assert) {
7+
describe('Unit | compile-markdown', function(hooks) {
8+
it('compacting curly paragraphs', function() {
99
let input = stripIndent`
1010
{{#foo-bar}}
1111
@@ -20,7 +20,7 @@ QUnit.module('Unit | compile-markdown', function(hooks) {
2020
assert.equal(result, expected);
2121
});
2222

23-
test('compacting angle bracket paragraphs', function(assert) {
23+
it('compacting angle bracket paragraphs', function() {
2424
let input = stripIndent`
2525
<FooBar>
2626
@@ -38,7 +38,7 @@ QUnit.module('Unit | compile-markdown', function(hooks) {
3838
assert.equal(result, expected);
3939
});
4040

41-
test('compacting implicit code blocks', function(assert) {
41+
it('compacting implicit code blocks', function() {
4242
// Surrounding whitespace + 4-space indent = code block in MD
4343
let input = stripIndent`
4444
{{#foo-bar}}
@@ -56,7 +56,7 @@ QUnit.module('Unit | compile-markdown', function(hooks) {
5656
assert.equal(result, expected);
5757
});
5858

59-
test('classic components remain unescaped', function(assert) {
59+
it('classic components remain unescaped', function() {
6060
let input = stripIndent`
6161
{{#foo-bar prop="value" otherProp='value'}}
6262
@@ -71,7 +71,7 @@ QUnit.module('Unit | compile-markdown', function(hooks) {
7171
assert.equal(result, expected);
7272
});
7373

74-
test('angle bracket contextual components remain unescaped', function(assert) {
74+
it('angle bracket contextual components remain unescaped', function() {
7575
let input = stripIndent`
7676
<foo.bar @prop={{value}}></foo.bar>
7777
`;
@@ -84,7 +84,7 @@ QUnit.module('Unit | compile-markdown', function(hooks) {
8484
assert.equal(result, expected);
8585
});
8686

87-
test('using opening curlies inside backticks shouldn\'t compact paragraphs', function(assert) {
87+
it('using opening curlies inside backticks shouldn\'t compact paragraphs', function() {
8888
let input = stripIndent`
8989
Foo bar is \`{{#my-component}}\`.
9090
@@ -100,7 +100,7 @@ QUnit.module('Unit | compile-markdown', function(hooks) {
100100
assert.equal(result, expected);
101101
});
102102

103-
test('using opening angle brackets inside backticks shouldn\'t compact paragraphs', function(assert) {
103+
it('using opening angle brackets inside backticks shouldn\'t compact paragraphs', function() {
104104
let input = stripIndent`
105105
Foo bar is \`<My component>\`.
106106

tests-node/unit/utils/update-demo-url-test.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
'use strict';
22

3-
const QUnit = require('qunit');
3+
const assert = require('chai').assert;
44
const fs = require('fs-extra');
55
const path = require('path');
66
const updateDemoUrl = require('../../../lib/utils/update-demo-url');
77

8-
const qModule = QUnit.module;
9-
const test = QUnit.test;
10-
11-
qModule('`updateDemoUrl` | fixture test', hooks => {
8+
describe('`updateDemoUrl` | fixture test', function() {
129
const fixturesPath = path.join(__dirname, '../..', 'fixtures', 'update-demo-url');
1310

1411
let inputCopyPath, outputPath, setupFixtureDirectory;
1512

16-
hooks.beforeEach(() => {
13+
beforeEach(function() {
1714
setupFixtureDirectory = (dir) => {
1815
inputCopyPath = path.join(fixturesPath, dir, 'input--temp.json');
1916
outputPath = path.join(fixturesPath, dir, 'output.json');
2017
fs.copySync(path.join(fixturesPath, dir, 'input.json'), inputCopyPath);
2118
}
2219
});
2320

24-
hooks.afterEach(() => {
21+
afterEach(function() {
2522
if (inputCopyPath) {
2623
fs.unlinkSync(inputCopyPath);
2724
inputCopyPath = '';
2825
}
2926
});
3027

31-
test('it leaves the `homepage` property if it already exists', assert => {
28+
it('it leaves the `homepage` property if it already exists', function() {
3229
setupFixtureDirectory('has-existing-homepage');
3330

3431
const result = updateDemoUrl(inputCopyPath);
@@ -40,7 +37,7 @@ qModule('`updateDemoUrl` | fixture test', hooks => {
4037
);
4138
});
4239

43-
test('it adds the `homepage` property based on git remote repository', assert => {
40+
it('it adds the `homepage` property based on git remote repository', function() {
4441
const dir = 'has-git-repository';
4542
setupFixtureDirectory(dir);
4643

@@ -55,7 +52,7 @@ qModule('`updateDemoUrl` | fixture test', hooks => {
5552
);
5653
});
5754

58-
test('it adds the `homepage` property based on package repository value', assert => {
55+
it('it adds the `homepage` property based on package repository value', function() {
5956
setupFixtureDirectory('has-package-repository');
6057

6158
const result = updateDemoUrl(inputCopyPath);
@@ -67,7 +64,7 @@ qModule('`updateDemoUrl` | fixture test', hooks => {
6764
);
6865
});
6966

70-
test('it adds the `homepage` property based on package repository url property', assert => {
67+
it('it adds the `homepage` property based on package repository url property', function() {
7168
setupFixtureDirectory('has-git-repository-object');
7269

7370
const result = updateDemoUrl(inputCopyPath);
@@ -79,7 +76,7 @@ qModule('`updateDemoUrl` | fixture test', hooks => {
7976
);
8077
});
8178

82-
test('it returns false when there is no repository to update', assert => {
79+
it('it returns false when there is no repository to update', function() {
8380
const dir = 'missing-repository';
8481
setupFixtureDirectory(dir);
8582

@@ -89,7 +86,7 @@ qModule('`updateDemoUrl` | fixture test', hooks => {
8986
assert.notOk(result);
9087
});
9188

92-
test('it returns false when the repository is not a git repo', assert => {
89+
it('it returns false when the repository is not a git repo', function() {
9390
const dir = 'non-git-repository';
9491
setupFixtureDirectory(dir);
9592

0 commit comments

Comments
 (0)