Skip to content

Commit

Permalink
Revert "Merge pull request #229 from Turbo87/shimmer"
Browse files Browse the repository at this point in the history
This reverts commit 9be046e, reversing
changes made to 76114be.
  • Loading branch information
Turbo87 committed Jan 21, 2018
1 parent 9799dce commit 81759d2
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 179 deletions.
4 changes: 4 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"directory": "bower_components",
"analytics": false
}
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ sudo: false

cache:
yarn: true
directories:
- $HOME/.cache # includes bowers cache

env:
- EMBER_TRY_SCENARIO=ember-lts-2.4
Expand All @@ -24,11 +26,13 @@ matrix:
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
- yarn global add phantomjs-prebuilt
- yarn global add bower phantomjs-prebuilt
- bower --version
- phantomjs --version

install:
- yarn install --no-lockfile
- bower install

script:
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
Expand Down
6 changes: 6 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "ember-cli-mocha",
"dependencies": {
"ember-cli-test-loader": "0.2.2"
}
}
177 changes: 173 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,185 @@
/* eslint-env node */

var path = require('path');
var fs = require('fs');
var MergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
var resolve = require('resolve');

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

contentFor(type) {
let output = this.eachAddonInvoke('contentFor', [type]);
return output.join('\n');
overrideTestCommandFilter: function() {
var TestCommand = this.project.require('ember-cli/lib/commands/test');

TestCommand.prototype.buildTestPageQueryString = function(options) {
var params = [];

if (options.filter) {
params.push('grep=' + options.filter);

if (options.invert) {
params.push('invert=1');
}
}

if (options.query) {
params.push(options.query);
}

return params.join('&');
};

TestCommand.prototype.availableOptions.push({
name: 'invert',
type: Boolean,
default: false,
description: 'Invert the filter specified by the --filter argument',
aliases: ['i']
});
},

blueprintsPath() {
_getDependencyTrees: function() {
if (this._dependencyTrees) {
return this._dependencyTrees;
}

var emberTestHelpersPath = path.dirname(resolve.sync('ember-test-helpers', { basedir: this._emberMochaLibPath }));
this._dependencyTrees = [
this.treeGenerator(this._emberMochaLibPath),
this.treeGenerator(emberTestHelpersPath),
];

return this._dependencyTrees;
},

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

this.overrideTestCommandFilter();

this._emberMochaLibPath = path.dirname(resolve.sync('ember-mocha'));
this._shouldPreprocessAddonTestSupport = !!this.options && !!this.options.babel;

this.setTestGenerator();
},

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

checkPackages: function () {
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') < 0) {
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);
}
},

blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},

treeForVendor: function(tree) {
var mochaPath = path.dirname(resolve.sync('mocha'));
// var mochaTree = this.treeGenerator(mochaPath);
var mochaTree = new Funnel(mochaPath, {
files: ['mocha.js', 'mocha.css'],
destDir: '/mocha',
});

var emberMochaBuildSupportPath = path.join(this._emberMochaLibPath, '..', 'build-support');

var mochaSetupTree = new Funnel(emberMochaBuildSupportPath, {
files: ['mocha-setup.js', 'ember-mocha-adapter.js'],
destDir: '/ember-mocha'
});

var trees = [
tree,
mochaTree,
mochaSetupTree
];

return new MergeTrees(trees, {
annotation: 'ember-cli-mocha: treeForVendor'
});
},

treeForAddonTestSupport: function() {
var tree = new MergeTrees(this._getDependencyTrees());

if (this._shouldPreprocessAddonTestSupport) {
return this.preprocessJs(tree, {
registry: this.registry
});
} else {
return tree;
}
},

included: function included(app, parentAddon) {
var target = (parentAddon || app);
this._super.included.call(this, target);

if (app.tests) {
var fileAssets = [
'vendor/mocha/mocha.js',
'vendor/mocha/mocha.css',
'vendor/ember-mocha/mocha-setup.js',
'vendor/ember-mocha/ember-mocha-adapter.js',
'vendor/ember-cli-mocha/test-loader.js'
];

var addonOptions = app.options['ember-cli-mocha'] || {};
if (addonOptions && !addonOptions.disableContainerStyles) {
fileAssets.push('vendor/ember-cli-mocha/test-container-styles.css');
}

fileAssets.forEach(function(file){
app.import(file, {
type: 'test'
});
});
}
},

contentFor: function(type) {
if (type === 'test-body') {
return this._readTemplate('test-body');
}
},

_readTemplate: function(name) {
return fs.readFileSync(path.join(__dirname, 'templates', name + '.html'));
},

setTestGenerator: function() {
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;
};
}
};
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@
"test": "ember try:each"
},
"dependencies": {
"ember-mocha": "^0.13.0-beta.1"
"broccoli-funnel": "^2.0.0",
"broccoli-merge-trees": "^2.0.0",
"ember-cli-babel": "^6.0.0",
"ember-cli-test-loader": "^2.0.0",
"ember-mocha": "^0.12.0",
"mocha": "^2.5.3",
"resolve": "^1.1.7"
},
"devDependencies": {
"ember-cli": "~2.16.0",
"ember-cli-babel": "^6.0.0",
"ember-cli-chai": "^0.4.0",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.0.0",
Expand Down
6 changes: 6 additions & 0 deletions templates/test-body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div id="mocha"></div>
<div id="mocha-fixture"></div>

<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
42 changes: 42 additions & 0 deletions tests/unit/test-loader-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';

describe('Unit | test-loader', function() {
var TestLoader = window.require('ember-cli/test-loader')['default'];
var originalRequire = window.require;
var requiredModules;

beforeEach(function() {
requiredModules = [];

window.require = (name) => {
requiredModules.push(name);
};
window.require.unsee = () => {};

window.requirejs.entries = {
'valid-test': true,
'valid_test': true,
'valid.jshint.lint-test': true,
'not-valid-jshint': true,
'not-a-test-module': true,
'nohyphentest': true
};
});

afterEach(function() {
window.require = originalRequire;
});

it('loads properly suffixed modules', function() {
TestLoader.load();

var expectedModules = [
'valid-test',
'valid_test',
'valid.jshint.lint-test'
];

expect(requiredModules).to.deep.equal(expectedModules);
});
});
14 changes: 14 additions & 0 deletions vendor/ember-cli-mocha/test-container-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ember-testing-container {
position: fixed;
background: white;
bottom: 0;
right: 0;
width: 640px;
height: 384px;
overflow: auto;
z-index: 9999;
border: 1px solid #ccc;
}
#ember-testing {
zoom: 50%;
}
31 changes: 31 additions & 0 deletions vendor/ember-cli-mocha/test-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* globals jQuery, chai, mocha, require, requirejs */

jQuery(document).ready(function() {
var testLoaderModulePath = 'ember-cli-test-loader/test-support/index';

if (!requirejs.entries[testLoaderModulePath]) {
testLoaderModulePath = 'ember-cli/test-loader';
}

var TestLoader = require(testLoaderModulePath)['default'];
TestLoader.prototype.shouldLoadModule = function(moduleName) {
return moduleName.match(/[-_]test$/) || moduleName.match(/\.jshint$/);
};

TestLoader.prototype.moduleLoadFailure = function(moduleName, error) {
describe('TestLoader Failures', function () {
it(moduleName + ': could not be loaded', function() {
throw error;
});
});
};

// Attempt to mitigate sourcemap issues in Chrome
// See: https:/ember-cli/ember-cli/issues/3098
// https:/ember-cli/ember-cli-qunit/pull/39
setTimeout(function() {
TestLoader.load();

window.mochaRunner = mocha.run();
}, 250);
});
Loading

0 comments on commit 81759d2

Please sign in to comment.