Enable "Experimental decorator support" with "tsify" in karma

I use tsify, a browser plugin, to override my code during karma modulation tests.

I get this kind of erro when I run my tests:

TypeScript error: src / app / emailLogin / emailLogin.component.ts (14,14): Error TS1219: Experimental decorator support is a feature that may be changed in a future version. Set the parameter "experimentalDecorators" to remove this warning.

How to enable experimental decoders in / tsify browser, which are specified in my karma.config.js file

Here is my karma.config.js:

module.exports = function(config) {
  config.set({
    browsers: ['Chrome'],
    frameworks: ['jasmine', 'browserify', 'es6-shim'],
    files: [
      'src/**/*.spec.ts'
    ],
    preprocessors: {
      '**/*.ts': ['browserify']
    },
    browserify: {
      debug: true,
      plugin: ['tsify'],
      transform: ['browserify-shim']
    }
  });
};

Here is my gulp file (I think it doesn't matter)

var gulp = require('gulp');
var Server = require('karma').Server;

/**
 * Run test once and exit
 */
gulp.task('test', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, done).start();
});

/**
 * Watch for file changes and re-run tests on each change
 */
gulp.task('tdd', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js'
  }, done).start();
});

gulp.task('default', ['tdd']);
0
1

, :

--emitDecoratorMetadata
--experimentalDecorators

, tsconfig.json (tsify tsconfig.json):

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5"
    },
    "files": []
}

- tsconfig.json, browserify Karma ( ):

browserify: {
    debug: true,
    plugin: [['tsify', {
        emitDecoratorMetadata: true,
        experimentalDecorators: true
    }]],
    transform: ['browserify-shim']
}

:

browserify -p [tsify --emitDecoratorMetadata --experimentalDecorators] main.ts > bundle.js
+1

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


All Articles