Fel vid användning av Karma med SystemJS, gulp och TypeScript
Jag är ny på node.js-stacken som npm, gulp osv. Jag har skrivit några JavaScript-enhetstestfall tidigare, och vill nu använda Karma som testrunner. Men efter några försök är jag helt förlorad nu.
För att börja har jag följande projektkonfigurationer:
SystemJSsom modulhanterare.Mappstruktur (vissa är utelämnade för korthet):
project | |--build //contains all gulp tasks | |--dist //contains the output (*.html, *.js etc.) | |--jspm_packages | |--node_modules | |--src //contains the source .html, and *.ts | |--tests //contains unit tests in *.ts. I also have a gulp task to build tests/**/*.ts to *.js in the same folder. | |--typings //contains type definitions | |--config.js //contains SystemJS configuration | |--karma.conf.jskarma.conf.js// Karma configuration module.exports = function (config) { config.set({ basePath: '', frameworks: [ 'qunit'], files: [ 'jspm_packages/system.js', //'config.js', 'dist/custom/*.js' //, //'tests/**/*.js' ], exclude: [ ], preprocessors: { }, reporters: ['progress'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, concurrency: Infinity }); }
Men, när jag gör karma start, får jag felet Uncaught TypeError: Unexpected anonymous System.register call.. Finns det något sätt att lösa detta?
Andra försök:
- Försökte skapa en gulp-uppgift enligt https://github.com/karma-runner/gulp-karma. Men har samma problem.
Försökte använda
karma-systemjs. Ochkarma.conf.jsvar annorlunda enligt följande:// Karma configuration module.exports = function (config) { config.set({ ... frameworks: [ 'systemjs', 'qunit'], plugins: ['karma-systemjs', 'karma-chrome-launcher', 'karma-firefox-launcher'], systemjs: { configFile: 'config.js', serveFiles: ['jspm_packages/**/*.js'], config: { transpiler: 'babel' } }, ... }); }Och i det här fallet fick jag följande fel, trots att jag har både
SystemJsochBabelinstallerade:[WARNING] Looking up paths with require.resolve() is deprecated. Please add "systemjs" to your SystemJS config paths. Cannot find "systemjs". Did you forget to install it ? npm install systemjs --save-dev [WARNING] Looking up paths with require.resolve() is deprecated. Please add "babel" to your SystemJS config paths. Cannot find "babel-core". Did you forget to install it ? npm install babel-core --save-dev
All hjälp i detta avseende kommer att vara bra.