Skip to content

Commit ed4e2ea

Browse files
authored
Merge pull request ember-cli-code-coverage#277 from Turbo87/functions
Use shorthand methods and named functions
2 parents cbb754d + 44612d4 commit ed4e2ea

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ module.exports = {
2626
fileLookup: null,
2727

2828
// Ember Methods
29-
init: function () {
29+
init() {
3030
this._super.init.apply(this, arguments);
3131
this.fileLookup = {};
3232
},
3333

34-
included: function (appOrAddon) {
34+
included(appOrAddon) {
3535
this._super.included.apply(this, arguments);
3636

3737
this.parentRegistry = appOrAddon.registry;
@@ -59,7 +59,7 @@ module.exports = {
5959
}
6060
},
6161

62-
contentFor: function (type) {
62+
contentFor(type) {
6363
if (type === 'test-body-footer' && this._isCoverageEnabled()) {
6464
var template = fs
6565
.readFileSync(path.join(__dirname, 'lib', 'templates', 'test-body-footer.html'))
@@ -73,7 +73,7 @@ module.exports = {
7373
return undefined;
7474
},
7575

76-
includedCommands: function () {
76+
includedCommands() {
7777
return {
7878
'coverage-merge': require('./lib/coverage-merge'),
7979
};
@@ -83,7 +83,7 @@ module.exports = {
8383
* If coverage is enabled attach coverage middleware to the express server run by ember-cli
8484
* @param {Object} startOptions - Express server start options
8585
*/
86-
serverMiddleware: function (startOptions) {
86+
serverMiddleware(startOptions) {
8787
if (!this._isCoverageEnabled()) {
8888
return;
8989
}
@@ -94,7 +94,7 @@ module.exports = {
9494
});
9595
},
9696

97-
testemMiddleware: function (app) {
97+
testemMiddleware(app) {
9898
if (!this._isCoverageEnabled()) {
9999
return;
100100
}
@@ -118,15 +118,15 @@ module.exports = {
118118
* Get project configuration
119119
* @returns {Configuration} project configuration
120120
*/
121-
_getConfig: function () {
121+
_getConfig() {
122122
return config(this.project.configPath());
123123
},
124124

125125
/**
126126
* Get paths to include for coverage
127127
* @returns {Array<String>} include paths
128128
*/
129-
_getIncludes: function () {
129+
_getIncludes() {
130130
return [
131131
...this._getIncludesForAppDirectory(),
132132
...this._getIncludesForAddonDirectory(),
@@ -138,7 +138,7 @@ module.exports = {
138138
* Get paths to include for covering the "app" directory.
139139
* @returns {Array<String>} include paths
140140
*/
141-
_getIncludesForAppDirectory: function () {
141+
_getIncludesForAppDirectory() {
142142
const dir = path.join(this.project.root, 'app');
143143
let prefix = this.parent.isEmberCLIAddon() ? 'dummy' : this.parent.name();
144144
return this._getIncludesForDir(dir, prefix);
@@ -148,7 +148,7 @@ module.exports = {
148148
* Get paths to include for covering the "addon" directory.
149149
* @returns {Array<String>} include paths
150150
*/
151-
_getIncludesForAddonDirectory: function () {
151+
_getIncludesForAddonDirectory() {
152152
let addon = this._findCoveredAddon();
153153
if (addon) {
154154
const addonDir = path.join(this.project.root, 'addon');
@@ -167,7 +167,7 @@ module.exports = {
167167
* Get paths to include for covering the in-repo-addon directories in "lib/*".
168168
* @returns {Array<String>} include paths
169169
*/
170-
_getIncludesForInRepoAddonDirectories: function () {
170+
_getIncludesForInRepoAddonDirectories() {
171171
return this._findInRepoAddons().reduce((acc, addon) => {
172172
let addonDir = path.join(this.project.root, 'lib', addon.name);
173173
let addonAppDir = path.join(addonDir, 'app');
@@ -189,7 +189,7 @@ module.exports = {
189189
* @param {String} prefix The prefix to the ember module ('app', 'dummy' or the name of the addon).
190190
* @returns {Array<String>} include paths
191191
*/
192-
_getIncludesForDir: function (dir, prefix) {
192+
_getIncludesForDir(dir, prefix) {
193193
const hasEmberCliTypescript =
194194
this.project &&
195195
this.project.findAddonByName &&
@@ -213,15 +213,15 @@ module.exports = {
213213
* Get paths to exclude from coverage
214214
* @returns {Array<String>} exclude paths
215215
*/
216-
_getExcludes: function () {
216+
_getExcludes() {
217217
return this._getConfig().excludes || [];
218218
},
219219

220220
/**
221221
* Determine whether or not coverage is enabled
222222
* @returns {Boolean} whether or not coverage is enabled
223223
*/
224-
_isCoverageEnabled: function () {
224+
_isCoverageEnabled() {
225225
var value = process.env[this._getConfig().coverageEnvVar] || false;
226226

227227
if (value.toLowerCase) {
@@ -235,7 +235,7 @@ module.exports = {
235235
* Determine the name of the parent app or addon.
236236
* @returns {String} the name of the parent
237237
*/
238-
_parentName: function () {
238+
_parentName() {
239239
if (this.parent.isEmberCLIAddon()) {
240240
return this._findCoveredAddon().name;
241241
} else {
@@ -247,7 +247,7 @@ module.exports = {
247247
* Find the addon (if any) that's being covered.
248248
* @returns {Addon} the addon under test
249249
*/
250-
_findCoveredAddon: function () {
250+
_findCoveredAddon() {
251251
if (!this._coveredAddon) {
252252
this._coveredAddon = this.project.findAddonByName(this.project.pkg.name);
253253
}
@@ -259,7 +259,7 @@ module.exports = {
259259
* Find the app's in-repo addons (if any).
260260
* @returns {Array<Addon>} the in-repo addons
261261
*/
262-
_findInRepoAddons: function () {
262+
_findInRepoAddons() {
263263
if (!this._inRepoAddons) {
264264
const pkg = this.project.pkg;
265265
const inRepoAddonPaths = pkg['ember-addon'] && pkg['ember-addon'].paths;

lib/attach-middleware.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function coverageHandler(map, options, req, res) {
6060

6161
// Used when app is in dev mode (`ember serve`).
6262
// Creates a new coverage map on every request.
63-
const serverMiddleware = function (app, options) {
63+
function serverMiddleware(app, options) {
6464
app.post(
6565
WRITE_COVERAGE,
6666
bodyParser,
@@ -70,14 +70,14 @@ const serverMiddleware = function (app, options) {
7070
},
7171
logError
7272
);
73-
};
73+
}
7474

7575
// Used when app is in ci mode (`ember test`).
7676
// Collects the coverage on each request and merges it into the coverage map.
77-
const testMiddleware = function (app, options) {
77+
function testMiddleware(app, options) {
7878
let map = istanbul.libCoverage.createCoverageMap();
7979
app.post(WRITE_COVERAGE, bodyParser, coverageHandler.bind(null, map, options), logError);
80-
};
80+
}
8181

8282
module.exports = {
8383
serverMiddleware,

lib/coverage-merge.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var dir = require('node-dir');
1111
module.exports = {
1212
name: 'coverage-merge',
1313
description: 'Merge multiple coverage files together.',
14-
run: function () {
14+
15+
run() {
1516
var istanbul = require('istanbul-api');
1617
var config = this._getConfig();
1718

@@ -56,7 +57,7 @@ module.exports = {
5657
* Get project configuration
5758
* @returns {Configuration} project configuration
5859
*/
59-
_getConfig: function () {
60+
_getConfig() {
6061
return getConfig(this.project.configPath());
6162
},
6263
};

test/unit/index-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('index.js', function () {
1414
Index.parent = Index.project = Index.app = Index.IstanbulPlugin = Index.parentRegistry = null;
1515
sandbox.stub(Index, 'fileLookup').value({});
1616
sandbox.stub(Index, 'parentRegistry').value({
17-
extensionsForType: function () {
17+
extensionsForType() {
1818
return ['js'];
1919
},
2020
});
@@ -44,7 +44,7 @@ describe('index.js', function () {
4444
'some/other/module.js': 'some/other/file.js',
4545
});
4646
sandbox.stub(Index, 'parent').value({
47-
isEmberCLIAddon: function () {
47+
isEmberCLIAddon() {
4848
return false;
4949
},
5050
});
@@ -165,10 +165,10 @@ describe('index.js', function () {
165165
describe('_getExcludes', function () {
166166
beforeEach(function () {
167167
sandbox.stub(Index, 'parent').value({
168-
isEmberCLIAddon: function () {
168+
isEmberCLIAddon() {
169169
return false;
170170
},
171-
name: function () {
171+
name() {
172172
return 'test';
173173
},
174174
});
@@ -301,10 +301,10 @@ describe('index.js', function () {
301301

302302
beforeEach(function () {
303303
sandbox.stub(Index, 'parent').value({
304-
name: function () {
304+
name() {
305305
return 'parent-app';
306306
},
307-
isEmberCLIAddon: function () {
307+
isEmberCLIAddon() {
308308
return isAddon;
309309
},
310310
});

0 commit comments

Comments
 (0)