mercredi 27 mai 2015

How to sovle "Uncaught SyntaxError: Unexpected token <" for testing for testing a Directive

Hello I am trying to test a directive that uses a Url path. The Karma test runs and then abruptly stops with "Uncaught SyntaxError: Unexpected token <" error for each of the "view.html" templates. However, looking at the logs, I see that the server DID get them right before the error was announced. Here is the Karma.conf.js file

module.exports = function (config) {
    config.set({
    //  root path location that will be used to resolve all relative paths in files and exclude sections
    basePath: '../',

    // files to include, ordered by dependencies
    files: [
        'src/libraries/angular/angular.js',
        'src/libraries/angular-mocks/angular-mocks.js',
        'src/libraries/jquery/dist/jquery.min.js',
        'src/libraries/jquery-ui/jquery-ui.min.js',
        'src/libraries/angular-moment/angular-moment.js',
        'src/libraries/lodash/lodash.min.js',
        'src/libraries/angular-route/angular-route.js',
        'src/libraries/angular-resource/angular-resource.js',
        'src/libraries/angular-sanitize/angular-sanitize.js',
        'src/libraries/angular-bootstrap/ui-bootstrap-tpls.min.js',
        'src/libraries/angular-translate/angular-translate.js',
        'src/libraries/angular-translate-loader-static-files/angular-translate-loader-static-files.js',
        'src/libraries/angular-ui-sortable/src/sortable.js',
        'src/libraries/ng-teradata/modules/**/*.js',
        'src/scripts/*.js',//load all source javascript
        'test/unit/*.js',//load all my unit tests
        'src/scripts/*.html',//load my html
        'src/*.html'
    ],
    // files to exclude
    exclude: [],

    // karma has its own autoWatch feature but Grunt watch can also do this
    autoWatch: false,

    // testing framework, be sure to install the correct karma plugin
    frameworks: ['jasmine'],

    // browsers to test against, be sure to install the correct browser launcher plugins
    browsers: ['Chrome'],

    // map of preprocessors that is used mostly for plugins
    preprocessors: {
        'src/scripts/datepicker-month-view.html': ['ng-html2js']
        //'mock_data/**/*': ['ng-json2js']
    },

    // test coverage
    'src/scripts/controllers/*.js': ['jshint', 'coverage'],
    'src/scripts/directives/*.js': ['jshint', 'coverage'],
    'src/scripts/services/app.js': ['jshint', 'coverage'],
    'src/scripts/*.js': ['jshint', 'coverage'],

    reporters: ['progress', 'coverage'],

    logLevel: config.DEBUG,

    // list of karma plugins
    plugins: [
        'karma-jshint-preprocessor',
        'karma-coverage',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-ng-html2js-preprocessor',
        'karma-phantomjs-launcher'
    ],

    // plugin settings
    ngHtml2JsPreprocessor: {
        stripPrefix: 'src/',
        moduleName: 'datePickerTemplates',
        prependPrefix: 'served/'

    },
    coverageReporter: {
        // type of file to output, use text to output to console
        type: 'html',
        // directory where coverage results are saved
        dir: 'test/test-results/coverage/'
        // if type is text or text-summary, you can set the file name
        // file: 'coverage.txt'
    },
    junitReporter: {
        outputFile: 'test/test-results/test-results.xml'
    },
    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true
   })
}

and here are the logs:

Chrome 43.0.2357 (Mac OS X 10.10.3) ERROR
Uncaught SyntaxError: Unexpected token <
at /Users/jc186096/Documents/myProjects/angular/td-ng    datepicker/src/scripts/quarterpicker-view.html:1
Chrome 43.0.2357 (Mac OS X 10.10.3): Executed 0 of 0 ERROR (0 secs / 0 secs)
Chrome 43.0.2357 (Mac OS X 10.10.3) ERROR
Uncaught SyntaxError: Unexpected token <
at /Users/jc186096/Documents/myProjects/angular/td-ng-datepicker/src/scripts/weekpicker-view.html:1
Chrome 43.0.2357 (Mac OS X 10.10.3): Executed 0 of 0 ERROR (0 secs / 0 secs)
Chrome 43.0.2357 (Mac OS X 10.10.3) ERROR
Uncaught SyntaxError: Unexpected token <
at /Users/jc186096/Documents/myProjects/angular/td-ng-datepicker/src/scripts/yearpicker-view.html:1
Chrome 43.0.2357 (Mac OS X 10.10.3): Executed 0 of 0 ERROR (0 secs / 0 secs)
 Chrome 43.0.2357 (Mac OS X 10.10.3) ERROR
Uncaught SyntaxError: Unexpected token <
at /Users/jc186096/Documents/myProjects/angular/td-ng-datepicker/src/index.html:1
Chrome 43.0.2357 (Mac OS X 10.10.3): Executed 0 of 0 ERROR (0 secs / 0 secs)
Chrome 43.0.2357 (Mac OS X 10.10.3): Executed 0 of 0 ERROR (0.212 secs / 0 secs)

Aucun commentaire:

Enregistrer un commentaire