Persistent Karma test runner with autoWatch=false - karma-runner

I am trying to run Karma via node (gulp, specifically) persistently in the background but to manually re-run the tests i.e. I have autoWatch set to false. I start the server with something like:
karma_server = new karma.Server(config.karma)
karma_server.start()
Then elsewhere I would like to trigger the tests running when files are updated outside Karma. The API method that one would expect might work is server.refreshFiles(), but it does not do this.
Internally it seems like executor.schedule() might do the trick, but it seems to be undocumented, private, and inaccessible.
So when autoWatch is turned off, how does one trigger Karma testing with an existing server? I'm sure I must be missing something obvious as otherwise the autoWatch option would always need to be true for the server to be useful.

If you have a server already running you can use the karma runner to communicate with it:
var runner = require('karma').runner,
karmaConfig = {/* The karma config here */};
runner.run(karmaConfig, callback);
The grunt-karma plugin works like this, you can check it out for more info:
https://github.com/karma-runner/grunt-karma/blob/master/tasks/grunt-karma.js

Related

How do you set jobrunr in run now/eager mode for spring integration testing

I must be missing something obvious. I've got a couple of jobrunr jobs where i'm using the lambda enqueue format version 5.1.6. Like this:
JobId jobId = BackgroundJob.<MyService>enqueue(x -> x.doWork());
I would like to validate the plumbing and work in the jobs is executing via some integration tests with Spring, but don't see the options to run now, eager mode, etc? Thanks
You can't, I'm afraid.
You can mock the JobScheduler and capture the args. JobRunr itself is also tested very well so if you pass a job, you can rest assured it will be enqueued.
You could also put the pollIntervalInSeconds to 5 and use awaitility then to verify your job executed. There are many examples of this in the JobRunr repo.

Setting headless as CLI arg

My Protractor suite generally uses the Chrome non-headless mode so the tests can be monitored and stuff, but I tend to switch often between headless and normal while writing tests. Constantly changing the conf.js file is a hassle so I'd like to be able to do this via a command line argument. Something like the following:
npm test -- --headless
npm test-headless
As you can see I'm running Protractor via npm, so a complex argument construction is not a problem here.
I haven't been able to find a way to do this using uncle Google. Can someone point me in the right direction?
keep it simle. Create two protractor.conf files:
- one for local (non headless purpose) - protractor.local.conf
- another for headless purpose that you have already had
And create some scripts that will run what you need, for example:
"scripts": {
"test-headless": "node ./config/protractor.headless.conf.js",
"test-local": "node ./config/protractor.local.conf.js",
}
A somewhat hackish solution, but it works! Check for this flag (or any other) in your configuration file using node's process.argv global. You can then dynamically configure Protractor accordingly. This is one of the great perks of JS config files.
For example:
const isHeadless = process.argv.includes('--headless');
exports.config = {
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
isHeadless && '--headless'
].filter(Boolean)
}
}
};
This does raise a warning in the Protractor CLI:
Ignoring unknown extra flags: headless. This will be an error in
future versions, please use --disableChecks flag to disable the
Protractor CLI flag checks.
As with all hacks you use them with some level of risk. The --disableChecks flag will get rid of the warning and future error, but may introduce other issues.

How can I set http.port in application.conf by using playframework2.4(Scala)

I could set http.port in applicaton.conf by using playframework1.2.7
like this
http.port = 9020
jpda.port = 8020
also jdpa.port.
But in play2.4.
I cannot set http.port in application.conf like this.
I know that I can do like this when I run this project.
activator "run 9020"
But it is too troublesome for me.
If you have some ideas,
please share your idea.
You cannot specify port in aaplication.conf during run mode (but this can be used while deploying).
In run mode the HTTP server part of Play starts before the application has been compiled. This means that the HTTP server cannot access the application.conf file when it starts. If you want to override HTTP server settings while using the run command you cannot use the application.conf file. Instead, you need to either use system properties or the devSettings setting shown above.
Source: https://www.playframework.com/documentation/2.4.x/Configuration#HTTP-server-settings-in-application.conf
Also look at full server configuration options
https://www.playframework.com/documentation/2.4.x/ProductionConfiguration#Server-configuration-options

How do I configure grunt-karma to run tests directly when starting a watch?

I have configured my grunt/karma setup according to https://github.com/karma-runner/grunt-karma
I'm also using it together with grunt-contrib-watch as described under https://github.com/karma-runner/grunt-karma#karma-server-with-grunt-watch
Almost everything works great, but how do I configure karma to perform all tests directly when the watch is started?
I start it with karma:unit:start watch but then I must first change a file before the tests are performed.
I have stared at the karma config params at http://karma-runner.github.io/0.8/config/configuration-file.html but still cannot find the correct param.
I haven't used grunt-karma before, but the easiest option is probably to configure your watch task, so that it runs it's tasks at startup. This can be done via options.atBegin. So if you take the example from the grunt-karma documentation, you would write:
watch: {
karma: {
files: ['app/js/**/*.js', 'test/browser/**/*.js'],
tasks: ['karma:unit:run'],
options: {
atBegin: true
}
}
},

Why is Rails caching assets in development mode on my iPhone?

According to the Ruby on Rails Guide: Caching, caching is disabled by default in the development and testing environments. If I make a small CSS change, run rails server and access my site at localhost:3000, I can see my change. However, if I access my rails server on my iPhone at 10.0.1.2:3000, the CSS doesn't update, even Chrome in Incognito Mode. When I try different iPhone that has an empty cache, the change is there.
I found a stack overflow post that described the same problem. Here were the suggested solutions:
Remove the public/assets directory. I don't have one.
Add config.serve_static_assets = false to environments/development.rb. It's already there.
Delete /tmp/cache/assets, add config.serve_static_assets = false to environments/development.rb and restart the server. I tried this and it didn't work.
Here's my relevant environments/development.rb config:
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
I'm pretty sure this is happening because Rails only does fingerprinting in production: http://guides.rubyonrails.org/asset_pipeline.html#in-production
This means that in development browsers that are more cache-aggressive can run into this issue.
Try adding this to your development.rb:
config.assets.digest = true
Or more preferable something conditional for when you're doing mobile development
# One of the few exceptions I'd make to a no ENV variables rule
# for my rails environment config files
config.assets.digest = true if ENV["MOBILE_DEBUG"]
How are use accessing your local machine via your iphone ?
have you configured any network settings or you push it to a different server and access from there, because the thing is if you are pusing it to a different server , that sever might be running in the production mode.
HTH
I don't have an iPhone to test, but it sounds like a normal browser caching issue. Try these instructions for clearing the browser cache. If that works, you'll need to do it each time you update your CSS (or J
I had a similar problem. It happened because my config/environments/development.rb had contained config.asset_host = 'http://localhost:3000'
I've removed it and all works fine.