【问题标题】:Configure grunt watch to run Jasmine tests against an app using requirejs配置 grunt watch 以使用 requirejs 对应用程序运行 Jasmine 测试
【发布时间】:2013-10-10 18:01:25
【问题描述】:

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

组成的仅前端解决方案
  1. 杜兰达尔
  2. 茉莉花 - [通过 npm 添加]
  3. Grunt Watch 在我的代码文件更改时监控和运行我的测试 - [通过 npm 添加]

请随时纠正我,因为这一切都是基于我过去 2 天的实验。其中大部分对我来说都是新的。我的目标是拥有类似于 Angular 与业力的东西。

现在我知道 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问题我已经整理好了)

问题:

我将如何设置我的 gruntfile 以要求任何依赖项。我很陌生,我不确定如何配置它以使我的测试知道在哪里可以找到诸如 3rd 方库和其他自定义 js 文件之类的东西

【问题讨论】:

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


    【解决方案1】:

    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'
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2016-03-19
      • 2012-11-16
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-19
      • 2014-09-02
      相关资源
      最近更新 更多