angularjs 仅在 rails 使用编译资产的功能规范上出现 nomod 错误
angularjs nomod error only on rails feature specs using compiled assets
我们的 rails
和 angularjs
最近将 angularjs 从 1.2.9 升级到 1.3.0,用 yarn 替换了 bower,并从节点 0.8.28 升级到了 8.11。 1. UI.
中的应用程序一切正常
我通过使用 ng-strict-di
指令严格依赖并明确注释所有依赖项来修复应用程序中缺少模块的错误。
我们使用水豚和 poltergiest
进行功能测试,我用 selenium
替换了 poltergiest,所有 jasmine 规格 运行 都很好。
我们使用 g运行t 作为任务 运行ner 并且所有资产都被编译到根级别的 public
文件夹中,当水豚启动服务器时它 运行s 指定端口上 public
文件夹中的应用程序。
我不明白或找不到水豚如何知道从 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
如果您需要更多信息,请告诉我。
我终于明白是怎么回事了,
我开始调试的方式是,我从 jenkins 应用程序的 public
文件夹中提取编译后的资产,并用它在本地进行测试,我可以看到它缺少一些包,原因是正在发生的是(我不确定如何),
在旧设置中,我们将 components 文件夹推送到 repo 中,其中包含包含脚本的 dist 文件夹,但现在我从 package.json
下载所有内容,它不会生成 dist
服务器上的文件夹,但在本地,因此缺少模块错误。
我们的 rails
和 angularjs
最近将 angularjs 从 1.2.9 升级到 1.3.0,用 yarn 替换了 bower,并从节点 0.8.28 升级到了 8.11。 1. UI.
我通过使用 ng-strict-di
指令严格依赖并明确注释所有依赖项来修复应用程序中缺少模块的错误。
我们使用水豚和 poltergiest
进行功能测试,我用 selenium
替换了 poltergiest,所有 jasmine 规格 运行 都很好。
我们使用 g运行t 作为任务 运行ner 并且所有资产都被编译到根级别的 public
文件夹中,当水豚启动服务器时它 运行s 指定端口上 public
文件夹中的应用程序。
我不明白或找不到水豚如何知道从 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
如果您需要更多信息,请告诉我。
我终于明白是怎么回事了,
我开始调试的方式是,我从 jenkins 应用程序的 public
文件夹中提取编译后的资产,并用它在本地进行测试,我可以看到它缺少一些包,原因是正在发生的是(我不确定如何),
在旧设置中,我们将 components 文件夹推送到 repo 中,其中包含包含脚本的 dist 文件夹,但现在我从 package.json
下载所有内容,它不会生成 dist
服务器上的文件夹,但在本地,因此缺少模块错误。