我想在AngularJS与噶,茉莉花,设置的WebPack测试。 我的WebPack工作正常,我可以使用运行我的网站npm start
一个简单的测试工作正常,但我尝试添加自己的app.js一切的那一刻顺心。
我已经尝试了很多很多很多的搜索和许多解决方案。 请不要认为,我写这个问题,我打了一个死胡同的时刻。 我花了一整天今天刚google搜索,并找到可行的解决方案。
还有就是我karma.conf.js文件
// Karma configuration
// Generated on Mon Sep 18 2017 09:27:36 GMT+1000 (AEST)
var webpackConfig = require('./webpack.config.js');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
frameworks: ['jasmine'],
// ... normal karma configuration
files: [
'./node_modules/jasmine-core/lib/jasmine-core/jasmine.js',
'./node_modules/angular/angular.js', // angular
'./node_modules/angular-mocks/angular-mocks.js', // loads our modules for tests
// all files for test
'./resources/assets/js/auth/app.js',
'./resources/assets/js/account/invoices/*.spec.js',
],
preprocessors: {
// add webpack as preprocessor
'./resources/assets/js/account/invoices/*.spec.js': ['webpack'],
},
webpack: {
// webpack configuration
webpackConfig
},
webpackMiddleware: {
// webpack-dev-middleware configuration
// i. e.
stats: 'errors-only'
},
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
我写的测试
describe('Unit testing Dash', function() {
var $compile,
$rootScope;
// Load the myApp module, which contains the directive
beforeEach(angular.mock.module('app'));
// Store references to $rootScope and $compile
// so they are available to all tests in this describe block
beforeEach(inject(function(_$compile_, _$rootScope_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
it('Replaces the element with the appropriate content', function() {
// Compile a piece of HTML containing the directive
var element = $compile("<dash-list></dash-list>")($rootScope);
// fire all the watches, so the scope expression {{1 + 1}} will be evaluated
$rootScope.$digest();
// Check that the compiled element contains the templated content
expect(element.html()).toContain("Unpaid");
});
});
它失败,此错误:
18 09 2017 15:00:18.554:DEBUG [web-server]: serving (cached): project/resources/assets/js/account/invoices/dash.spec.js
18 09 2017 15:00:18.557:DEBUG [web-server]: serving (cached): project/resources/assets/js/account/invoices/add-business.spec.js
18 09 2017 15:00:18.576:DEBUG [web-server]: serving: project/node_modules/karma/static/context.js
Chrome 60.0.3112 (Mac OS X 10.12.6) ERROR
Uncaught SyntaxError: Unexpected token import
at resources/assets/js/auth/app.js:1
我使用OSX。 从技术上讲,应该的WebPack服务编译的文件噶。 但意外的标记进口意味着文件不被编译并担任噶。
请帮忙。
我甚至试图与巴贝尔编译但didnt无论去任何地方。 我搬到的WebPack因为我们已经拥有的WebPack配置构建和项目使用webpage.config编译
UPDATE
任何人在这个问题谁茬,我菲利克斯使用选项#1。 我只是包含在噶编译后的文件。 它的工作般的魅力。
汽车的WebPack编译文件时,只要文件被更改,所以只需添加输出工作的罚款。
我的文件阵列看起来像以下
files: [
'./node_modules/jasmine-core/lib/jasmine-core/jasmine.js',
'./node_modules/angular/angular.js', // angular
'./node_modules/angular-mocks/angular-mocks.js', // loads our modules for tests
'./resources/assets/js/account/stripe.spec.js',
'./node_modules/angular-stripe/index.js',
'./node_modules/angular-stripe-checkout/angular-stripe-checkout.js',
// all files for test
'./public/assets/vendor.bundle.js',
'http://localhost:8080/assets/account.js',
'./resources/assets/js/account/invoices/*.spec.js',
我不得不遗憾的是使用http第二个选项,但它工作正常。