Skip to content
This repository
Browse code

Merge pull request #669 from jgrund/server-task-config

#530 Make server tasks configurable.
  • Loading branch information...
commit 6b0f3289381ffb6ae496a48f4188cfe0988e3e8a 2 parents 448968e + 110dee8
Sindre Sorhus sindresorhus authored
3  cli/tasks/server.js
@@ -270,8 +270,7 @@ module.exports = function(grunt) {
270 270 open( 'http://' + opts.hostname + ':' + opts.port );
271 271 }
272 272 });
273   -
274   - grunt.task.run( tasks[target] );
  273 + grunt.task.run(grunt.config('server.' + target) || tasks[target]);
275 274 });
276 275
277 276 grunt.registerHelper('server', function(opts, cb) {
7 cli/test/helpers/index.js
@@ -120,16 +120,21 @@ helpers.yeoman = function (cmds, takeOver) {
120 120 // }));
121 121 //
122 122 // Returns a function suitable to use with mocha hooks.
123   -helpers.gruntfile = function(options) {
  123 +helpers.gruntfile = function(options, taskMap) {
124 124 return function gruntfile(done) {
125 125 var config = 'grunt.initConfig(' + JSON.stringify(options, null, 2) + ');';
126 126 config = config.split('\n').map(function(line) {
127 127 return ' ' + line;
128 128 }).join('\n');
129 129
  130 + var tasks = Object.keys(taskMap || {}).map(function(key) {
  131 + return '\ngrunt.registerTask(\'' + key + '\', ' + taskMap[key] + ');';
  132 + }).join('\n');
  133 +
130 134 var out = [
131 135 'module.exports = function(grunt) {',
132 136 config,
  137 + tasks,
133 138 '};'
134 139 ];
135 140
42 cli/test/test-server.js
... ... @@ -0,0 +1,42 @@
  1 +/*global describe, before, after, beforeEach, afterEach, describe, it */
  2 +var helpers = require('./helpers');
  3 +var grunt = require('grunt');
  4 +var assert = require('assert');
  5 +var fs = require('fs');
  6 +
  7 +describe('yeoman server', function() {
  8 + before(helpers.directory('.test'));
  9 +
  10 + describe('When I run the app server with a customized task', function () {
  11 + var options = {
  12 + server: {
  13 + app: 'testTask'
  14 + }
  15 + };
  16 + var tasks = {
  17 + 'testTask': function () {
  18 + grunt.file.write('test_task/test.js', '"testing custom task"');
  19 + }
  20 + };
  21 +
  22 + before(helpers.gruntfile(options, tasks));
  23 +
  24 + before(function(done) {
  25 + this.yeoman = helpers.run('server:app --no-color', {redirect: true})
  26 + .expect(0)
  27 + .end(done);
  28 + });
  29 +
  30 + it('should generate a testTask directory', function(done) {
  31 + fs.stat('test_task/', done);
  32 + });
  33 +
  34 + it('should generate a test.js file', function(done) {
  35 + fs.stat('test_task/test.js', done);
  36 + });
  37 +
  38 + it('should write the content from the task to the test file', function() {
  39 + assert.equal(grunt.file.read('test_task/test.js'), '"testing custom task"');
  40 + });
  41 + });
  42 +});

0 comments on commit 6b0f328

Please sign in to comment.
Something went wrong with that request. Please try again.