2013-07-05 1 views
3

Yeoman 생성기를 사용하여 백본 프로젝트를 설정했습니다.yeoman generator 자동 실행 테스트

Gruntfile에는 많은 자료를 실행하지만 livereload를 실행하는 server라는 작업이 있습니다. test라고하는 또 다른 작업이 있지만 테스트는 거의 동일하게 실행되지만 테스트는 한 번만 실행되고 라이브로드는 실행되지 않습니다.

워크 플로우와 관련하여 다소 혼란 스럽습니다. 하나의 터미널 창에서 서버를 실행할 수 없으며 같은 포트를 사용하기 때문에 다른 터미널 창에서 테스트를 실행할 수 없습니다.

매번 테스트를 실행하기 위해 서버를 계속 중지해야하는 것처럼 보입니다.

파일을 변경하고 앱을 다시로드 할 때마다 테스트가 자동으로 실행되도록 설정하려면 어떻게해야합니까? 여기

가 gruntfile (발전기 기본값) : 경우

'use strict'; 
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet; 
var mountFolder = function (connect, dir) { 
    return connect.static(require('path').resolve(dir)); 
}; 

// # Globbing 
// for performance reasons we're only matching one level down: 
// 'test/spec/{,*/}*.js' 
// use this if you want to match all subfolders: 
// 'test/spec/**/*.js' 
// templateFramework: 'handlebars' 

module.exports = function (grunt) { 
    // load all grunt tasks 
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); 

    // configurable paths 
    var yeomanConfig = { 
     app: 'app', 
     dist: 'dist' 
    }; 

    grunt.initConfig({ 
     yeoman: yeomanConfig, 
     watch: { 
      coffee: { 
       files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'], 
       tasks: ['coffee:dist'] 
      }, 
      coffeeTest: { 
       files: ['test/spec/{,*/}*.coffee'], 
       tasks: ['coffee:test'] 
      }, 
      compass: { 
       files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'], 
       tasks: ['compass'] 
      }, 
      express: { 
       files:[ 
        '<%= yeoman.app %>/*.html', 
        '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css', 
        '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js', 
        '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}' 
       ], 
       tasks: [ 'express:dev', 'livereload' ] 
      }, 
      livereload: { 
       files: [ 
        '<%= yeoman.app %>/*.html', 
        '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css', 
        '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js', 
        '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}' 
       ], 
       tasks: ['livereload'] 
      }, 
      handlebars: { 
       files: [ 
        '<%= yeoman.app %>/scripts/templates/*.hbs' 
       ], 
       tasks: ['handlebars'] 
      } 
     }, 
     connect: { 
      options: { 
       port: 9000, 
       // change this to '0.0.0.0' to access the server from outside 
       hostname: 'localhost' 
      }, 
      livereload: { 
       options: { 
        middleware: function (connect) { 
         return [ 
          lrSnippet, 
          mountFolder(connect, '.tmp'), 
          mountFolder(connect, 'app') 
         ]; 
        } 
       } 
      }, 
      test: { 
       options: { 
        middleware: function (connect) { 
         return [ 
          mountFolder(connect, '.tmp'), 
          mountFolder(connect, 'test') 
         ]; 
        } 
       } 
      }, 
      dist: { 
       options: { 
        middleware: function (connect) { 
         return [ 
          mountFolder(connect, 'dist') 
         ]; 
        } 
       } 
      } 
     }, 
     express: { 
      options: { 
       // Override defaults here 
       port: '<%= connect.options.port %>' 
      }, 
      dev: { 
       options: { 
        script: 'server/app.js' 
       } 
      }, 
      prod: { 
       options: { 
        script: 'server/app.js' 
       } 
      }, 
      test: { 
       options: { 
        script: 'server/app.js' 
       } 
      } 
     }, 
     open: { 
      server: { 
       path: 'http://localhost:<%= connect.options.port %>' 
      } 
     }, 
     clean: { 
      dist: ['.tmp', '<%= yeoman.dist %>/*'], 
      server: '.tmp' 
     }, 
     jshint: { 
      options: { 
       jshintrc: '.jshintrc' 
      }, 
      all: [ 
       'Gruntfile.js', 
       '<%= yeoman.app %>/scripts/{,*/}*.js', 
       '!<%= yeoman.app %>/scripts/vendor/*', 
       'test/spec/{,*/}*.js' 
      ] 
     }, 
     mocha: { 
      all: { 
       options: { 
        run: true, 
        urls: ['http://localhost:<%= connect.options.port %>/index.html'] 
       } 
      } 
     }, 
     coffee: { 
      dist: { 
       files: [{ 
        // rather than compiling multiple files here you should 
        // require them into your main .coffee file 
        expand: true, 
        cwd: '<%= yeoman.app %>/scripts', 
        src: '*.coffee', 
        dest: '.tmp/scripts', 
        ext: '.js' 
       }] 
      }, 
      test: { 
       files: [{ 
        expand: true, 
        cwd: '.tmp/spec', 
        src: '*.coffee', 
        dest: 'test/spec' 
       }] 
      } 
     }, 
     compass: { 
      options: { 
       sassDir: '<%= yeoman.app %>/styles', 
       cssDir: '.tmp/styles', 
       imagesDir: '<%= yeoman.app %>/images', 
       javascriptsDir: '<%= yeoman.app %>/scripts', 
       fontsDir: '<%= yeoman.app %>/styles/fonts', 
       importPath: 'app/bower_components', 
       relativeAssets: true 
      }, 
      dist: {}, 
      server: { 
       options: { 
        debugInfo: true 
       } 
      } 
     }, 
     requirejs: { 
      dist: { 
       // Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js 
       options: { 
        // `name` and `out` is set by grunt-usemin 
        baseUrl: 'app/scripts', 
        optimize: 'none', 
        paths: { 
         'templates': '../../.tmp/scripts/templates' 
        }, 
        // TODO: Figure out how to make sourcemaps work with grunt-usemin 
        // https://github.com/yeoman/grunt-usemin/issues/30 
        //generateSourceMaps: true, 
        // required to support SourceMaps 
        // http://requirejs.org/docs/errors.html#sourcemapcomments 
        preserveLicenseComments: false, 
        useStrict: true, 
        wrap: true, 
        //uglify2: {} // https://github.com/mishoo/UglifyJS2 
       } 
      } 
     }, 
     useminPrepare: { 
      html: '<%= yeoman.app %>/index.html', 
      options: { 
       dest: '<%= yeoman.dist %>' 
      } 
     }, 
     usemin: { 
      html: ['<%= yeoman.dist %>/{,*/}*.html'], 
      css: ['<%= yeoman.dist %>/styles/{,*/}*.css'], 
      options: { 
       dirs: ['<%= yeoman.dist %>'] 
      } 
     }, 
     imagemin: { 
      dist: { 
       files: [{ 
        expand: true, 
        cwd: '<%= yeoman.app %>/images', 
        src: '{,*/}*.{png,jpg,jpeg}', 
        dest: '<%= yeoman.dist %>/images' 
       }] 
      } 
     }, 
     cssmin: { 
      dist: { 
       files: { 
        '<%= yeoman.dist %>/styles/main.css': [ 
         '.tmp/styles/{,*/}*.css', 
         '<%= yeoman.app %>/styles/{,*/}*.css' 
        ] 
       } 
      } 
     }, 
     htmlmin: { 
      dist: { 
       options: { 
        /*removeCommentsFromCDATA: true, 
        // https://github.com/yeoman/grunt-usemin/issues/44 
        //collapseWhitespace: true, 
        collapseBooleanAttributes: true, 
        removeAttributeQuotes: true, 
        removeRedundantAttributes: true, 
        useShortDoctype: true, 
        removeEmptyAttributes: true, 
        removeOptionalTags: true*/ 
       }, 
       files: [{ 
        expand: true, 
        cwd: '<%= yeoman.app %>', 
        src: '*.html', 
        dest: '<%= yeoman.dist %>' 
       }] 
      } 
     }, 
     copy: { 
      dist: { 
       files: [{ 
        expand: true, 
        dot: true, 
        cwd: '<%= yeoman.app %>', 
        dest: '<%= yeoman.dist %>', 
        src: [ 
         '*.{ico,txt}', 
         '.htaccess', 
         'images/{,*/}*.{webp,gif}' 
        ] 
       }] 
      } 
     }, 
     bower: { 
      all: { 
       rjsConfig: '<%= yeoman.app %>/scripts/main.js' 
      } 
     }, 
     handlebars: { 
      compile: { 
       options: { 
        namespace: 'JST', 
        amd: true 
       }, 
       files: { 
        '.tmp/scripts/templates.js': ['<%= yeoman.app %>/scripts/templates/*.hbs'] 
       } 
      } 
     } 
    }); 

    grunt.renameTask('regarde', 'watch'); 

    grunt.registerTask('createDefaultTemplate', function() { 
     grunt.file.write('.tmp/scripts/templates.js', 'this.JST = this.JST || {};'); 
    }); 

    grunt.registerTask('server', function (target) { 
     if (target === 'dist') { 
      return grunt.task.run(['build', 'open', 'connect:dist:keepalive']); 
     } 

     grunt.task.run([ 
      'clean:server', 
      'coffee:dist', 
      'createDefaultTemplate', 
      'handlebars', 
      'compass:server', 
      'livereload-start', 
      'connect:livereload', 
      'open', 
      'watch' 
     ]); 
    }); 

    grunt.registerTask('expressserver', function (target) { 
     if (target === 'dist') { 
      return grunt.task.run(['build', 'open', 'connect:dist:keepalive']); 
     } 

     grunt.task.run([ 
      'clean:server', 
      'coffee:dist', 
      'createDefaultTemplate', 
      'handlebars', 
      'compass:server', 
      'express:dev', 
      'livereload-start', 
      'open', 
      'watch' 
     ]); 
    }); 

    grunt.registerTask('test', [ 
     'clean:server', 
     'coffee', 
     'createDefaultTemplate', 
     'handlebars', 
     'compass', 
     'connect:test', 
     'mocha' 
    ]); 

    grunt.registerTask('build', [ 
     'clean:dist', 
     'coffee', 
     'createDefaultTemplate', 
     'handlebars', 
     'compass:dist', 
     'useminPrepare', 
     'requirejs', 
     'imagemin', 
     'htmlmin', 
     'concat', 
     'cssmin', 
     'uglify', 
     'copy', 
     'usemin' 
    ]); 

    grunt.registerTask('default', [ 
     'jshint', 
     'test', 
     'build' 
    ]); 
}; 

답변

0

당신이 backbone-generator 사용하고, 우리는 지금 그 기능이 없습니다. 하지만 앞으로 우리가 추가 할 기능 중 하나 일 것입니다.

그 때까지는 Gruntfile 및 like this에서 몇 가지 조정할 수 있습니다. 그 비틀기를 들어 당신은 당신이 브라우저에서 인 test.html 열립니다 grunt server:test을 실행하면 이제

을 test.html를 위해 테스트 디렉토리에서 index.html을 이름을 변경 할 필요가 작동합니다.

동시에 서버와 테스트를 사용하는 포트 문제와 관련하여 지금 당장은 어떤 해결책이 있는지 잘 모릅니다. 그러나 하나를 찾고 여기에서 업데이트하려고합니다.