javascript - בדיקות יחידה עם karma ב-Angular 4 עם Webpack
הנה קובץ karma.config.js שלי -
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
'karma-webpack',
'karma-babel-preprocessor',
// 'babel-preset-es2015'
],
client: {
builtPaths: [appBase, testingBase], // add more spec base paths as needed
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
customLaunchers: {
// From the CLI. Not used here but interesting
// chrome setup for travis CI using chromium
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
mime: {
'text/x-typescript': ['ts']
},
files: [
'./src/client/app/phone/component/nokia.component.ts',
'./src/client/app/phone/component/nokia.spec.ts'
],
// Proxied base paths for loading assets
proxies: {
// required for component assets fetched by Angular's compiler
"/app/": appAssets
},
// webpack: configureWebpack(),
exclude: [],
preprocessors: {
'./src/client/app/phone/component/nokia.component.spec.ts': ['babel', 'webpack'],
},
// babelPreprocessor: {
// options: {
// "presets": ["es2015"]
// }
// },
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
function configureWebpack() {
var webpackConfig = require('./webpack.config');
webpackConfig.entry = undefined; // karma will pass the proper
argument for entry
return webpackConfig;
}
הבעיה שאני מתמודד איתה היא שאני לא יכול לגשת לרכיב מקובץ הספציפיקציה. כרמה זורקת שגיאה
שגיאה ב-./src/client/app/phone/component/nokia.component.spec.ts מודול לא נמצא: שגיאה: לא ניתן לפתור את './nokia.component' ב-'/media/folder/New Volume/.....path' @ ./src/client/app/phone/component/nokia.component.spec.ts 1:0-61
מה שאני מקבל -
בסיסית, אני לא יכול לגשת להצהרות import מקובץ המפרט. מכיוון שהרכיבים שלנו משתמשים בדברים של ES6 אבל הקונפיגורציה של Karma שלי לא יכולה להבין את הדברים של ES6.
האם יש דרך שיכולה להגיד או להמיר את הדברים שלי ב-ES6 ל-ES5 כדי שהדפדפן שלי יוכל להבין את זה.
בעניין זה מצאתי את הדבר 'babel-preset-es2015' אבל אני לא מצליח לשלב את זה בקובץ הקונפיגורציה שלי של karma.
או שיש דרך חלופית - בקונפיגורציה של כרמה כדי שאוכל לבדוק את כל הרכיבים שלי עם Karma Jasmine באנגולר 4.
הערה - אני משתמש ב-webpack ישירות (לא ב-angular cli).
אנא ענה עבור webpack