How to register Mocha / Velocity (Meteor testing)?

What is the right way to display speed test information with Meteor?

I have some mocha tests from which I would like to derive some values, I think it would be nice if the result could be in the logs section of the speed window ... but it seems like any documentation anywhere?

+7
logging testing meteor velocity
source share
2 answers

I have not yet seen this documented.

I do not know how to write messages to the Velocity window, although I do not like the idea of ​​entering the user interface.

I created a simple Logger object that wraps the entire console. {{method}} causes and prevents logging if process.env.IS_MIRROR . This will only result in the release of test framework messages on the terminal. If I need to debug a specific test, I activate log output for a while in Logger.

+1
source share

This is a terrible hack. It will open an insecure method that writes to your database.

But it works.

I was very unpleasant when I was missing this feature, so I dug in the Velocity code to find out that they have a VelocityLogs collection that is publicly available. But you need to access it from your production, and not test the instance to see it in the web reporter.

So, it took me a while to enable Meteor CORS, but I finally managed - even for Firefox - to create a new route in IronRouter before the POST log message. (CORS might be better with this sentence - but you really shouldn't disclose it anyway.)

For this you will need meteor add http .

Put outside of / tests:

 if Meteor.isServer Router.route 'log', -> if @request.method is 'OPTIONS' @response.setHeader 'Access-Control-Allow-Origin', '*' @response.setHeader 'Access-Control-Allow-Methods', 'POST, OPTIONS' @response.setHeader 'Access-Control-Max-Age', 1000 @response.setHeader 'Access-Control-Allow-Headers', 'origin, x-csrftoken, content-type, accept' @response.end() return if @request.method is 'POST' logEntry = @request.body logEntry.level ?= 'unspecified' logEntry.framework ?= 'log hack' logEntry.timestamp ?= moment().format("HH:mm:ss.SSS") _id = VelocityLogs.insert(logEntry) @response.setHeader 'Access-Control-Allow-Origin', '*' @response.end(_id) return , where: 'server' 

Inside tests/mocha/lib or similarly as a utility function:

 @log = (message, framework, level) -> HTTP.post "http://localhost:3000/log", data: { message: message, framework: framework, level: level} (error) -> console.dir error 

For coffee lovers: coffeescript.org > TRY NOW> Paste the code to convert> Get the good old JavaScript.

0
source share

All Articles