Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Commit 0eeeba8

Browse files
committed
Added eslint-tests based on sane and fixed codebase.
1 parent f706fc2 commit 0eeeba8

File tree

8 files changed

+101
-11
lines changed

8 files changed

+101
-11
lines changed

.eslintrc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"rules" : {
3+
"strict" : 0,
4+
"no-underscore-dangle" : 0,
5+
"no-multi-spaces" : 0,
6+
"key-spacing" : 0,
7+
"no-shadow" : 0,
8+
"consistent-return" : 2,
9+
"no-use-before-define" : 2,
10+
"new-parens" : 2,
11+
"no-cond-assign" : 2,
12+
"space-after-keywords" : 2,
13+
"space-infix-ops" : 2,
14+
"comma-dangle" : [2, "never"],
15+
"no-multiple-empty-lines" : [2, {"max": 2}],
16+
"quotes" : [2, "single"],
17+
"eqeqeq" : [2, "smart"],
18+
"wrap-iife" : [2, "inside"],
19+
"indent" : [2, 2],
20+
"brace-style" : [2, "1tbs"],
21+
"spaced-line-comment" : [2, "always", {"exceptions":["-","+"]}],
22+
"space-before-function-parentheses": [2, {
23+
"anonymous" : "always",
24+
"named" : "never"
25+
}]
26+
},
27+
"env": {
28+
"node": true,
29+
"es6" : true
30+
}
31+
}

bin/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ var scope = {
1919
},
2020

2121
// For the NEW generator we're generating:
22-
generatorName: process.argv[ 2 ],
22+
generatorName: process.argv[ 2 ]
2323
};
2424

2525
sailsgen( scope, function ( err ) {
26-
if ( err ) throw err;
26+
if ( err ) {
27+
throw err;
28+
}
2729

2830
// It worked.
2931
console.log( 'Done.' );

lib/before.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* Module dependencies
33
*/
44

5-
var util = require( 'util' ),
6-
_ = require( 'lodash' );
5+
var _ = require( 'lodash' );
76

87
// Make _.defaults recursive
98
_.defaults = require( 'merge-defaults' );

lib/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@ module.exports = {
1818

1919
targets: {
2020
'./': {
21-
exec: function( scope, cb ) {
21+
exec: function ( scope, cb ) {
2222
// get the "flavor" of bluepritns
2323
templateDir = templateDir + '/' + scope.flavor;
2424
console.log( 'Running generator (sails-generate-ember-blueprints) @ `' + scope.rootPath + '`...' );
2525

2626
// check for previous installation
2727
if ( fs.existsSync( scope.rootPath + '/api/blueprints' ) && fs.existsSync( scope.rootPath + '/api/services/Ember.js' ) && !scope.force ) {
2828
console.log( scope );
29-
return cb( new Error( "Looks like the blueprints are already installed. Just in case you made some changes to them, we're stopping here. If you want to override the existing files and do a fresh install use the '--force' option." ) );
29+
return cb( new Error( 'Looks like the blueprints are already installed. Just in case you made some changes to them, we\'re stopping here. If you want to override the existing files and do a fresh install use the \'--force\' option.' ) );
3030
}
3131

3232
// copy blueprint and service files
3333
console.log( 'Installing "' + scope.flavor + '" of blueprints.' );
3434

3535
// create blueprints directory if it does not exist
36-
if( ! fs.existsSync( scope.rootPath + '/api/blueprints' ) ) {
36+
if ( !fs.existsSync( scope.rootPath + '/api/blueprints' ) ) {
3737
fs.mkdirSync( scope.rootPath + '/api/blueprints' );
3838
}
3939

40-
['create', 'destroy', 'find', 'findone', 'populate', 'update'].forEach(function(blueprint) {
41-
fs.writeFileSync(scope.rootPath + '/api/blueprints/' + blueprint + '.js', "module.exports = require('sails-generate-ember-blueprints/templates/" + scope.flavor + "/api/blueprints/" + blueprint + ".js');\n");
40+
['create', 'destroy', 'find', 'findone', 'populate', 'update'].forEach(function (blueprint) {
41+
fs.writeFileSync(scope.rootPath + '/api/blueprints/' + blueprint + '.js', 'module.exports = require(\'sails-generate-ember-blueprints/templates/' + scope.flavor + '/api/blueprints/' + blueprint + '.js\');\n');
4242
});
4343

44-
fs.writeFileSync(scope.rootPath + '/api/services/Ember.js', "module.exports = require('sails-generate-ember-blueprints/templates/" + scope.flavor + "/api/services/Ember.js');\n");
44+
fs.writeFileSync(scope.rootPath + '/api/services/Ember.js', 'module.exports = require(\'sails-generate-ember-blueprints/templates/' + scope.flavor + '/api/services/Ember.js\');\n');
4545

4646
// @todo: check configuration options? Would be great if we could peek into the Sails project configuration and notify the developer about necessary changes
4747

4848
cb();
4949
}
50-
},
50+
}
5151
}
5252
};

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"email": "[email protected]"
88
},
99
"main": "lib/index.js",
10+
"scripts": {
11+
"test": "node tests/runner"
12+
},
1013
"homepage": "https://github.com/mphasize/sails-generate-ember-blueprints",
1114
"repository": {
1215
"type": "git",
@@ -30,6 +33,9 @@
3033
"merge-defaults": "^0.2.1"
3134
},
3235
"devDependencies": {
36+
"glob": "^5.0.5",
37+
"mocha": "^2.2.4",
38+
"mocha-eslint": "^0.1.4",
3339
"sails-generate": "*"
3440
},
3541
"sailsGenerator": {

tests/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"mocha": true
4+
}
5+
}

tests/runner.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*eslint no-process-exit:0*/
2+
'use strict';
3+
4+
var glob = require('glob');
5+
var Mocha = require('mocha');
6+
7+
var mocha = new Mocha({
8+
// For some reason, tests take a long time on Windows (or at least AppVeyor)
9+
timeout: (process.platform === 'win32') ? 30000 : 10000,
10+
reporter: 'spec'
11+
});
12+
13+
// Determine which tests to run based on argument passed to runner
14+
var arg = process.argv[2];
15+
var root;
16+
var files = '/**/*-test.js';
17+
if (!arg) {
18+
root = 'tests/{unit,acceptance}';
19+
} else if (arg === 'lint') {
20+
root = 'tests/unit';
21+
files = '/lint-test.js';
22+
} else {
23+
root = 'tests/{unit,acceptance}';
24+
}
25+
26+
function addFiles(mocha, files) {
27+
glob.sync(root + files).forEach(mocha.addFile.bind(mocha));
28+
}
29+
30+
addFiles(mocha, files);
31+
32+
mocha.run(function (failures) {
33+
process.on('exit', function () {
34+
process.exit(failures);
35+
});
36+
});

tests/unit/eslint-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
var lint = require('mocha-eslint');
4+
5+
var paths = [
6+
'bin/index.js',
7+
'lib',
8+
'tests'
9+
];
10+
11+
lint(paths);

0 commit comments

Comments
 (0)