业力找不到文件

karma not finding files

此应用程序构建于 Visual Studio 2013 年,使用 gulpJs 进行捆绑、缩小和 运行ning js 测试。我可以通过右键单击测试项目中的 html 文件和 'View in Browser' 来 运行 我的测试。当我 运行 启动 karma 的 gulp 任务时,浏览器打开并且出现错误:

 ReferenceError: angular is not defined
    at Suite.<anonymous> (C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/billingAddressController.spec.js:5:16)

这是我的 karma.conf.js

module.exports = function (config) {
    config.set({
        browsers: ['Chrome'],
        frameworks: ['jasmine'],
        files: [
            './../../eStore.JS.Specs/Tools/angular.min.js',
            './../../eStore.JS.Specs/Tools/angular-mocks.js',
            './Scripts/**/*.js',
            './../../eStore.JS.Specs/**/*.spec.js'
        ],
        logLevel: config.LOG_DEBUG,
        autoWatch: true,
        singleRun: false
    });
};

这是我的 gulp.js 测试任务:

var testFiles = '../../eStore.JS.Specs/**/*.spec.js';

gulp.task('test', function () {
    gulp.src(testFiles)
        .pipe(karma({
                configFile: './karma.conf.js',
                action: 'run'
            })
            .on('error', errorHandler));
});

似乎 karma 正在请求我所有的规范文件,但我没有看到对 angular、angular-mocks 或我正在测试的 JS 文件的请求。这是业力输出:

17 09 2015 16:18:33.827:DEBUG [plugin]: Loading karma-* from C:\Dev\eStoreNextGen\eStore-branch-F2\eStore\Web\eStore\node_modules
17 09 2015 16:18:33.832:DEBUG [plugin]: Loading plugin C:\Dev\eStoreNextGen\eStore-branch-F2\eStore\Web\eStore\node_modules/karma-chrome-launcher.
17 09 2015 16:18:33.846:DEBUG [plugin]: Loading plugin C:\Dev\eStoreNextGen\eStore-branch-F2\eStore\Web\eStore\node_modules/karma-jasmine.
17 09 2015 16:18:33.915:WARN [karma]: Port 9876 in use
17 09 2015 16:18:33.916:INFO [karma]: Karma v0.13.9 server started at http://localhost:9877/
17 09 2015 16:18:33.931:INFO [launcher]: Starting browser Chrome
17 09 2015 16:18:33.932:DEBUG [temp-dir]: Creating temp dir at C:\Users\lanry001\AppData\Local\Temp\karma-82999076
17 09 2015 16:18:33.933:DEBUG [launcher]: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --user-data-dir=C:\Users\lanry001\AppData\Local\Temp\karma-82999076 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate http://localhost:9877/?id=82999076
17 09 2015 16:18:36.120:DEBUG [web-server]: serving: C:\Dev\eStoreNextGen\eStore-branch-F2\eStore\Web\eStore\node_modules\karma\static/client.html
17 09 2015 16:18:36.169:DEBUG [web-server]: serving: C:\Dev\eStoreNextGen\eStore-branch-F2\eStore\Web\eStore\node_modules\karma\static/karma.js
17 09 2015 16:18:36.268:DEBUG [karma]: A browser has connected on socket KC-_aUVr3iMH3R9aAAAA
17 09 2015 16:18:36.270:DEBUG [web-server]: serving: C:\Dev\eStoreNextGen\eStore-branch-F2\eStore\Web\eStore\node_modules\karma\static/favicon.ico
17 09 2015 16:18:36.278:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=KC-_aUVr3iMH3R9aAAAA
17 09 2015 16:18:36.336:INFO [Chrome 45.0.2454 (Windows 7 0.0.0)]: Connected on socket KC-_aUVr3iMH3R9aAAAA with id 82999076
17 09 2015 16:18:36.337:DEBUG [launcher]: Chrome (id 82999076) captured in 2.421 secs
17 09 2015 16:18:36.375:DEBUG [web-server]: serving: C:\Dev\eStoreNextGen\eStore-branch-F2\eStore\Web\eStore\node_modules\karma\static/context.html
17 09 2015 16:18:36.392:DEBUG [middlware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?578a1e5ff14db21b04e2d6db7fd0eda37042440c /
17 09 2015 16:18:36.393:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/Web/eStore/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
17 09 2015 16:18:36.396:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/Web/eStore/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
17 09 2015 16:18:36.400:DEBUG [middlware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?4a7da64f416169520c9d5c43b5a7feac6bde9104 /
17 09 2015 16:18:36.401:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/Web/eStore/node_modules/karma-jasmine/lib/boot.js
17 09 2015 16:18:36.402:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/Web/eStore/node_modules/karma-jasmine/lib/boot.js
17 09 2015 16:18:36.403:DEBUG [middlware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?3030709c83121e1b2ca4d1e657306b834fc13350 /
17 09 2015 16:18:36.403:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/Web/eStore/node_modules/karma-jasmine/lib/adapter.js
17 09 2015 16:18:36.404:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/Web/eStore/node_modules/karma-jasmine/lib/adapter.js
17 09 2015 16:18:36.411:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/billingAddressController.spec.js?77fb3fd410364a99aa9b97857e540429cb6c1cdd /
17 09 2015 16:18:36.411:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/billingAddressController.spec.js
17 09 2015 16:18:36.412:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/billingAddressController.spec.js
17 09 2015 16:18:36.417:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/continueCheckoutController.spec.js?d2bf9c9b3c195931ee577cb02376e3bc031b69f5 /
17 09 2015 16:18:36.417:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/continueCheckoutController.spec.js
17 09 2015 16:18:36.418:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/continueCheckoutController.spec.js
17 09 2015 16:18:36.420:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/paymentController.spec.js?7b1a0f34f75d121e380045ebbf27a05a90aa2ef6 /
17 09 2015 16:18:36.420:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/paymentController.spec.js
17 09 2015 16:18:36.421:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/paymentController.spec.js
17 09 2015 16:18:36.426:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewBillingController.spec.js?d1dd4012eb89d012c0624bd3c1edc2d2d7bc8dc4 /
17 09 2015 16:18:36.427:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewBillingController.spec.js
17 09 2015 16:18:36.427:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewBillingController.spec.js
17 09 2015 16:18:36.429:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewCartController.spec.js?8deeec6e6290d578724508625dccfb2db8aa1731 /
17 09 2015 16:18:36.430:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewCartController.spec.js
17 09 2015 16:18:36.431:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewCartController.spec.js
17 09 2015 16:18:36.441:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewShippingController.spec.js?0de14d74b1d27dbb3f2a2e9874885d19f891e229 /
17 09 2015 16:18:36.441:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewShippingController.spec.js
17 09 2015 16:18:36.442:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/reviewShippingController.spec.js
17 09 2015 16:18:36.447:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/shippingAddressController.spec.js?768216b5b1fab88b00382cecc077f75e0b5d63e6 /
17 09 2015 16:18:36.449:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/shippingAddressController.spec.js
17 09 2015 16:18:36.451:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/shippingAddressController.spec.js
17 09 2015 16:18:36.454:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/shippingOptionsController.spec.js?e9833a1fd1cebf78843f35c719f1f34fff75b7cd /
17 09 2015 16:18:36.454:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/shippingOptionsController.spec.js
17 09 2015 16:18:36.456:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/shippingOptionsController.spec.js
17 09 2015 16:18:36.457:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/submitOrderController.spec.js?de0f526507cc7cc74705aec4de7be4e83f0d4e7c /
17 09 2015 16:18:36.457:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/submitOrderController.spec.js
17 09 2015 16:18:36.458:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/submitOrderController.spec.js
17 09 2015 16:18:36.460:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/addressSelectorController.spec.js?3d88eef3c2edbcd652206271c3d7a7debac3d603 /
17 09 2015 16:18:36.460:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/addressSelectorController.spec.js
17 09 2015 16:18:36.463:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/addressSelectorController.spec.js
17 09 2015 16:18:36.466:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/cartController.spec.js?99de5adfa7d042b7621e7fc2abd5cc01df58e8c7 /
17 09 2015 16:18:36.467:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/cartController.spec.js
17 09 2015 16:18:36.467:DEBUG [middlware:source-files]: Requesting /absoluteC:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/departmentListController.spec.js?732b464f4d7a2a2ef8a8e72f03911ed82518e384 /
17 09 2015 16:18:36.468:DEBUG [middlware:source-files]: Fetching C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/departmentListController.spec.js
17 09 2015 16:18:36.468:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/cartController.spec.js
17 09 2015 16:18:36.471:DEBUG [web-server]: serving (cached): C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Common/departmentListController.spec.js
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 0 of 12 SUCCESS (0 secs / 0 secs)
Chrome 45.0.2454 (Windows 7 0.0.0)  encountered a declaration exception FAILED
    ReferenceError: angular is not defined
        at Suite.<anonymous> (C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/billingAddressController.spec.js:5:16)
        at C:/Dev/eStoreNextGen/eStore-branch-F2/eStore/eStore.JS.Specs/Checkout/billingAddressController.spec.js:4:1
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 12 (1 FAILED) (0 secs / 0.008 secs)
Chrome 45.0.2454 (Windows 7 0.0.0)  encountered a declaration exception FAILED

作为参考,这是我的 HTML 规范 运行ner(有效):

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Jasmine Spec Runner</title>

    <link rel="shortcut icon" type="image/png" href="Tools/jasmine-2.3.4/jasmine_favicon.png">
    <link rel="stylesheet" type="text/css" href="Tools/jasmine-2.3.4/jasmine.css">
    <script src="Tools/jasmine-2.3.4/jasmine.js"></script>
    <script src="Tools/jasmine-2.3.4/jasmine-html.js"></script>
    <script src="Tools/jasmine-2.3.4/boot.js"></script>
    <script src="Tools/angular.min.js"></script>
    <script src="Tools/angular-block-ui.min.js"></script>
    <script src="Tools/angular-mocks.js"></script>
    <script src="Tools/angular-route.min.js"></script>
    <script src="Tools/jquery-1.11.3.min.js"></script>
    <script src="Tools/sinon-1.16.1.js"></script>
    <script src="Tools/sinon-stub-promise.js"></script>
    <script src="Tools/ui-bootstrap-tpls-0.13.4.min.js"></script>
    <script src="Tools/underscore.min.js"></script>

    <!-- angular modules -->
    <script src="../web/estore/Scripts/Common/underscoreApp.js"></script>
    <script src="../web/estore/Scripts/Common/directives/dccdirectivesapp.js"></script>
    <script src="../web/estore/Scripts/eStoreApp.js"></script>
    <script src="../web/estore/Scripts/lib/angular-block-ui.min.js"></script>

    <!-- angular app files -->
    <script src="../web/estore/Scripts/Checkout/AddressSelector/addressSelectorController.js"></script>
    <script src="../web/estore/Scripts/Checkout/BillingAddress/billingAddressController.js"></script>
    <script src="../web/estore/Scripts/Checkout/BillingAddress/billingAddressService.js"></script>
    <script src="../web/estore/Scripts/Checkout/checkoutData.js"></script>
    <script src="../web/estore/Scripts/Checkout/checkoutValidation.js"></script>
    <script src="../web/estore/Scripts/Checkout/ContinueCheckout/continueCheckoutController.js"></script>
    <script src="../web/estore/Scripts/Checkout/Payment/paymentController.js"></script>
    <script src="../web/estore/Scripts/Checkout/ReviewBilling/reviewBillingController.js"></script>
    <script src="../web/estore/Scripts/Checkout/ReviewCart/reviewCartController.js"></script>
    <script src="../web/estore/Scripts/Checkout/ReviewShipping/reviewShippingController.js"></script>
    <script src="../web/estore/Scripts/Checkout/ShippingAddress/shippingAddressController.js"></script>
    <script src="../web/estore/Scripts/Checkout/ShippingAddress/shippingAddressService.js"></script>
    <script src="../web/estore/Scripts/Checkout/ShippingOptions/shippingOptionsController.js"></script>
    <script src="../web/estore/Scripts/Checkout/ShippingOptions/shippingOptionsService.js"></script>
    <script src="../web/estore/Scripts/Checkout/SubmitOrder/submitOrderController.js"></script>
    <script src="../web/estore/Scripts/Checkout/SubmitOrder/submitOrderService.js"></script>
    <script src="../web/estore/Scripts/Common/Directives/cart/cartController.js"></script>
    <script src="../web/estore/Scripts/Common/Directives/navigation/departmentListController.js"></script>
    <script src="../web/estore/Scripts/Common/Directives/Navigation/departmentService.js"></script>
    <script src="../web/estore/Scripts/Common/Directives/navigation/navigationController.js"></script>
    <script src="../web/estore/Scripts/Common/Services/addressService.js"></script>
    <script src="../web/estore/Scripts/Common/Services/cartservice.js"></script>
    <script src="../web/estore/Scripts/Common/Services/dateService.js"></script>
    <script src="../web/estore/Scripts/Common/Services/pageContentTranslationService.js"></script>
    <script src="../web/estore/Scripts/Common/Services/sessionService.js"></script>
    <script src="../web/estore/Scripts/Common/Services/settingsService.js"></script>

    <!-- test files -->
    <script src="Checkout/billingAddressController.spec.js"></script>
    <script src="Checkout/continuecheckoutcontroller.spec.js"></script>
    <script src="Checkout/paymentController.spec.js"></script>
    <script src="Checkout/reviewBillingController.spec.js"></script>
    <script src="Checkout/reviewShippingController.spec.js"></script>
    <script src="Checkout/reviewCartController.spec.js"></script>
    <script src="Checkout/shippingAddressController.spec.js"></script>
    <script src="Checkout/shippingOptionsController.spec.js"></script>
    <script src="Checkout/submitOrderController.spec.js"></script>
    <script src="Common/addressSelectorController.spec.js"></script>
    <script src="Common/cartController.spec.js"></script>
    <script src="Common/departmentListController.spec.js"></script>
</head>
<body>

</body>
</html>

在您的 gulp 任务中,替换:

configFile: './karma.conf.js'

与:

configFile: path.join(__dirname, './karma.conf.js')

假设您有:

var path = require('path'); 

使用包 'karma' 中的 server.start 而不是 'gulp-karma' 包。

var karma = require('karma').server;

karma.start({
    configFile: __dirname + '/karma.conf.js',
}, karmaCompleted);

function karmaCompleted(karmaResult) {
    log('Karma completed');
    if (karmaResult === 1) {
        done('karma: tests failed with code ' + karmaResult);
    } else {
        done();
    }
}