2016-05-18 11 views
0

私のNodeJSアプリケーション用の単体テストを設定してから、Jasmineを使ってそれらを実行する際に問題があるようです。この問題は、ジャスミンのdone機能を使用して発生します。私がテストにdone関数を含めると、次のエラーメッセージが表示されます。Warning: Cannot read property 'clearTimeout' of undefined Use --force to continue.私は何か正しいことをしていないと確信していますが、何かが私を逃れています。jasmine-nodejsとdone()を使って非同期テストを完了する

マイGruntfile.js:問題の

module.exports = function(grunt){ 
    // Load grunt tasks automatically 
    require('load-grunt-tasks')(grunt); 

    grunt.initConfig({ 
     // Make sure code styles are up to par and there are no obvious mistakes 
     jshint: { 
      options: { 
       jshintrc: '.jshintrc' 
      }, 
      all: [ 
       'Gruntfile.js', 
       'app/scripts/Directives/**/*.js', 
       'app/scripts/Services/**/*.js', 
       'app/scripts/app.js' 
      ] 
     }, 

     // Empties folders to start fresh 
     clean: { 
      options: { force: true }, 
      dist: { 
       files: [ 
        { 
         dot: true, 
         src: [ 
          '/dist/*' 
         ] 
        } 
       ] 
      }, 
      coverage: { 
       files: [ 
        { 
         dot: true, 
         src: [ 
          '.coverage/' 
         ] 
        } 
       ] 
      } 
     }, 

     // Copies remaining files to places other tasks can use 
     copy: { 
      dist: { 
       files: [ 
        { 
         expand: true, 
         dot: true, 
         cwd: '<%= yeoman.app %>', 
         dest: '<%= yeoman.dist %>', 
         src: [ 
          '*.{ico,png,txt,json,js,shtml,template}', 
          'images/{,*/}*.{webp}', 
          'fonts/*', 
          'images/**/*.svg', 
          'api-documentation/**/**/*', 
          'api-explorer/**/*', 
          'styles/*.{ttf,woff,svg,css}', 
          'docs/**/*', 
          'template/**/*.{htm,html}', 
          'locale/*', 
          'config/*' 
         ], 
         rename: function(dest, src){ 

          if(src.indexOf('customizations.html.template') !== -1 || 
           src.indexOf('customizations.js.template') !== -1){ 
           console.log(dest + '/' + src.replace('.template', '')); 
           return dest + '/' + src.replace('.template', ''); 
          } 

          return dest + '/' + src; 
         } 
        }, 
        { 
         expand: true, 
         cwd: '.tmp/images', 
         dest: '<%= yeoman.dist %>/images', 
         src: [ 
          'generated/*' 
         ] 
        }, 
        { 
         expand:true, 
         cwd: '.tmp/styles', 
         dest: '<%= yeoman.dist %>/styles', 
         src:['customer.css'] 
        } 
       ] 
      } 
     }, 

     // Test settings 
     karma: { 
      unit: { 
       configFile: 'karma.conf.js', 
       singleRun: true, 
       reporters: ['dots'] 
      }, 
      coverage: { 
       configFile: 'karma.coverage.conf.js', 
       singleRun: true, 
       reporters: ['spec', 'coverage'], 
       coverageReporter: { 
        type: 'html', 
        dir: '.coverage/' 
       } 
      }, 
      node:{ 
       configFile:'karma.node.conf.js', 
       singleRun:true, 
       reporters:['spec', 'coverage'], 
       coverageReporter: { 
        type: 'html', 
        dir: '.nodeCoverage/' 
       } 
      } 
     }, 

     open : { 
      coverage : { 
       path: 'http://127.0.0.1:8888/src' 
      }, 
      covReport: { 
       path: 'http://localhost:63342/ClassroomLibrary/' + grunt.file.expand('.coverage/Phantom*/index.html') 
      } 
     }, 

     jasmine_nodejs:{ 
      options:{ 
       specNameSuffix:'node.spec.js', 
       reporters:{ 
        console:{ 
         colors:true, 
         cleanStack:1, 
         verbosity:4, 
         listStyle:'indent', 
         activity:false 
        } 
       } 
      }, 
      all:{ 
       options:{ 
        useHelpers:true 
       }, 
       specs:[ 
        'tests/Node/**' 
       ] 
      } 
     }, 
     nodemon:{ 
      tests:{ 
       script:'app/index.js' 
      } 
     }, 
     concurrent:{ 
      nodeTests:['nodemon', 'jasmine_nodejs'] 
     }, 
     run_node:{ 
      start:{ 
       files:{src:['app/index.js']} 
      } 
     }, 
     stop_node:{ 
      stop:{ 
       files:{src:['app/index.js']} 
      } 
     } 
    }); 

    grunt.loadNpmTasks('grunt-jasmine-nodejs'); 
    grunt.loadNpmTasks('grunt-nodemon'); 
    grunt.loadNpmTasks('grunt-concurrent'); 
    grunt.loadNpmTasks('grunt-run-node'); 

    grunt.registerTask('test', [ 
     'karma:unit' 
    ]); 

    grunt.registerTask('coverage', [ 
     'clean:coverage', 
     'karma:coverage', 
     'open:covReport' 
    ]); 

    grunt.registerTask('nodeTests', ['concurrent:nodeTests']); 
    grunt.registerTask('testingNode', ['run_node', 'jasmine_nodejs', 'stop_node']); 
    //grunt.registerTask('karmaNode', ['run_node', 'karma:node', 'stop_node']); 
}; 

テストスイート:

明らか
var request = require('http'); 
describe('Node server', function(){ 
    'use strict'; 

    //http://www.randomjavascript.com/2012/12/using-jasmine-node-to-test-your-node.html 
    var serverUrl = 'http://127.0.0.1:2425'; 

    it('should respond to /', function(done){ 
     request.get(serverUrl, function(response){ 
      expect(response.statusCode).toBe(200); 
      done(); 
     }); 
    }); 
}); 

私はこの作業を取得するさまざまな方法をいくつか試してみました。カルマを介してそれらを実行することは、それが価値があった(私が試したことを示すためにそこにその設定を残した)よりも困難だった。 doneの機能がなくても、あなたが期待していたようにハングアップするからです。ちょうどそこにあるはずですが、私にとってはそうではありません。私のpackage.jsonは含まれています。プロセスは、それが必要なもの欠けているところ

{ 
    "name": "myProject", 
    "version": "0.0.1", 
    "dependencies":{}, 
    "devDependencies": { 
    "karma": "~0.13", 
    "karma-coverage": "~0.5", 
    "karma-phantomjs-launcher": "~1.0", 
    "karma-ng-html2js-preprocessor": "~0.1", 
    "phantomjs-prebuilt": "~2.1", 
    "grunt": "~1.0", 
    "grunt-contrib-clean": "~0.7", 
    "grunt-contrib-uglify": "~0.11", 
    "grunt-contrib-concat": "~0.5", 
    "grunt-contrib-copy": "~1.0", 
    "grunt-concurrent":"~2.3", 
    "grunt-jasmine-nodejs":"~1.5", 
    "grunt-jasmine-node-coverage":"0.5.0", 
    "grunt-open":"~0.2", 
    "grunt-nodemon":"~0.4", 
    "grunt-run-node":"~0.1", 
    "grunt-karma": "~0.12", 
    "jasmine-core": "~2.4", 
    "jasmine-node":"~1.14", 
    "karma-jasmine": "~0.3", 
    "karma-jasmine-matchers": "~2.0", 
    "karma-spec-reporter":"~0.0", 
    "karma-requirejs":"~1.0", 
    "load-grunt-tasks": "~3.4", 
    "uglify-js": "~2.6", 
    "grunt-sass": "~1.1", 
    "jshint":"~2.9" 
    }, 
    "engines": { 
    "node": ">=0.12.0" 
    }, 
    "scripts": { 
    "global": "npm i karma-cli grunt-cli -g" 
    } 
} 

誰かが私に教えていただけますか?

答えて

1

あなたが実際に使用しているジャスミンのバージョンが、あなたが使用しようとしているものと一致していることを確認できますか?私は `done 'コールバックが2.0で追加されたと思うので、古いバージョンでこのエラーが発生するのを見ることができました。

EDIT:バージョン1.3.1の" jasmine-node "機能が利用できないようにします。

+0

良いキャッチ!私はそこを見ていなかった。 – MBielski

関連する問題