Karma + Rails: file structure?

When using the javacript test library (née Testacular) for karma along with Rails, where should the files be placed and the data marked?

It seems strange to have them in / assets / because we actually don't want to serve their users. (But I think if they just never were precompiled, then this is not a real problem, right?)

+6
source share
3 answers

As a result, we finished testing and mocked the data in the “Rails apps” spec folder and configured Karma to import them, as well as our tested code with app/assets .

It works for us. Other thoughts are welcome.

Our config/karma.conf.js file:

 basePath = '../'; files = [ JASMINE, JASMINE_ADAPTER, //libs 'vendor/assets/javascripts/angular/angular.js', 'vendor/assets/javascripts/angular/angular-*.js', 'vendor/assets/javascripts/jquery-1.9.1.min.js', 'vendor/assets/javascripts/underscore-min.js', 'vendor/assets/javascripts/angular-strap/angular-strap.min.js', 'vendor/assets/javascripts/angular-ui/angular-ui.js', 'vendor/assets/javascripts/angular-bootstrap/ui-bootstrap-0.2.0.min.js', //our app! 'app/assets/javascripts/<our-mini-app>/**', // and our tests 'spec/javascripts/<our-mini-app>/lib/angular/angular-mocks.js', 'spec/javascripts/<our-mini-app>/unit/*.coffee', // mocked data 'spec/javascripts/<our-mini-app>/mocked-data/<data-file>.js.coffee', ]; autoWatch = true; browsers = 'PhantomJS'.split(' ') preprocessors = { '**/*.coffee': 'coffee' } 
+3
source

Via this post: https://groups.google.com/forum/#!topic/angular/Mg8YjKWbEJ8

I am experimenting with something that looks like this:

 // list of files / patterns to load in the browser files: [ 'http://localhost:3000/assets/application.js', 'spec/javascripts/*_spec.coffee', { pattern: 'app/assets/javascripts/*.{js,coffee}', watched: true, included: false, served: false } ], 

It monitors the app js files, but does not include them or does not maintain them, instead, including application.js, served by rails and asterisks.

I also played with https://github.com/lucaong/sprockets-chain , but did not find a way to use requirejs to include js files from within gems (e.g. jquery-rails or angularjs-rails).

+8
source

I found this project useful as a starting point. https://github.com/monterail/rails-angular-karma-example . This is explained by the authors on their blog .

This is an example rails application with angular.js and a karma test runner.

+3
source

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


All Articles