-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ROADMAP.md: Add test generator to backlog. #2499
ROADMAP.md: Add test generator to backlog. #2499
Conversation
Implementation details: I believe that sails-generate-test should be built compositionally; for example If possible, each generator type could read the specified model/controller/whatever and generate tests for each method in that module. This may be possible if the sails global is available to the generator, by checking |
@jedd-ahyoung thanks! I rebased just now because I'd been dinking with the file, but it's in there :) |
@jedd-ahyoung my reactions below:
👍
👍 100% w/ you
Perfect- let's start with controllers/actions though?
tricky for anything but controllers currently (b/c javascript man- but check out http://node-machine.org/ for my proposed solution) |
Yeah, I'd like to help with this. I started on something a while back, here: https://github.com/jedd-ahyoung/sails-generate-test It's very rudimentary, and can't really be used yet, but I think it's a start, perhaps. What do you think? |
@jedd-ahyoung Apologies for the very late response to your excellent suggestion, Jedd. I'm in the process of cleaning up our roadmap, and so we have something on the books, I'd like to propose a watered down first pass here (we can always follow up once this is in place): Use CaseHistorically, testing with Sails has not been very opinionated-- it's largely been left up to the user. But after having written many hundreds of tests for Sails APIs, it became clear that a default setup for testing would make a great addition to the Sails CLI by default. Currently, initially setting up tests in a Sails app requires either some creative planning (if you've never done it), or repetitive copy & pasting (if you have). Rather than prescribing a particular test generator, let's be opinionated about the default test framework and go from there. Usage Summary$ sails new foo When a new Sails project is created, a ./foo
├── api/
├── assets/
├── ...
├── test/
│ ├── integration/
│ │ └── .gitkeep
│ ├── fixtures/
│ │ └── .gitkeep
│ ├── bootstrap.test.js
│ └── mocha.opts
└── views/ The test folder contains:
Then, out of the box, running Impact to Sails core
Documentation
Misc.
If anyone reading this would like to make refinements, clarifications, or corrections to the above (or has additional related ideas/comments), please reply in this pull request. Also please let me know about any confusing statements or typos. Thanks! |
I've been thinking a lot about adding this feature since months ago. As always, time is short. /**
* Mocha Test
*
*/
module.exports = function(grunt) {
grunt.config.set('mochaTest', {
test: {
options: {
reporter: 'list'
},
src: ['test/**/*.spec.js']
},
testdev: {
options: {
reporter: 'spec',
bail: true
},
src: ['test/**/*.spec.js']
}
});
grunt.loadNpmTasks('grunt-mocha-test');
}; and module.exports = function (grunt) {
grunt.registerTask('test', ['mochaTest']);
grunt.registerTask('testdev', ['mochaTest:testdev']);
}; For other projects we just changed our Gruntfile.js to look something like this: /*global module:false*/
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
// Task configuration.
jshint: {
// http://jshint.com/docs/options
options: {
// See http://jshint.com/docs/ for more details
"maxerr": 50, // {int} Maximum error before stopping
// Enforcing
"bitwise": true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase": false, // true: Identifiers must be in camelCase
"curly": true, // true: Require {} for every new block or scope
"eqeqeq": true, // true: Require triple equals (===) for comparison
"forin": false, // true: Require filtering for..in loops with obj.hasOwnProperty()
"freeze": true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"indent": 2, // {int} Number of spaces to use for indentation
"latedef": true, // true: Require variables/functions to be defined before being used
"newcap": false, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg": true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty": true, // true: Prohibit use of empty blocks
"nonbsp": true, // true: Prohibit "non-breaking whitespace" characters.
"nonew": true, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus": false, // true: Prohibit use of `++` and `--`
"quotmark": false, // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef": true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused": true, // Unused variables:
// true : all variables, last function parameter
// "vars" : all variables only
// "strict" : all variables, all function parameters
"strict": false, // true: Requires all functions run in ES5 Strict Mode
"maxparams": false, // {int} Max number of formal params allowed per function
"maxdepth": false, // {int} Max depth of nested blocks (within functions)
"maxstatements": false, // {int} Max number statements per function
"maxcomplexity": false, // {int} Max cyclomatic complexity per function
"maxlen": false, // {int} Max number of characters per line
// Relaxing
"asi": false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss": false, // true: Tolerate assignments where comparisons would be expected
"eqnull": false, // true: Tolerate use of `== null`
"funcscope": false, // true: Tolerate defining variables inside control statements
"validthis": false, // true: Tolerate using this in a non-constructor function
//reporter: require('jshint-stylish'),
force: false
},
gruntfile: {
globals: {
require: false
},
src: 'Gruntfile.js'
},
lib_test: {
options: {
node: true,
"globals": {
"sails": false,
"Node": false,
"describe": false,
"xdescribe": false,
"ddescribe": false,
"it": false,
"xit": false,
"iit": false,
"beforeEach": false,
"afterEach": false,
"expect": false,
"pending": false,
"should": false,
"spyOn": false
}
//reporter: require('jshint-stylish')
},
src: ['lib/**/*.js', 'test/**/*.spec.js']
}
},
mochaTest: {
test: {
options: {
reporter: 'spec',
timeout: 5000
},
src: ['test/**/*.spec.js']
}
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
lib_test: {
files: '<%= jshint.lib_test.src %>',
tasks: ['jshint:lib_test', 'mochaTest']
},
default: {
files: 'lib/**/*.js',
tasks: ['jshint']
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
//testing
grunt.registerTask('test', ['mochaTest']);
// Default task.
grunt.registerTask('default', ['jshint', 'test']);
}; Would you prefer this approach or just add the specific commands inside package.json? I would definitely implement this feature. |
btw, I really would like the idea of including jshint too. |
@luislobo thanks for the insight on how you guys do it, Luis. That's a cool solution and I think a lot of folks will benefit from seeing it. I'd like to get the most basic implementation as specced above completed first since it's the lowest common denominator for most teams' testing strategies. In general, I'm not sure if we can commit to maintaining more Grunt tasks as part of the default install of Sails, but I think that's ok- seems like what you're suggesting could be implemented in a pretty straightforward way as a generator (although a Grunt task might probably be easier to install). |
Add test generator to project backlog. Sorry if this is in the wrong repo - if it should be in a sails subrepository, let me know!