-1

在我们最近将 angularjs 从 1.2.9 升级到 1.3.0 的其中一个中railsangularjs将 bower 替换为 yarn 并从节点 0.8.28 升级到 8.11.1。UI 中的应用程序一切正常。

我通过将严格依赖于 usingng-strict-di指令并显式注释所有依赖项来修复应用程序中缺少的模块错误。

我们使用 capybara 并poltergiest进行功能测试,我用 poltergiest 替换了selenium,所有 jasmine 规格都运行良好。

我们使用 grunt 作为任务运行器,所有资产都编译到public根级别的文件夹中,当 capybara 启动服务器时,它从public指定端口上的文件夹运行应用程序。

我不明白或找不到 capybara 如何知道从public文件夹中已编译的应用程序启动应用程序。

出于测试目的,我让功能规范在 chrome 中运行,我得到了臭名昭著的错误,

[$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

我无法弄清楚为什么我在运行实际应用程序时没有收到该错误,但仅在功能规格中。

这是我的 Gruntfile.js

'use strict';
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
var serveStatic = require('serve-static');

module.exports = function (grunt) {
  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  // configurable paths
  var yeomanConfig = {
    app: 'app',
    dist: '../public'
  };

  try {
    yeomanConfig.app = require('./package.json').appPath || yeomanConfig.app;
  } catch (e) {}

  grunt.initConfig({
    ngtemplates: {
      app: {
        options: {
          base: 'app',
          // concat: '<%= yeoman.dist %>/scripts/scripts.js'
          concat: 'generated'
        },
        src: ['app/views/**/*.html'],
        dest: '.tmp/template.js'
      }
    },
    yeoman: yeomanConfig,
    watch: {
      all : {
        options : { livereload: true },
        files: [
          '<%= yeoman.app %>/{,*/}*.html',
          '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
          '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
          '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
        ],
        tasks: ['jshint']
      }
    },
    connect: {
      proxies: [{
        context: '/api',
        host: '127.0.0.1',
        port: 5000,
        https: false,
        changeOrigin: false
      }, {
        context: '/public/api',
        host: '127.0.0.1',
        port: 5000,
        https: false,
        changeOrigin: false
      }, {
        context: '/print',
        host: '127.0.0.1',
        port: 5000,
        https: false,
        changeOrigin: false
      }, {
        context: '/users',
        host: '127.0.0.1',
        port: 5000,
        https: false,
        changeOrigin: false
      }],
      livereload: {
        options: {
          port: 9000,
          // Change this to 'localhost' to restrict access to the server from outside.
          hostname: '0.0.0.0',
          middleware: function () {
            return [
              require('connect-livereload')(),
              proxySnippet,
              serveStatic('.tmp'),
              serveStatic('test'),
              serveStatic(yeomanConfig.app)
            ];
          }
        }
      },
      test: {
        options: {
          port: 9001,
          middleware: function () {
            return [
              serveStatic('.tmp'),
              serveStatic('test')
            ];
          }
        }
      },
      teste2e: {
        options: {
          port: 9002,
          hostname: 'localhost',
          middleware: function () {
            return [
              proxySnippet,
              serveStatic('.tmp'),
              serveStatic('test'),
              serveStatic(yeomanConfig.app)
            ];
          }
        }
      }
    },
    open: {
      server: {
        url: 'http://localhost:<%= connect.livereload.options.port %>'
      }
    },
    clean: {
      options: {
        force: true
      },
      dist: ['.tmp', '<%= yeoman.dist %>/*'],
      server: '.tmp'
    },
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: [
        'Gruntfile.js',
        '<%= yeoman.app %>/scripts/{,*/}*.js',
        '<%= yeoman.app %>/modules/{,*/}*.js'
      ]
    },
    karma: {
      unit: {
        configFile: 'karma.conf.js',
        singleRun: true
      },
      dev: {
        configFile: 'karma.conf.js',
        singleRun: false
      },
      e2e: {
        configFile: 'karma-e2e.conf.js',
        singleRun: true
      }
    },
    coffee: {
      dist: {
        files: {
          '.tmp/scripts/coffee.js': '<%= yeoman.app %>/scripts/*.coffee'
        }
      },
      test: {
        files: [{
          expand: true,
          cwd: '.tmp/spec',
          src: '*.coffee',
          dest: 'test/spec'
        }]
      }
    },
    compass: {
      options: {
        sassDir: '<%= yeoman.app %>/styles',
        cssDir: '.tmp/styles',
        imagesDir: '<%= yeoman.app %>/images',
        javascriptsDir: '<%= yeoman.app %>/scripts',
        fontsDir: '<%= yeoman.app %>/styles/fonts',
        importPath: 'app/components',
        relativeAssets: true
      },
      dist: {},
      server: {
        options: {
          debugInfo: true
        }
      }
    },
    concat: {
      dist: {
        files: {
          '<%= yeoman.dist %>/scripts/scripts.js': [
            '.tmp/scripts/{,*/}*.js',
            '<%= yeoman.app %>/scripts/{,*/}*.js'
          ]
        }
      }
    },
    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>'
      }
    },
    rev: {
      files: {
        src: ['<%= yeoman.dist %>/lib/components.js', '<%= yeoman.dist %>/lib/components-ie8.js', '<%= yeoman.dist %>/lib/components-ie.js', '<%= yeoman.dist %>/scripts/scripts.js', '<%= yeoman.dist %>/styles/main.css']
      }
    },
    usemin: {
      html: ['<%= yeoman.dist %>/{,*/}*.html'],
      css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
      options: {
        dirs: ['<%= yeoman.dist %>']
      }
    },
    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },
    cssmin: {
      dist: {
        files: {
          '<%= yeoman.dist %>/styles/main.css': [
            '.tmp/styles/{,*/}*.css',
            '<%= yeoman.app %>/styles/{,*/}*.css'
          ]
        }
      }
    },
    htmlmin: {
      dist: {
        options: { },
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>',
          src: ['*.html', 'views/*.html'],
          dest: '<%= yeoman.dist %>'
        }]
      }
    },
    ngmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.dist %>/scripts',
          src: '*.js',
          dest: '<%= yeoman.dist %>/scripts'
        }]
      }
    },
    uglify: {
      dist: {
        files: {
          '<%= yeoman.dist %>/scripts/scripts.js': ['<%= yeoman.dist %>/scripts/*.js']
        }
      }
    },
    copy: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.{ico,txt}',
            '.htaccess',
            'fonts/**/*',
            'scriptx/**/*',
            'lib/**/*',
            'images/{,*/}*.{gif,webp,svg}'
          ]
        }]
      }
    }
  });

  grunt.registerTask('server', [
    'clean:server',
    'coffee:dist',
    'compass:server',
    'configureProxies',
    'connect:livereload',
    'open',
    'watch'
  ]);

  grunt.registerTask('test', [
    'clean:server',
    'coffee',
    'compass',
    'connect:test',
    'karma:unit'
  ]);

  grunt.registerTask('test-e2e', [
    'clean:server',
    'coffee',
    'compass',
    'configureProxies',
    'connect:teste2e',
    'karma:e2e'
  ]);

  grunt.registerTask('deploy', [
    'clean:dist',
    'coffee',
    'compass:dist',
    'useminPrepare',
    'imagemin',
    'cssmin',
    'htmlmin',
    'ngtemplates',
    'concat',
    'ngmin',
    'uglify',
    'copy',
    'rev',
    'usemin'
  ]);

  grunt.registerTask('build', [
    'clean:dist',
    'jshint',
        'karma:unit',
    'compass:dist',
    'useminPrepare',
    'imagemin',
    'cssmin',
    'htmlmin',
    'ngtemplates',
    'concat',
    'ngmin',
    'uglify',
    'copy',
    'rev',
    'usemin'
  ]);

  grunt.registerTask('default', ['build']);
};

这是我的功能规格,

require 'spec_helper'
require 'vcr'
require 'timecop'

Capybara.default_max_wait_time = 10

feature "Consignment creation and dispatch"  do
  include SpecHelpers
  include Acceptance

  scenario "Creating a Consignment", :js => true do

    puts "Running with #{Capybara.current_driver}"

    VCR.use_cassette('cassete file') do
    end

  end

end

如果您需要更多信息,请与我们联系。

4

1 回答 1

0

终于明白怎么回事了

我开始调试的方式是,我从publicjenkins 的应用程序的文件夹中提取编译的资产,并用它在本地测试它,我可以看到它缺少一些包,发生的原因是(我不确定如何) ,

在旧设置中,我们在 repo 中推送 components 文件夹,其中包含包含脚本的 dist 文件夹,但现在我正在从其中下载所有内容package.json,它不会dist在服务器上生成文件夹,而是在本地生成,因此缺少模块错误.

于 2018-08-28T04:34:18.763 回答