在Bitbucket管道上运行的Karma测试给出错误“无法找到变量角度(和模块)”

问题描述 投票:1回答:1

我正在尝试让Bitbucket管道为我的MEAN堆栈应用程序工作。

所以我将MEAN堆栈框架克隆到我的Bitbucket https://github.com/linnovate/mean并添加了以下bitbucket-pipelines.yml:

# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:6.9.4

definitions: 
  services: 
    mongo: 
      image: mongo

pipelines:
  default:
    - step:
        caches:
          - node
        script: # Modify the commands below to build your repository.
          - npm install
          - npm test
        services: 
          - mongo
        deployment: test

但是当我运行测试时,我收到以下错误消息(请参阅pastebin https://pastebin.com/TY6sBigB):

[36m06 03 2019 04:18:12.764:DEBUG [phantomjs.launcher]: [39mReferenceError: Can't find variable: angular

  http://localhost:9876/base/modules/users/client/views/settings/settings.client.view.html.js?7d60b7bc1406b1321039f3ea5f1c798982967142:5

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  An error was thrown in afterAll
  ReferenceError: Can't find variable: module in modules/articles/tests/client/list-articles.client.controller.tests.js (line 34)
  modules/articles/tests/client/list-articles.client.controller.tests.js:34:22
  <Jasmine>
  modules/articles/tests/client/list-articles.client.controller.tests.js:4:11
  <Jasmine>

Finished in 0.041 secs / 0 secs @ 04:18:12 GMT+0000 (UTC)

缺少的“模块”错误似乎出现在(admin.articles.client.routes.tests.js):

(function () {
  'use strict';

  describe('Articles Route Tests', function () {
    // Initialize global variables
    var $scope,
      ArticlesService;

    // We can start by loading the main application module
    beforeEach(module(ApplicationConfiguration.applicationModuleName));

'module'变量是@Types模块中定义的全局变量,但我不确定这是如何导致错误的。

丢失的'angular'变量发生在:(articles.client.service.js)

(function () {
  'use strict';

  angular
    .module('articles.services')
    .factory('ArticlesService', ArticlesService);

哪个是angular typescript文件中定义的命名空间:export as namespace angular;

这是我的业力配置文件:https://pastebin.com/MVYyXAzV

还有我的package.json:https://pastebin.com/GEvTSi2A

karma-runner bitbucket-pipelines
1个回答
0
投票

您需要为package.json文件添加角度。尝试npm install angular然后提交你的package.json并推送到你的回购。

可能看起来像这样

40   "dependencies": {                                                             
41     "acl": "^0.4.11",                                                           
42     "amazon-s3-uri": "0.0.3",                                                   
43     "angular": "^1.7.7",                                                    
44     "angular-mocks": "^1.7.7",                                                
45     "async": "~2.5.0",                                                   
46     "aws-sdk": "^2.415.0",                                                   
47     "body-parser": "^1.18.3",                                                   
48     "bower": "^1.8.8",                                                   

在你的package.json中

每次看到这样的消息时,您都会知道您缺少依赖关系,或者您没有在某处定义变量。

在这种情况下,我们知道它是一个缺少的依赖,因为你的自定义代码中没有提到角度的业力,我们必须假设业力测试运行器工作,或者为什么有人会推荐它。

仅供参考,你的许多依赖项看起来像dev依赖项,比如bower,你可能不应该出于各种原因将它们放在生产环境中,包括托管的总成本。您只希望bitbucket管道在构建到生产服务器之后推送应用程序运行所需的文件。

最终目标通常是运行生产中的应用程序所需的最少量代码,而dev依赖项只是构建和测试代码。

例如,bower本质上是一个包管理器,就像npm一样,但是一旦它下载了所有的包,就可以抛弃bower,同时保持bower_components文件夹的生产。显然,你也可以创建脚本,将你的bower_components削减成只需要你需要的部分的文件,并扔掉bower_components文件夹,只保留最低生产量。

希望在某种程度上有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.