UNPKG

3.1 kBJavaScriptView Raw
1'use strict';
2
3var path = require('path');
4var fs = require('fs');
5var jshintTrees = require('broccoli-jshint');
6
7module.exports = {
8 name: 'Ember CLI Mocha',
9
10 overrideTestCommandFilter: function() {
11 var TestCommand = this.project.require('ember-cli/lib/commands/test');
12
13 TestCommand.prototype.buildTestPageQueryString = function(options) {
14 var queryString = '';
15
16 if (options.filter) {
17 queryString = "grep=" + options.filter;
18
19 if (options.invert) {
20 queryString += '&invert=1';
21 }
22 }
23
24 return queryString;
25 };
26
27 TestCommand.prototype.availableOptions.push({
28 name: 'invert',
29 type: Boolean,
30 default: false,
31 description: 'Invert the filter specified by the --filter argument',
32 aliases: ['i']
33 });
34 },
35
36 init: function() {
37 this.overrideTestCommandFilter();
38 },
39
40 blueprintsPath: function() {
41 return path.join(__dirname, 'blueprints');
42 },
43
44 included: function(app) {
45 this._super.included(app);
46
47 if (app.tests) {
48 var fileAssets = [
49 app.bowerDirectory + '/mocha/mocha.js',
50 app.bowerDirectory + '/mocha/mocha.css',
51 app.bowerDirectory + '/chai/chai.js',
52 app.bowerDirectory + '/ember-mocha/mocha-setup.js',
53 app.bowerDirectory + '/ember-mocha-adapter/adapter.js',
54 'vendor/ember-cli-mocha/test-loader.js'
55 ];
56
57 var addonOptions = app.options['ember-cli-mocha'] || {};
58 if (addonOptions && !addonOptions.disableContainerStyles) {
59 fileAssets.push('vendor/ember-cli-mocha/test-container-styles.css');
60 }
61
62 app.import(app.bowerDirectory + '/ember-mocha/ember-mocha.amd.js', {
63 type: 'test',
64 exports: {
65 'ember-mocha': [
66 'describeModule',
67 'describeComponent',
68 'describeModel',
69 'it',
70 'setResolver'
71 ]
72 }
73 });
74
75 app.import(app.bowerDirectory + '/ember-cli-shims/test-shims.js', {
76 type: 'test',
77 exports: {
78 'qunit': ['default']
79 }
80 });
81
82 fileAssets.forEach(function(file){
83 app.import(file, {
84 type: 'test'
85 });
86 });
87 }
88 this.jshintrc = app.options.jshintrc;
89 },
90
91 contentFor: function(type) {
92 if (type === 'test-body') {
93 return this._readTemplate('test-body');
94 }
95 },
96
97 _readTemplate: function(name) {
98 return fs.readFileSync(path.join(__dirname, 'templates', name + '.html'));
99 },
100
101 lintTree: function(type, tree) {
102 return jshintTrees(tree, {
103 jshintrcPath: this.jshintrc[type],
104 description: 'JSHint ' + type + '- Mocha',
105 testGenerator: testGenerator
106 });
107 }
108
109};
110
111function testGenerator(relativePath, passed, errors) {
112 if (errors) {
113 errors = "\\n" + this.escapeErrorString(errors);
114 } else {
115 errors = "";
116 }
117
118 return "describe('JSHint - " + relativePath + "', function(){\n" +
119 "it('should pass jshint', function() { \n" +
120 " expect(" + !!passed + ", '" + relativePath + " should pass jshint." + errors + "').to.be.ok; \n" +
121 "})});\n";
122}