karma-typescript-preprocessor icon indicating copy to clipboard operation
karma-typescript-preprocessor copied to clipboard

Uncaught SyntaxError: Unexpected token import

Open sudhamsa opened this issue 10 years ago • 5 comments

Here is my angular module,

app.ts:

 /// <reference path='../thirdparty/jasmine/jasmine.d.ts'/>
 /// <reference path= '../thirdparty/angular/angular.d.ts'/>
 import {common} from './modules/common/Common.module';
 var app:ng.Imodule= angular.module('comp', [common.name]);

app.test.ts:

    /// <reference path='../thirdparty/jasmine/jasmine.d.ts'/>
   /// <reference path= '../thirdparty/angular/angular.d.ts'/>

   import {comp} from './app';

   export function main() {
     describe('comp', function () {
    it('Comp should be defined', function () {
        expect(comp).toBeDefined();
    });
    });
   }

Karma.config.ts

   module.exports = function (config) {
    config.set({
    frameworks: ['jasmine'],
    basePath: '',
    preprocessors: {
        'app/app.ts': ['typescript'],
        'app/app.test.ts': ['typescript']
    },
    typescriptPreprocessor: {
        typings: [
            'thirdparty/jasmine/jasmine.d.ts',
            'node_modules/typescript/typescript.d.ts',
            'thirdparty/angular/angular.d.ts',
            'thirdparty/jquery/src/jquery.d.ts'
        ],
        options: {
            sourceMap: false,
            target: 'ES5',
            module: 'commonjs',
            noImplicitAny: true,
            noResolve: true,
            removeComments: true,
            concatinateOutput: false
        },
    },
    files: [
        'app/modules/**/*.module.ts',
        'app/app.ts',
        'app/app.test.ts',
        'node_modules/requirejs/require.js'
    ],
    exclude: [
        'modules/**/e2e_test/**',
        'app/**/e2e/**/*.js',
        'thirdparty/pioneer/featureFlag/**/*{t,T}est.js',
        'app/Templates.ts',
        'app/routes.ts',
        'app/ThirdpartyTemplates.ts'
    ],
    browsers: ['Chrome'],
    reporters: ['spec', 'junit'],
    specReporter: { maxLogLines: 5 },
    junitReporter: {
        outputFile: './build/work/jasmine/TEST-results.xml',
        suite: 'COMP'
    },
    port: 9876
});
 };

running the test throws error saying that unexpected token import and cannot import app. Not sure whats is wrong. Did some one came across this issue? Can some point where is the mistake.

sudhamsa avatar Dec 26 '15 06:12 sudhamsa

Same for me using Jasmine in AngularJS2 with NodeJS application.

$ jasmine C:\xampp\htdocs\xxx@xxx\ng2_msButton\spec\msButton.component.spec.js:2 import { ^^^^^^ SyntaxError: Unexpected token import

pauleau avatar Mar 24 '16 15:03 pauleau

the preprocessor is just rewritten using https://github.com/sergeyt/typescript-simple, so now it should support all compiler options. Please retry again.

sergeyt avatar Apr 11 '16 16:04 sergeyt

Still exist. How can I use typescript-simple? Do I have to change typescript to typescript-simple here?

preprocessors: {
        'app/app.ts': ['typescript'], //['typescript-simple']
        'app/app.test.ts': ['typescript']
    },

Andras-Csanyi avatar Sep 25 '16 17:09 Andras-Csanyi

I gave up using karma-typescript-preprocessor in favor of webpack.

My karma.config.js looks like this:

    preprocessors: {
      "./test/**/**/**.test.ts": ["webpack"]
    },

endel avatar Sep 25 '16 17:09 endel

could you share the karma.conf.js to me as reference, which dependencies are required?

neuropaddy avatar Aug 17 '17 10:08 neuropaddy