Error in using karma with SystemJS, gulp and TypeScript

I am new to the node.js stack like npm , gulp etc. I previously wrote several cases of JavaScript unit test, and now I want to use Karma as a test runner. However, after several attempts, I was completely lost.

For starters, I have the following project configurations:

  • SystemJS as a module loader.
  • Folder structure (some are omitted for brevity):

     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.js 
  • karma.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 }); } 

However, when I do karma start , I have an Uncaught TypeError: Unexpected anonymous System.register call. . Is there any way to resolve this?

Other attempts:

  • Tried to create a gulp task, according to https://github.com/karma-runner/gulp-karma . But they have the same problem.
  • Tried to use karma-systemjs . And karma.conf.js differed as follows:

     // 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' } }, ... }); } 

    And in this case, I got the following error, although I have installed both SystemJS and Babel :

     [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 

Any help in this regard would be great.

+5
source share

Source: https://habr.com/ru/post/1242780/


All Articles