Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template files are not handled by karma-ng-html2js-preprocessor when using Jade #731

Closed
sdornan opened this issue Aug 20, 2015 · 2 comments

Comments

@sdornan
Copy link

sdornan commented Aug 20, 2015

If you generate an app that uses Jade, the default generated configuration for Karma does not correctly handle loading templates into JavaScript. I ended up using https://github.com/chmanie/karma-ng-jade2js-preprocessor in my project, but there's probably an easy way to make karma-ng-html2js-preprocessor compatible with Jade.

@Swiip
Copy link
Owner

Swiip commented Sep 11, 2015

Sorry for the delay. I think it should be as easy as searching for html files in the tmp folder which is not done right now. It's a bug, thanks.

@Swiip Swiip closed this as completed in a6cf0a6 Sep 14, 2015
zckrs pushed a commit that referenced this issue Sep 14, 2015
Load preprocessed markups in karma tests, fix #731
@lunatik-210
Copy link

The problem is still there.. It works only when I keep .html files along with .jade in the same folder that doesn't make any scenes..

I get the following traceback

[13:44:48] Using gulpfile ~/projects/myprofile/frontend/gulpfile.js
[13:44:48] Starting 'scripts:test'...
[13:44:50] Time: 2201ms
          Asset     Size  Chunks             Chunk Names
index.module.js  21.9 kB       0  [emitted]  main
[13:44:50] Finished 'scripts:test' after 2.38 s
[13:44:50] Starting 'test'...
PhantomJS 1.9.8 (Linux 0.0.0) directive navbar should be compiled FAILED
    Error: Unexpected request: GET app/components/navbar/navbar.html
    No more request expected
        at $httpBackend (/home/andrew/projects/myprofile/frontend/bower_components/angular-mocks/angular-mocks.js:1245)
        at sendReq (/home/andrew/projects/myprofile/frontend/bower_components/angular/angular.js:10515)
        at /home/andrew/projects/myprofile/frontend/bower_components/angular/angular.js:10221
        at processQueue (/home/andrew/projects/myprofile/frontend/bower_components/angular/angular.js:14678)
        at /home/andrew/projects/myprofile/frontend/bower_components/angular/angular.js:14694
        at /home/andrew/projects/myprofile/frontend/bower_components/angular/angular.js:15922
        at /home/andrew/projects/myprofile/frontend/bower_components/angular/angular.js:15733
        at /home/andrew/projects/myprofile/frontend/.tmp/serve/app/index.module.js:9
        at invoke (/home/andrew/projects/myprofile/frontend/bower_components/angular/angular.js:4476)
        at workFn (/home/andrew/projects/myprofile/frontend/bower_components/angular-mocks/angular-mocks.js:2438)
    undefined
PhantomJS 1.9.8 (Linux 0.0.0): Executed 14 of 18 (1 FAILED) (0 secs / 0.077 secs

Generated Karma conf looks like that right now:

var path = require('path');
var conf = require('./gulp/conf');

var _ = require('lodash');
var wiredep = require('wiredep');

var pathSrcHtml = [
  path.join(conf.paths.tmp, '/serve/app/**/*.html'),
  path.join(conf.paths.src, '/**/*.html')
];

function listFiles() {
  var wiredepOptions = _.extend({}, conf.wiredep, {
    dependencies: true,
    devDependencies: true
  });

  return wiredep(wiredepOptions).js
    .concat([
      path.join(conf.paths.tmp, '/serve/app/index.module.js'),
    ])
    .concat(pathSrcHtml);
}

module.exports = function(config) {

  var configuration = {
    files: listFiles(),

    singleRun: true,

    autoWatch: false,

    ngHtml2JsPreprocessor: {
      stripPrefix: conf.paths.src + '/',
      moduleName: 'frontend'
    },

    logLevel: 'WARN',

    frameworks: ['jasmine'],

    browsers : ['PhantomJS'],

    plugins : [
      'karma-phantomjs-launcher',
      'karma-coverage',
      'karma-jasmine',
      'karma-ng-html2js-preprocessor'
    ],

    coverageReporter: {
      type : 'html',
      dir : 'coverage/'
    },

    reporters: ['progress']
  };

  // This is the default preprocessors configuration for a usage with Karma cli
  // The coverage preprocessor in added in gulp/unit-test.js only for single tests
  // It was not possible to do it there because karma doesn't let us now if we are
  // running a single test or not
  configuration.preprocessors = {};
  pathSrcHtml.forEach(function(path) {
    configuration.preprocessors[path] = ['ng-html2js'];
  });

  // This block is needed to execute Chrome on Travis
  // If you ever plan to use Chrome and Travis, you can keep it
  // If not, you can safely remove it
  // https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076
  if(configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) {
    configuration.customLaunchers = {
      'chrome-travis-ci': {
        base: 'Chrome',
        flags: ['--no-sandbox']
      }
    };
    configuration.browsers = ['chrome-travis-ci'];
  }

  config.set(configuration);
};

.yo-rc.json

{
  "generator-gulp-angular": {
    "version": "1.0.0-rc2",
    "props": {
      "angularVersion": "~1.4.2",
      "angularModules": [
        {
          "key": "animate",
          "module": "ngAnimate"
        }
      ],
      "jQuery": {
        "key": "jquery2"
      },
      "resource": {
        "key": "restangular",
        "module": "restangular"
      },
      "router": {
        "key": "ui-router",
        "module": "ui.router"
      },
      "ui": {
        "key": "foundation",
        "module": null
      },
      "foundationComponents": {
        "key": "angular-foundation",
        "module": "mm.foundation"
      },
      "cssPreprocessor": {
        "key": "node-sass",
        "extension": "scss"
      },
      "jsPreprocessor": {
        "key": "babel",
        "extension": "js",
        "srcExtension": "es6"
      },
      "htmlPreprocessor": {
        "key": "jade",
        "extension": "jade"
      },
      "bootstrapComponents": {
        "name": null,
        "version": null,
        "key": null,
        "module": null
      },
      "paths": {
        "src": "src",
        "dist": "dist",
        "e2e": "e2e",
        "tmp": ".tmp"
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants