配置grunt watch以使用requirejs对应用程序运行Jasmine测试

时间:2013-10-10 09:05:55

标签: node.js requirejs durandal grunt-contrib-watch

试图提升我的一般编码技能......并学习新的东西。 我已经开始尝试连接仅由

组成的前端解决方案
  1. 迪朗达尔
  2. Jasmine - [通过npm添加]
  3. Grunt Watch to monitor&在我的代码文件发生变化时运行我的测试 - [通过npm添加]
  4. 随意纠正我,因为这完全取决于我在过去两天的实验。其中大部分对我来说都是新的。我的目标是拥有与业力角度相似的东西。

    现在我知道Durandal项目(带有自定义规范运行器,如github解决方案中所示)

    我的设置:

    gruntfile.js

        module.exports = function(grunt) {
        var appPath = 'App/viewmodels/*.js';
        var testPath = 'Tests/**/*.js';
        grunt.initConfig({
            jasmine:    {
                pivotal: {
                    src: appPath,
                    options: {
                        specs: testPath,
                        template: require('grunt-template-jasmine-requirejs'),
                        templateOptions: {
                          requireConfigFile: 'SpecRunner.js'
                        }
                    }
                }
            },
            jshint: {
                all: [testPath, appPath],
                options: {
                    curly: true
                }
            },
            watch: {
                files: [testPath, appPath], 
                tasks: ['jshint','jasmine']
            }   
        });
    
        grunt.loadNpmTasks('grunt-contrib-jasmine');
        grunt.loadNpmTasks('grunt-contrib-jshint');
        grunt.loadNpmTasks('grunt-contrib-watch');
    
        grunt.registerTask('default', ['jshint','jasmine']);    
    };
    

    SpecRunner.js

    require.config({
      paths: {
        jquery: 'Scripts/jquery-1.9.1',
        knockout: 'Scripts/knockout-2.3.0'
      },
      shim: {
        knockout: {
          exports: "ko"
        }
      }
    });
    

    当我运行grunt时,我收到一个非法路径或脚本错误:['plugins / http'] (我在截图中整理了ko问题) enter image description here

    问题:

    我如何设置我的gruntfile以要求任何依赖项。我很擅长要求,而且我不确定如何配置它以使我的测试知道在哪里可以找到第三方库和其他自定义js文件等内容

1 个答案:

答案 0 :(得分:2)

SpecRunner require.config缺少Durandal特定路径信息。如果将baseUrl设置为“App”,则下面的路径与HTML示例或StarterKit布局相匹配。如果你的布局不同,你必须相应地调整它。

requirejs.config({
    paths: {
        'text': '../lib/require/text',
        'durandal':'../lib/durandal/js',
        'plugins' : '../lib/durandal/js/plugins',
        'transitions' : '../lib/durandal/js/transitions',
        'knockout': '../lib/knockout/knockout-2.3.0',
        'bootstrap': '../lib/bootstrap/js/bootstrap',
        'jquery': '../lib/jquery/jquery-1.9.1'
    }
});