【问题标题】:mean.io unit tests don't runmean.io 单元测试不运行
【发布时间】:2015-04-04 08:24:21
【问题描述】:

从一个全新的 mean.io 应用开始,即

mean init newApp
cd newApp
npm install [1]
bower install

[1] npm install --dev 导致 npm 永远运行并最终因内存不足错误而失败,因此我运行 npm install,然后为 devDependencies 中列出的每个包单独运行 npm install devPackage

gulp env:test mochaTest 的输出是

Invoking gulp - development
[10:12:54] Using gulpfile ~/projects/kueDemo/gulpfile.js
[10:12:54] Starting 'env:test'...
[10:12:54] Finished 'env:test' after 56 μs
[10:12:54] Starting 'loadTestSchema'...
[10:12:54] Finished 'loadTestSchema' after 487 ms
[10:12:54] Starting 'mochaTest'...


  0 passing (0ms)

[10:12:54] Finished 'mochaTest' after 48 ms

也没有测试失败,并且在 Article 包中肯定有很多测试要运行,所以我不明白为什么它们没有被选中。

注意:我必须按 CTRL-C 来停止 gulp 任务并返回提示符

应用程序本身运行良好,开箱即用。如果我运行 gulp test,Karma 测试运行良好—— mocha 测试仍然被忽略。

系统:

  • 节点 v0.12.2
  • npm v2.7.4
  • meanio v0.9.26

【问题讨论】:

    标签: gulp mocha.js mean.io


    【解决方案1】:

    好的,经过一些调试我发现这是mean.io源中的一个错误。

    gulp/test.js 中,以下几行应更改:

    第 20 行: require('../node_modules/meanio/lib/core_modules/module/util').preload('../p

    require('../node_modules/meanio/lib/core_modules/module/util').preload('./packages/**/server', 'model');
    

    类似的第 24 行:

    return gulp.src('../packages/**/server/tests/*.js', {read: false})
    

    return gulp.src('./packages/**/server/tests/*.js', {read: false})
    

    node_modules/meanio/lib/core_modules/module/util 预加载函数现在将失败,但您可以通过修补 walk 函数中的 2 个 realPath 行来解决此问题:

    // recursively walk modules path and callback for each file
    function walk(wpath, type, excludeDir, callback) {
      // regex - any chars, then dash type, 's' is optional, with .js or .coffee extension, case-insensitive
      // e.g. articles-MODEL.js or mypackage-routes.coffee
      var rgx = new RegExp('(.*)-' + type + '(s?).(js|coffee)$', 'i');
      if (!fs.existsSync(wpath)) return;
      fs.readdirSync(wpath).forEach(function(file) {
        var newPath = path.join(wpath, file);
        var stat = fs.statSync(newPath);
        if (stat.isFile() && (rgx.test(file) || (baseRgx.test(file)) && ~newPath.indexOf(type))) {
          var realPath = fs.realpathSync(newPath);
          callback(realPath);
        } else if (stat.isDirectory() && file !== excludeDir && ~newPath.indexOf(type)) {
          walk(newPath, type, excludeDir, callback);
        }
      });
    }
    

    【讨论】:

    猜你喜欢
    • 2013-04-07
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多