Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions test/fixtures/my-addon/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
extends: [
'eslint:recommended'
],
env: {
browser: true
},
rules: {
},
overrides: [
// node files
{
files: [
'index.js',
'testem.js',
'ember-cli-build.js',
'config/**/*.js',
'lib/**',
'test/**',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'app/**',
'addon/**',
'test/fixtures/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
}
}
]
};
3 changes: 3 additions & 0 deletions test/fixtures/my-addon/config/coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
reporters: ['lcov', 'html', 'text']
};
3 changes: 3 additions & 0 deletions test/fixtures/my-app-with-in-repo-addon/config/coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
reporters: ['lcov', 'html', 'text']
};
42 changes: 42 additions & 0 deletions test/fixtures/my-app-with-in-repo-engine/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
extends: [
'eslint:recommended'
],
env: {
browser: true
},
rules: {
},
overrides: [
// node files
{
files: [
'index.js',
'testem.js',
'ember-cli-build.js',
'config/**/*.js',
'test/**',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'app/**',
'addon/**',
'test/fixtures/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
}
}
]
};
13 changes: 13 additions & 0 deletions test/fixtures/my-app-with-in-repo-engine/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import EmberRouter from '@ember/routing/router';
import config from './config/environment';

const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
this.mount('my-in-repo-engine')
});

export default Router;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function myCoveredUtil() {
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function myUncoveredUtil() {
return true;
}
3 changes: 3 additions & 0 deletions test/fixtures/my-app-with-in-repo-engine/config/coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
reporters: ['lcov', 'html', 'text']
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
env: {
node: true,
browser: false
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Engine from 'ember-engines/engine';
import loadInitializers from 'ember-load-initializers';
import Resolver from './resolver';
import config from './config/environment';

const { modulePrefix } = config;

const Eng = Engine.extend({
modulePrefix,
Resolver
});

loadInitializers(Eng, modulePrefix);

export default Eng;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Resolver from 'ember-resolver';

export default Resolver;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import buildRoutes from 'ember-engines/routes';

export default buildRoutes(function() {
// Define your engine's route map here
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{outlet}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function myCoveredUtil() {
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function myUncoveredUtil() {
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*jshint node:true*/
'use strict';

module.exports = function(environment) {
var ENV = {
modulePrefix: 'my-in-repo-engine',
environment: environment
};

return ENV;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "my-in-repo-engine",
"keywords": [
"ember-addon",
"ember-engine"
],
"dependencies": {
"ember-cli-htmlbars": "*",
"ember-cli-babel": "*"
}
}
24 changes: 24 additions & 0 deletions test/fixtures/my-app-with-in-repo-engine/testem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: [
'Chrome'
],
launch_in_dev: [
'Chrome'
],
browser_args: {
Chrome: {
mode: 'ci',
args: [
// --no-sandbox is needed when running Chrome inside a container
process.env.TRAVIS ? '--no-sandbox' : null,

'--disable-gpu',
'--headless',
'--remote-debugging-port=0',
'--window-size=1440,900'
].filter(Boolean)
}
}
};
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import myCoveredUtil from 'my-in-repo-engine/utils/my-covered-util';
import { module, test } from 'qunit';

module('Unit | Utility | my covered util');

// Replace this with your real tests.
test('it works', function(assert) {
let result = myCoveredUtil();
assert.ok(result);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import myCoveredUtil from 'my-app-with-in-repo-engine/utils/my-covered-util-app';
import { module, test } from 'qunit';

module('Unit | Utility | my covered util app');

// Replace this with your real tests.
test('it works', function(assert) {
let result = myCoveredUtil();
assert.ok(result);
});
3 changes: 3 additions & 0 deletions test/fixtures/my-app/config/coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
reporters: ['lcov', 'html', 'text']
};
55 changes: 55 additions & 0 deletions test/helpers/in-repo-engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

const InRepoAddon = require('./in-repo-addon');

class InRepoEngine extends InRepoAddon {
static generate(app, name, options) {
let args = ['generate', 'in-repo-engine', name];

if (typeof options.lazy !== 'undefined') {
args.push('--lazy', options.lazy);
}

if (typeof options.type !== 'undefined') {
args.push('--type', options.type);
}

return app.runEmberCommand.apply(app, args).then(() => {
let engine = new InRepoEngine(app, name);
// Set up a simple default CSS file
engine.writeFixture({
addon: {
styles: {
'app.css': `/* ${name}.css */`,
},
},
});
return engine;
});
}

generateNestedEngine(name) {
// Generate another in-repo-engine at the app level...
let args = Array.prototype.slice.call(arguments);
args.unshift(this.app);
return InRepoEngine.generate.apply(null, args).then(engine => {
// Remove the in-repo-engine from the app...
this.app.editPackageJSON(pkg => {
pkg['ember-addon'].paths = pkg['ember-addon'].paths.filter(
path => path !== `lib/${name}`
);
});

// Add the in-repo-engine to this engine.
this.editPackageJSON(pkg => {
pkg['ember-addon'] = pkg['ember-addon'] || {};
pkg['ember-addon'].paths = pkg['ember-addon'].paths || [];
pkg['ember-addon'].paths.push(`../${name}`);
});

return engine;
});
}
}

module.exports = InRepoEngine;
81 changes: 81 additions & 0 deletions test/integration/in-repo-engine-coverage-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

var fs = require('fs-extra');
var RSVP = require('rsvp');
var rimraf = RSVP.denodeify(require('rimraf'));
var chai = require('chai');
const co = require('co');
var expect = chai.expect;
var chaiFiles = require('chai-files');
var dir = chaiFiles.dir;
var file = chaiFiles.file;
var path = require('path');

const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
const InRepoEngine = require('../helpers/in-repo-engine');

chai.use(chaiFiles);

let app;

describe('in-repo engine coverage generation', function() {
this.timeout(10000000);
beforeEach(function() {
app = new AddonTestApp();
return app.create('my-app-with-in-repo-engine', {
emberVersion: '2.16.0'
}).then(() => {
app.editPackageJSON(pkg => {
pkg.devDependencies['ember-engines'] = '0.5.14';
pkg.devDependencies['ember-exam'] = '0.7.0';
// Temporarily remove the addon before install to work around https://github.com/tomdale/ember-cli-addon-tests/issues/176
delete pkg.devDependencies['ember-cli-code-coverage'];
});
return app.run('npm', 'install').then(() => {
app.editPackageJSON(pkg => {
pkg.devDependencies['ember-cli-code-coverage'] = '*';
});
let addonPath = path.join(app.path, 'node_modules', 'ember-cli-code-coverage');
fs.removeSync(addonPath);
fs.ensureSymlinkSync(process.cwd(), addonPath);
return rimraf(`${app.path}/coverage*`);
});
});
});

afterEach(function() {
return RSVP.all([
rimraf(`${app.path}/config/coverage.js`)
]);
});

it('runs coverage on in-repo engine', co.wrap(function* () {
let engine = yield InRepoEngine.generate(app, 'my-in-repo-engine', {
lazy: false
});
engine.editPackageJSON(
pkg => (pkg.dependencies = {
'ember-cli-babel': '*',
'ember-cli-htmlbars': '*',
})
);
expect(dir(`${app.path}/coverage`)).to.not.exist;
process.env.COVERAGE = true;
return app.run('ember', 'test').then(function() {
expect(file(`${app.path}/coverage/lcov-report/index.html`)).to.not.be.empty;
expect(file(`${app.path}/coverage/index.html`)).to.not.be.empty;

const summary = fs.readJSONSync(`${app.path}/coverage/coverage-summary.json`);
expect(summary.total.lines.pct).to.equal(75);
expect(summary['app/utils/my-covered-util-app.js'].lines.total).to.equal(1);

// Check that lib/my-in-repo-engine/utils/my-covered-utill is 1 line and that 1 line is covered
expect(summary['lib/my-in-repo-engine/addon/utils/my-covered-util.js'].lines.total).to.equal(1);
expect(summary['lib/my-in-repo-engine/addon/utils/my-covered-util.js'].lines.covered).to.equal(1);

// Check that lib/my-in-repo-engine/utils/my-uncovered-utill is 1 line and that 0 lines are covered
expect(summary['lib/my-in-repo-engine/addon/utils/my-uncovered-util.js'].lines.total).to.equal(1);
expect(summary['lib/my-in-repo-engine/addon/utils/my-uncovered-util.js'].lines.covered).to.equal(0);
});
}));
});