在服务器端运行Jasmine

7
我正在尝试使用Node.JS在服务器端测试JavaScript。 我正在使用gruntgrunt-jasmine-node,但我无法运行我的测试。 它只是记录下来:

PS C:\Development\NET\Source\jsn> grunt Running "jasmine_node" task undefined

Finished in 0.001 seconds 0 tests, 0 assertions, 0 failures

Done, without errors.

这是我的Gruntfile.js
module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        jasmine_node: {
            specNameMatcher: 'spec',
            projectRoot: '.',
            requirejs: false,
            forceExit: true,
            jUnit: {
                report: false,
                savePath : "./build/reports/jasmine/",
                useDotNotation: true,
                consolidate: true
            }
        }
    });

    grunt.loadNpmTasks('grunt-jasmine-node');
    grunt.registerTask('default', 'jasmine_node');
};

我的文件结构如下:

enter image description here

那么,我做错了什么?

就像 stub.js 文件从未被加载一样,因为它有一个 console.log 调用来测试。


我无法在这里帮助您解决问题,但作为替代方案,您可以尝试来自Grunt团队的Jasmine插件:https://github.com/gruntjs/grunt-contrib-jasmine。 - Felix Kling
grunt-contrib-jasmine 在浏览器中(PhantomJS)运行测试。它无法帮助在 node 上运行测试。 - johnmcase
1个回答

6

两种方法:

  • 确保你的javascript测试规范的扩展名为.spec.js

或者

  • 将配置选项specNameMatcher替换为matchall: true

1
我也是,我正在尝试在/specs/**/*.coffee中运行coffeescript测试,但我无法成功。有什么提示吗? - Edmondo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接