1 |
|
2 | 'use strict';
|
3 |
|
4 | const path = require('path');
|
5 | const resolvePackagePath = require('resolve-package-path');
|
6 | const stripIndent = require('common-tags').stripIndent;
|
7 |
|
8 | const validatePeerDependencies = require('validate-peer-dependencies');
|
9 |
|
10 | module.exports = {
|
11 | name: 'ember-qunit',
|
12 |
|
13 | init() {
|
14 | this._super.init && this._super.init.apply(this, arguments);
|
15 |
|
16 | this.setTestGenerator();
|
17 | },
|
18 |
|
19 | included() {
|
20 | this._super.included.apply(this, arguments);
|
21 |
|
22 | validatePeerDependencies(__dirname, {
|
23 | resolvePackagePathFrom: this.parent.root,
|
24 | });
|
25 |
|
26 |
|
27 |
|
28 | this.import('vendor/qunit/qunit.css', { type: 'test' });
|
29 |
|
30 | let addonOptions = this.targetOptions();
|
31 | let explicitlyDisabledStyles = addonOptions.disableContainerStyles === true;
|
32 | if (!explicitlyDisabledStyles) {
|
33 | this.import('vendor/ember-qunit/test-container-styles.css', {
|
34 | type: 'test',
|
35 | });
|
36 | }
|
37 | },
|
38 |
|
39 | targetOptions() {
|
40 | if (!this._targetOptions) {
|
41 |
|
42 | let targetOptions =
|
43 | this.parent.options && this.parent.options['ember-qunit'];
|
44 |
|
45 |
|
46 | targetOptions =
|
47 | targetOptions ||
|
48 | (this.app && this.app.options && this.app.options['ember-qunit']);
|
49 | this._targetOptions = targetOptions || {};
|
50 | }
|
51 |
|
52 | return this._targetOptions;
|
53 | },
|
54 |
|
55 | treeForVendor: function (tree) {
|
56 | const MergeTrees = require('broccoli-merge-trees');
|
57 | const Funnel = require('broccoli-funnel');
|
58 |
|
59 | let qunitPackagePath = resolvePackagePath('qunit', this.parent.root);
|
60 | let qunitPath = path.join(path.dirname(qunitPackagePath), 'qunit');
|
61 |
|
62 | let qunitTree = new Funnel(this.treeGenerator(qunitPath), {
|
63 | destDir: 'qunit',
|
64 | annotation: 'ember-qunit#treeForVendor',
|
65 | });
|
66 |
|
67 | return new MergeTrees([qunitTree, tree]);
|
68 | },
|
69 |
|
70 | treeForAddonTestSupport(tree) {
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | const Funnel = require('broccoli-funnel');
|
76 |
|
77 | let scopedInputTree = new Funnel(tree, { destDir: 'ember-qunit' });
|
78 |
|
79 | return this.preprocessJs(scopedInputTree, '/', this.name, {
|
80 | annotation: `ember-qunit - treeForAddonTestSupport`,
|
81 | registry: this.registry,
|
82 | treeType: 'addon-test-support',
|
83 | });
|
84 | },
|
85 |
|
86 | setTestGenerator: function () {
|
87 | this.project.generateTestFile = function (moduleName, tests) {
|
88 | let output = `QUnit.module('${moduleName}');\n`;
|
89 |
|
90 | tests.forEach(function (test) {
|
91 | output += stripIndent`
|
92 | QUnit.test('${test.name}', function(assert) {
|
93 | assert.expect(1);
|
94 | assert.ok(${test.passed}, '${test.errorMessage}');
|
95 | });
|
96 | `;
|
97 | });
|
98 |
|
99 | return output;
|
100 | };
|
101 | },
|
102 | };
|