Skip to content

Commit

Permalink
Port existing code to addon structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Dec 6, 2017
1 parent de626c0 commit 9f6bc66
Show file tree
Hide file tree
Showing 38 changed files with 715 additions and 754 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 0 additions & 30 deletions bower.json

This file was deleted.

15 changes: 0 additions & 15 deletions build-support/globalize.js

This file was deleted.

1 change: 0 additions & 1 deletion build-support/iife-start.js

This file was deleted.

1 change: 0 additions & 1 deletion build-support/iife-stop.js

This file was deleted.

1 change: 0 additions & 1 deletion build-support/mocha-setup.js

This file was deleted.

121 changes: 120 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,125 @@

/* eslint-env node */
'use strict';

const path = require('path');
const stripIndent = require('common-tags').stripIndent;

module.exports = {
name: 'ember-mocha'
name: 'ember-mocha',

init() {
this._super.init && this._super.init.apply(this, arguments);

this.setTestGenerator();
},

postBuild() {
this.checkPackages();
},

checkPackages() {
var packages = Object.keys(this.project.addonPackages);
if (packages.indexOf('ember-cli-qunit') !== -1) {
console.warn('\nIt looks like you are using "ember-cli-qunit" which can cause issues with "ember-cli-mocha", please remove this package.\n');
process.exit(1);
}
if (packages.indexOf('ember-cli-htmlbars-inline-precompile') === -1) {
console.warn('\nIt looks like you\'re not on ember-cli 1.13, which includes ember-cli-htmlbars-inline-precompile by default. Please run: ember install ember-cli-htmlbars-inline-precompile.\n');
process.exit(1);
}
},

included() {
this._super.included.apply(this, arguments);

this.import('vendor/mocha/mocha.js', { type: 'test' });
this.import('vendor/mocha/mocha.css', { type: 'test' });
this.import('vendor/ember-mocha/mocha-configuration.js', { type: 'test' });
this.import('vendor/ember-mocha/ember-mocha-adapter.js', { type: 'test' });
this.import('vendor/ember-mocha/test-loader.js', { type: 'test' });

let addonOptions = this.targetOptions();
let explicitlyDisabledStyles = addonOptions.disableContainerStyles === true;
if (!explicitlyDisabledStyles) {
this.import('vendor/ember-mocha/test-container-styles.css', { type: 'test' });
}
},

targetOptions() {
if (!this._targetOptions) {
// 1. check this.parent.options['ember-mocha']
let targetOptions = this.parent.options && this.parent.options['ember-mocha'];
// 2. check this.app.options['ember-mocha']
targetOptions = targetOptions || (this.app && this.app.options && this.app.options['ember-mocha']);
// 3. check this.parent.options['ember-cli-mocha']
targetOptions = targetOptions || (this.parent.options && this.parent.options['ember-cli-mocha']);
// 4. check this.app.options['ember-cli-mocha']
targetOptions = targetOptions || (this.app && this.app.options && this.app.options['ember-cli-mocha']);
this._targetOptions = targetOptions || {};
}

return this._targetOptions;
},

contentFor(type) {
// Skip if insertContentForTestBody === false.
if (type === 'test-body' && !(this.targetOptions().insertContentForTestBody === false)) {
return stripIndent`
<div id="mocha"></div>
<div id="mocha-fixture"></div>
<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
`;
}
},

treeForVendor(tree) {
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
let mochaPath = path.dirname(require.resolve('mocha'));

let mochaTree = new Funnel(this.treeGenerator(mochaPath), {
destDir: 'mocha',
annotation: 'ember-mocha#treeForVendor',
});

return new MergeTrees([mochaTree, tree]);
},

treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
// import { ... } from 'ember-mocha';

return this.preprocessJs(tree, '/', this.name, {
registry: this.registry,
});
},

setTestGenerator() {
this.project.generateTestFile = function(moduleName, tests) {
var output = `describe('${moduleName}', function() {\n`;

tests.forEach(function(test) {
output += ` it('${test.name}', function() {\n`;
if (test.passed) {
output +=
" // precompiled test passed\n";
} else {
output +=
" // precompiled test failed\n" +
` var error = new chai.AssertionError('${test.errorMessage}');\n` +
" error.stack = undefined;\n" +
" throw error;\n";
}
output += " });\n";
});

output += "});\n";

return output;
};
},
};
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,38 @@
"scripts": {
"build": "ember build",
"start": "ember serve",
"test": "ember try:each"
"test": "ember test",
"test:all": "ember try:each"
},
"dependencies": {
"ember-cli-babel": "^6.6.0"
"@ember/test-helpers": "^0.7.2",
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^2.0.0",
"common-tags": "^1.5.1",
"ember-cli-babel": "^6.6.0",
"ember-cli-test-loader": "^2.2.0",
"mocha": "^2.5.3"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^3.0.0",
"ember-cli": "~2.17.0",
"ember-cli-chai": "^0.4.3",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.2.1",
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.0",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-qunit": "^4.1.1",
"ember-cli-pretender": "^1.0.1",
"ember-cli-shims": "^1.2.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^2.0.0",
"ember-data": "^2.17.0",
"ember-disable-prototype-extensions": "^1.1.2",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
"ember-resolver": "^4.0.0",
"ember-source": "~2.17.0",
"ember-welcome-page": "^3.0.0",
"loader.js": "^4.2.3"
},
"engines": {
Expand Down
61 changes: 0 additions & 61 deletions tests/acceptance-test.js

This file was deleted.

32 changes: 32 additions & 0 deletions tests/acceptance/acceptance-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';

describe('basic acceptance test', function() {
this.timeout(5000);

let application;

beforeEach(function() {
application = startApp();
});

afterEach(function() {
destroyApp(application);
});

it('can visit subroutes', function() {
visit('/');

andThen(function() {
expect(find('h2').text()).to.be.empty;
});

visit('/foo');

andThen(function() {
expect(find('h2').text()).to.be.equal('this is an acceptance test');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
/* global visit, andThen */

import Ember from 'ember';
import { describe, it } from 'mocha';
import { setupAcceptanceTest } from 'ember-mocha';
import { expect } from 'chai';

const { expect } = window.chai;

var Router = Ember.Router.extend();

Router.map(function() {
this.route('foo');
});
import App from '../../app';

var App = Ember.Application.extend({
rootElement: '#ember-testing',
Router: Router
});

App.FooController = Ember.Controller.extend({
});
const Application = App.extend({ rootElement: '#ember-testing' });

describe('setupAcceptanceTest()', function() {
this.timeout(5000);

setupAcceptanceTest({ Application: App });
setupAcceptanceTest({ Application });

it('can visit subroutes', function() {
visit('/');
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Router = EmberRouter.extend({
});

Router.map(function() {
this.route('foo');
});

export default Router;
Empty file added tests/dummy/app/styles/app.css
Empty file.
5 changes: 0 additions & 5 deletions tests/dummy/app/templates/application.hbs

This file was deleted.

1 change: 1 addition & 0 deletions tests/dummy/app/templates/foo.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>this is an acceptance test</h2>
1 change: 1 addition & 0 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2></h2>
File renamed without changes.
Loading

0 comments on commit 9f6bc66

Please sign in to comment.