ReferenceError: module is not defined - 使用Angular/Laravel应用程序的Karma/Jasmine配置

10 浏览
0 Comments

ReferenceError: module is not defined - 使用Angular/Laravel应用程序的Karma/Jasmine配置

我有一个现有的Angular/Laravel应用程序,其中Laravel作为Angular前端的API,仅提供JSON数据。加载Angular应用程序的页面index.php目前由Laravel提供。从那里,Angular接管。

我在尝试使用Karma/Jasmine启动时遇到了很大的困难。当我在项目的根目录下使用karma startkarma start karma.conf.js运行我的测试时,我会收到以下错误:

ReferenceError: module is not defined

完整输出:

INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
WARN [watcher]: Pattern "/Users/raph/coding/webroot/digitalocean/rugapp/public/rugapp/*.js" does not match any file.
INFO [Chrome 39.0.2171 (Mac OS X 10.9.5)]: Connected on socket 3OCUMp_xhrGtlGHwiosO with id 7897120
Chrome 39.0.2171 (Mac OS X 10.9.5) hello world encountered a declaration exception FAILED
    ReferenceError: module is not defined
        at Suite. (/Users/raph/coding/webroot/digitalocean/rugapp/tests/js/test.js:3:16)
        at jasmineInterface.describe (/Users/raph/coding/webroot/digitalocean/rugapp/node_modules/karma-jasmine/lib/boot.js:59:18)
        at /Users/raph/coding/webroot/digitalocean/rugapp/tests/js/test.js:1:1
Chrome 39.0.2171 (Mac OS X 10.9.5): Executed 2 of 2 (1 FAILED) (0.005 secs / 0.003 secs)

然而,Chrome浏览器确实启动,并显示如下内容:

enter image description here

我的karma.conf.js文件如下:

// Karma配置
// 生成于Mon Dec 22 2014 18:13:09 GMT-0500 (EST)
module.exports = function(config) {
  config.set({
    // 用于解析所有模式(文件、排除等)的基路径
    basePath: 'public/rugapp/',
    // 使用的框架
    // 可用框架:https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],
    // 加载到浏览器的文件/模式列表
    files: [
      '*.html',
      '**/*.js',
      '../../tests/js/test.js',
      '../../tests/js/angular/angular-mocks.js'
    ],
    // 要排除的文件列表
    exclude: [
    ],
    // 在提供给浏览器之前对匹配文件进行预处理
    // 可用的预处理器:https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },
    // 使用的测试结果报告器
    // 可能的值:'dots'、'progress'
    // 可用报告器:https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],
    // 网页服务器端口
    port: 9876,
    // 在输出(报告器和日志)中启用/禁用颜色
    colors: true,
    // 日志级别
    // 可能的值:config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,
    // 启用/禁用在任何文件更改时观察文件并执行测试
    autoWatch: true,
    // 启动这些浏览器
    // 可用的浏览器启动器:https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],
    // 持续集成模式
    // 如果为true,Karma会捕获浏览器、运行测试并退出
    singleRun: false
  });
};

我的package.json文件如下所示:

{

"devDependencies": {

"gulp": "^3.8.8",

"karma": "^0.12.28",

"karma-chrome-launcher": "^0.1.7",

"karma-jasmine": "^0.3.2",

"laravel-elixir": "*"

}

}

test.js

describe("hello world", function() {
    var CreateInvoiceController;
    beforeEach(module("MobileAngularUiExamples"));
    beforeEach(inject(function($controller) {
        CreateInvoiceController = $controller("CreateInvoiceController");
    }));
    describe("CreateInvoiceController", function() {
        it("Should say hello", function() {
            expect(CreateInvoiceController.message).toBe("Hello");
        });
    });
});
describe("true", function() {
    it("Should be true", function() {
        expect(true).toBeTruthy();
    });
});

非常感谢任何帮助。

0