Skip to content

Commit aab6364

Browse files
Michael Jonesmdeanjones
andauthored
Use in-repo addon's "root" property for includes location (#290)
Co-authored-by: Jones, Michael Dean (Contractor) <[email protected]>
1 parent 7979f03 commit aab6364

39 files changed

+776
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ yarn-error.log
1111
# ember-try
1212
.node_modules.ember-try/
1313
/bower.json.ember-try
14-
/package.json.ember-try
14+
/package.json.ember-try

packages/ember-cli-code-coverage/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ module.exports = {
169169
*/
170170
_getIncludesForInRepoAddonDirectories() {
171171
return this._findInRepoAddons().reduce((acc, addon) => {
172-
let addonDir = path.join(this.project.root, 'lib', addon.name);
172+
let addonDir =
173+
typeof addon.root === 'string'
174+
? addon.root
175+
: path.join(this.project.root, 'lib', addon.name);
176+
173177
let addonAppDir = path.join(addonDir, 'app');
174178
let addonAddonDir = path.join(addonDir, 'addon');
175179
const addonAddonTestSupportDir = path.join(addonDir, 'addon-test-support');
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict';
2+
3+
const fs = require('fs-extra');
4+
const util = require('util');
5+
const rimraf = util.promisify(require('rimraf'));
6+
const chai = require('chai');
7+
const expect = chai.expect;
8+
const chaiFiles = require('chai-files');
9+
const dir = chaiFiles.dir;
10+
const file = chaiFiles.file;
11+
const path = require('path');
12+
const execa = require('execa');
13+
14+
chai.use(chaiFiles);
15+
16+
const BASE_PATH = path.join(__dirname, 'my-app-with-custom-path-in-repo-addon');
17+
18+
describe('alternate in-repo addon coverage generation', function () {
19+
this.timeout(10000000);
20+
21+
beforeEach(async function () {
22+
await rimraf(`${BASE_PATH}/coverage*`);
23+
await execa('git', ['clean', '-f', 'my-app-with-custom-path-in-repo-addon'], { cwd: __dirname });
24+
await execa('git', ['restore', 'my-app-with-custom-path-in-repo-addon'], { cwd: __dirname });
25+
});
26+
27+
afterEach(async function () {
28+
await rimraf(`${BASE_PATH}/coverage*`);
29+
await execa('git', ['clean', '-f', 'my-app-with-custom-path-in-repo-addon'], { cwd: __dirname });
30+
await execa('git', ['restore', 'my-app-with-custom-path-in-repo-addon'], { cwd: __dirname });
31+
});
32+
33+
it('runs coverage on in-repo addons from a non-standard directory structure', async function () {
34+
expect(dir(`${BASE_PATH}/coverage`)).to.not.exist;
35+
36+
let env = { COVERAGE: 'true' };
37+
await execa('ember', ['test'], { cwd: BASE_PATH, env });
38+
expect(file(`${BASE_PATH}/coverage/lcov-report/index.html`)).to.not.be.empty;
39+
expect(file(`${BASE_PATH}/coverage/index.html`)).to.not.be.empty;
40+
41+
const summary = fs.readJSONSync(`${BASE_PATH}/coverage/coverage-summary.json`);
42+
expect(summary.total.lines.pct).to.equal(46.67);
43+
expect(summary['app/utils/my-covered-util-app.js'].lines.total).to.equal(1);
44+
45+
// Check that local-lib/addons/my-in-repo-addon/utils/my-covered-utill
46+
// is 1 line and that 1 line is covered
47+
expect(
48+
summary['local-lib/addons/my-in-repo-addon/addon/utils/my-covered-util.js'].lines.total
49+
).to.equal(1);
50+
expect(
51+
summary['local-lib/addons/my-in-repo-addon/addon/utils/my-covered-util.js'].lines.covered
52+
).to.equal(1);
53+
54+
// Check that local-lib/addons/my-in-repo-addon/utils/my-uncovered-utill
55+
// is 1 line and that 0 lines are covered
56+
expect(
57+
summary['local-lib/addons/my-in-repo-addon/addon/utils/my-uncovered-util.js'].lines.total
58+
).to.equal(1);
59+
expect(
60+
summary['local-lib/addons/my-in-repo-addon/addon/utils/my-uncovered-util.js'].lines.covered
61+
).to.equal(0);
62+
63+
// Check that local-lib/addons/my-in-repo-addon/addon-test-support/uncovered-test-support
64+
// is 4 lines and that 0 lines are covered
65+
expect(
66+
summary['local-lib/addons/my-in-repo-addon/addon-test-support/uncovered-test-support.js']
67+
.lines.total
68+
).to.equal(4);
69+
70+
expect(
71+
summary['local-lib/addons/my-in-repo-addon/addon-test-support/uncovered-test-support.js']
72+
.lines.covered
73+
).to.equal(0);
74+
});
75+
});

test-packages/index-test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,53 @@ describe('index.js', function () {
484484
});
485485
});
486486
});
487+
488+
describe('for an app with an inrepo addon under a custom path', function () {
489+
let root = path.join(__dirname, 'my-app-with-custom-path-in-repo-addon');
490+
let addon = { name: 'my-in-repo-addon', root: root + '/local-lib/addons/my-in-repo-addon' };
491+
492+
beforeEach(function () {
493+
sandbox.stub(path, 'basename').returns('my-in-repo-addon');
494+
sandbox.stub(Index, 'project').value({
495+
pkg: {
496+
'ember-addon': {
497+
paths: [''],
498+
},
499+
},
500+
root: root,
501+
findAddonByName() {
502+
return addon;
503+
},
504+
});
505+
});
506+
507+
afterEach(function () {
508+
addon = null;
509+
});
510+
511+
it('instruments the inrepo addon', function () {
512+
const includes = Index._getIncludesForInRepoAddonDirectories();
513+
expect(includes).to.deep.equal([
514+
'my-app/utils/my-covered-util.js',
515+
'my-app/utils/my-uncovered-util.js',
516+
'my-in-repo-addon/utils/my-covered-util.js',
517+
'my-in-repo-addon/utils/my-uncovered-util.js',
518+
'my-in-repo-addon/test-support/uncovered-test-support.js',
519+
]);
520+
expect(Index.fileLookup).to.deep.equal({
521+
'my-app/utils/my-covered-util.js':
522+
'local-lib/addons/my-in-repo-addon/app/utils/my-covered-util.js',
523+
'my-app/utils/my-uncovered-util.js':
524+
'local-lib/addons/my-in-repo-addon/app/utils/my-uncovered-util.js',
525+
'my-in-repo-addon/utils/my-covered-util.js':
526+
'local-lib/addons/my-in-repo-addon/addon/utils/my-covered-util.js',
527+
'my-in-repo-addon/utils/my-uncovered-util.js':
528+
'local-lib/addons/my-in-repo-addon/addon/utils/my-uncovered-util.js',
529+
'my-in-repo-addon/test-support/uncovered-test-support.js':
530+
'local-lib/addons/my-in-repo-addon/addon-test-support/uncovered-test-support.js',
531+
});
532+
});
533+
});
487534
});
488535
});
489536
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.hbs]
16+
insert_final_newline = false
17+
18+
[*.{diff,md}]
19+
trim_trailing_whitespace = false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
/**
3+
Ember CLI sends analytics information by default. The data is completely
4+
anonymous, but there are times when you might want to disable this behavior.
5+
6+
Setting `disableAnalytics` to true will prevent any data from being sent.
7+
*/
8+
"disableAnalytics": false
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# unconventional js
2+
/blueprints/*/files/
3+
/vendor/
4+
5+
# compiled output
6+
/dist/
7+
/tmp/
8+
9+
# dependencies
10+
/bower_components/
11+
/node_modules/
12+
13+
# misc
14+
/coverage/
15+
!.*
16+
17+
# ember-try
18+
/.node_modules.ember-try/
19+
/bower.json.ember-try
20+
/package.json.ember-try
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
module.exports = {
4+
root: true,
5+
parser: 'babel-eslint',
6+
parserOptions: {
7+
ecmaVersion: 2018,
8+
sourceType: 'module',
9+
ecmaFeatures: {
10+
legacyDecorators: true
11+
}
12+
},
13+
plugins: [
14+
'ember'
15+
],
16+
extends: [
17+
'eslint:recommended',
18+
'plugin:ember/recommended'
19+
],
20+
env: {
21+
browser: true
22+
},
23+
rules: {
24+
'ember/no-jquery': 'error'
25+
},
26+
overrides: [
27+
// node files
28+
{
29+
files: [
30+
'.eslintrc.js',
31+
'.template-lintrc.js',
32+
'ember-cli-build.js',
33+
'testem.js',
34+
'blueprints/*/index.js',
35+
'config/**/*.js',
36+
'lib/*/index.js',
37+
'server/**/*.js'
38+
],
39+
parserOptions: {
40+
sourceType: 'script'
41+
},
42+
env: {
43+
browser: false,
44+
node: true
45+
},
46+
plugins: ['node'],
47+
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
48+
// add your custom rules and overrides for node files here
49+
50+
// this can be removed once the following is fixed
51+
// https://github.com/mysticatea/eslint-plugin-node/issues/77
52+
'node/no-unpublished-require': 'off'
53+
})
54+
}
55+
]
56+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist/
5+
/tmp/
6+
7+
# dependencies
8+
/bower_components/
9+
/node_modules/
10+
11+
# misc
12+
/.env*
13+
/.pnp*
14+
/.sass-cache
15+
/connect.lock
16+
/coverage/
17+
/libpeerconnection.log
18+
/npm-debug.log*
19+
/testem.log
20+
/yarn-error.log
21+
22+
# ember-try
23+
/.node_modules.ember-try/
24+
/bower.json.ember-try
25+
/package.json.ember-try
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
extends: 'octane'
5+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
language: node_js
3+
node_js:
4+
- "10"
5+
6+
dist: trusty
7+
8+
addons:
9+
chrome: stable
10+
11+
cache:
12+
directories:
13+
- $HOME/.npm
14+
15+
env:
16+
global:
17+
# See https://git.io/vdao3 for details.
18+
- JOBS=1
19+
20+
branches:
21+
only:
22+
- master
23+
24+
script:
25+
- npm run lint:hbs
26+
- npm run lint:js
27+
- npm test
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ignore_dirs": ["tmp", "dist"]
3+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# my-app-with-custom-path-in-repo-addon
2+
3+
This README outlines the details of collaborating on this Ember application.
4+
A short introduction of this app could easily go here.
5+
6+
## Prerequisites
7+
8+
You will need the following things properly installed on your computer.
9+
10+
* [Git](https://git-scm.com/)
11+
* [Node.js](https://nodejs.org/) (with npm)
12+
* [Ember CLI](https://ember-cli.com/)
13+
* [Google Chrome](https://google.com/chrome/)
14+
15+
## Installation
16+
17+
* `git clone <repository-url>` this repository
18+
* `cd my-app-with-custom-path-in-repo-addon`
19+
* `npm install`
20+
21+
## Running / Development
22+
23+
* `ember serve`
24+
* Visit your app at [http://localhost:4200](http://localhost:4200).
25+
* Visit your tests at [http://localhost:4200/tests](http://localhost:4200/tests).
26+
27+
### Code Generators
28+
29+
Make use of the many generators for code, try `ember help generate` for more details
30+
31+
### Running Tests
32+
33+
* `ember test`
34+
* `ember test --server`
35+
36+
### Linting
37+
38+
* `npm run lint:hbs`
39+
* `npm run lint:js`
40+
* `npm run lint:js -- --fix`
41+
42+
### Building
43+
44+
* `ember build` (development)
45+
* `ember build --environment production` (production)
46+
47+
### Deploying
48+
49+
Specify what it takes to deploy your app.
50+
51+
## Further Reading / Useful Links
52+
53+
* [ember.js](https://emberjs.com/)
54+
* [ember-cli](https://ember-cli.com/)
55+
* Development Browser Extensions
56+
* [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi)
57+
* [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Application from '@ember/application';
2+
import Resolver from 'ember-resolver';
3+
import loadInitializers from 'ember-load-initializers';
4+
import config from './config/environment';
5+
6+
export default class App extends Application {
7+
modulePrefix = config.modulePrefix;
8+
podModulePrefix = config.podModulePrefix;
9+
Resolver = Resolver;
10+
}
11+
12+
loadInitializers(App, config.modulePrefix);

0 commit comments

Comments
 (0)