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

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

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

的前端解决方案
  1. Durandal
  2. Jasmine - [通过 npm 添加]
  3. Grunt Watch 在我的代码文件更改时监控和运行我的测试 - [通过 npm 添加]

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

现在我知道 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 来需要任何依赖项。我对 require 还很陌生,我不知道如何配置它以使我的测试知道在哪里可以找到诸如第 3 方库和其他自定义 js 文件之类的东西

最佳答案

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

关于node.js - 配置 grunt watch 以使用 requirejs 对应用程序运行 Jasmine 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19291488/

相关文章:

requirejs - 路径配置文件中的文本文件

javascript - 在 require.js data-main 上过期缓存

javascript - SignalR & require.js 配置

asp.net-mvc-3 - 撰写主要内容后,Durandal 不撰写页脚 View

javascript - 地铁用户界面 CSS : How to achieve class ="active" effect?

javascript - Breeze.js - 尝试使用 "any"运算符时出错 - 错误 : Unable to get value of the property 'isAnonymous' : object is null or undefined

javascript - Sequelize 查询 SELECT * FROM Table 只返回一行

javascript - 类型错误 : circular structure to JSON starting at object with constructor 'ClientRequest' property 'socket' -> object with constructor 'Socket'

javascript - 在 Node.js 项目中使用 jquery 发出 api 请求

node.js - MongoDB 和 i18n