mad-eye / meteor-mocha-web Goto Github PK
View Code? Open in Web Editor NEWeasily and safely run mocha tests within the Meteor framework
License: MIT License
easily and safely run mocha tests within the Meteor framework
License: MIT License
Hey @rissem,
I haven't checked this carefully, so if you think I'm wrong, let me know and I'll do better research. But a quick VelocityTestFiles.find().fetch() in my console does not show any mocha-web-files, but results are populating, so I think mocha-web is not reporting back the files it's using.
I'm thinking that's what I want to use to cause the "create sample tests" button to be presented, so I'll need this as part of that effort unless you think this should work differently.
Running into this issue when trying to run tests.
When I try to run tests using meteor-mocha-web I get the following error:
While building package
mocha-web: path.js:313:15: Arguments to path.resolve must be strings
I think this may have to do with the recent update of Meteor to version 0.6.6 Meteor is now using node 0.10. Other people with this issue said it was due to an older version of NPM. My systems NPM is up to date (v1.3.11) but NPM and node are packaged with Meteor so I don't think this matters.
Anyone else having this issue?
I'm doing some validation, so I'm writing Meteor Methods instead of using Model.Insert, etc. The problem is, when an assertion fails in an asynchronous test, I'm not told which test or suite (it
or describe
) is failing in the console.
I get a message back like this, but it contains no useful information to determine which test this feedback is coming from:
Exception while delivering result of invoking 'insertTransaction'
AssertionError {message: "expected 'Cause not found' to include 'Owner'", actual: "Cause not found", expected: undefined, operator: undefined, showDiff: false…}
actual: "Cause not found"
expected: undefined
message: "expected 'Cause not found' to include 'Owner'"
operator: undefined
showDiff: false
stack: "expected 'Cause not found' to include 'Owner'"
I guess it would be most useful if that stack
property contained a call stack, or the name of the suite and test, or at least the file and line number that threw it.
When I say an async test, I mean one like this:
it 'accepts only numeric amounts', (done) ->
Meteor.call "insertTransaction", newTran, (error, result) ->
should.exist error
error.details.should.contain "NaN"
done()
What's the best practice for removing this during deployment?
Add a safety check to the top of server.js that will bail unless the server is running in development mode. This would stop both the server side tests, the mirror and phantomJS from starting up.
This might be due to the documentation being outdated or me being retarded, and not understanding meteorite. Either way, I'm getting Uncaught Error: No such template 'mochaTestReport'.
I suspect that this is due to mocha-web not being installed at all, because if I run
mrt add mocha-web from the project directory
and then search for the string "mocha-web" in the project, it finds 0 matches.
This is the installation output I get:
mrt add mocha-web --verbose
Installing Meteor
branch: https://github.com/meteor/meteor.git#master
Installing smart packages
Resolving dependency tree
I don't have a smart.json or anything like that, just installed meteorite and I'm trying to use it on an existing project.
Looking at the mocha docs, it.skip('name', func) lets you skip specific specs. This doesn't seem to work on server side.
TypeError: Object function (name, func){
wrappedFunc = function(callback)
if (func.length == 0)
func();
callback();
}
else {
func(callback)
}
}
boundWrappedFunction = moddedBindEnvironment(
throw err;
});
mochaExports[testFunctionName](name,boundWrappedFunction);
} has no method 'skip'
Mocha on the client lets you run just 1 describe block by clicking on it. It would be very useful to be able to do this on the server too.
We use the audit-argument-checks, and meteor-mocha-web throws an error when trying to make it's subscriptions: Error: Did not check() all arguments during publisher 'mochaServerSideTests'
I'm kinda puzzling over how to change the ui options to TDD (suite() -> setup()) instead of the default BDD (describe -> describe). According to the Mocha docs, you can use a test/mocha.opts file to set this. I've tried putting one in my tests/ folder but it's not helped.
Hi! Great to see this effort - we have recently included quick-n-dirty testing support to observatoryjs.com (check out testing tab overthere, github is https://github.com/jhoxray/observatory) based on chai and very small subset of mocha-like syntax, but we'd much rather use the real thing. The only problem is that there we included both server and client side testing (all run inside the full Meteor app environment) so I was wondering if you have plans to add that. If not, would you be ok if we fork yours and play with it to see if any pull requests work? Thanks!
Hi guys,
Having just updated to the newly released 0.6.5
I'm getting a package build error at startup:
While building package `mocha-web`:
error: File not found: tests/_global.coffee
error: File not found: tests/auth_acl_spec.coffee
...
Are you seeing the same thing?
Thanks!
Hey @rissem as far as I can tell, it looks like the tests written in mocha web run against the actual running version of the meteor app that was spun up?
I ask because this seems bad for data isolation, from a testing standpoint.
When running the following test:
describe "Tests", ->
describe "should work", ->
it "loads chai and mocha", ->
chai.expect(1+1).to.equal(2)
I get the following error:
Error: global leak detected: script1364333185006
at Runner.checkGlobals (http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4230:21)
at Runner.<anonymous> (http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4115:44)
at Runner.EventEmitter.emit (http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:522:20)
at http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4461:14
at Test.Runnable.run (http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4049:5)
at Runner.runTest (http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4404:10)
at http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4450:12
at next (http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4330:14)
at http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4339:7
at next (http://localhost:3000/packages/mocha-web/mocha.js?6063a59f4cc9bc796634b8496e4d619b5a6cd22d:4287:23)
It looks like the tests are kicked off before all of our startup blocks are finished. Is there a way to guarantee that they get run after Meteor.startup blocks have all completed?
This package will now be responsible for using PhantomJS to run the client side tests. This should happen on code or test change.
I Confused about that.
Whenever you add a test file or change the METEOR_MOCHA_TEST_DIRS
environment variable, you will need to meteor rebuild-all to rebuild the
mocha-web package and bring in the correct test files
I'm trying to clear a meteor collection in before() hook, but it gives an Error: Meteor code must always run within a Fiber.
Stack trace:
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
at Object.Meteor._nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9)
at Object.Meteor.bindEnvironment (packages/meteor/dynamics_nodejs.js:66)
at null.<anonymous> (packages/meteor/helpers.js:108)
at MongoConnection.(anonymous function) [as remove] (packages/mongo-livedata/mongo_driver.js:561)
at Meteor.Collection.(anonymous function) [as remove] (packages/mongo-livedata/collection.js:451)
at Context.<anonymous> (packages/mocha-web//home/vagrant/inviting/tests/server/sales.js:18)
at Hook.Runnable.run (/home/vagrant/.meteorite/packages/mocha-web/mad-eye/meteor-mocha-web/5a681e206ad455d29a0e445caedc7bb1cbc12f47/.npm/package/node_modules/mocha/lib/runnable.js:221:32)
at next (/home/vagrant/.meteorite/packages/mocha-web/mad-eye/meteor-mocha-web/5a681e206ad455d29a0e445caedc7bb1cbc12f47/.npm/package/node_modules/mocha/lib/runner.js:259:10)
at Object._onImmediate (/home/vagrant/.meteorite/packages/mocha-web/mad-eye/meteor-mocha-web/5a681e206ad455d29a0e445caedc7bb1cbc12f47/.npm/package/node_modules/mocha/lib/runner.js:276:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
My test code:
describe("Leaderboard", function() {
describe("Player", function() {
before(function() {
Players.remove({});
});
it("can insert a player into the db", function(done) {
// some test code
});
});
});
I looked at serverPreTest.js and I think the problem is in the wrapping function. In mocha, the 'it' function has different signature than 'before', 'beforeEach', 'after', and 'afterEach' function, so I don't think they can be combined in one wrapping function.
It should be possible to store your tests in multiple directories.
In the following scenario:
Meteor.methods
'foo': ->
console.log 'foo method'
describe 'Meteor methods', ->
it 'calls', (done) ->
Meteor.call 'foo', (err, result) ->
console.log 'callback', err
done()
The method runs client-side, then the following error is returned:
Meteor.Error {error: 404, reason: "Method not found", details: undefined}
I'm guessing this is the way the test files are being added conditionally, and maybe are not being added in a way where the server registers these methods. ??
Having this work would be very helpful. It would allow server-side setup of collections for testing which becomes very difficult the moment autopublish
is turned off.
Thanks!
Seeing this when I start velocity
I20140602-19:42:27.926(-7)? MOCHA-WEB MIRROR LISTENING AT http://localhost:53502/
I20140602-19:42:27.949(-7)? Running mocha-web server tests
I20140602-19:42:27.960(-7)? Exception in callback of async function: TypeError: Bad argument
I20140602-19:42:27.960(-7)? at ChildProcess.spawn (child_process.js:923:24)
I20140602-19:42:27.960(-7)? at exports.spawn (child_process.js:723:9)
I20140602-19:42:27.960(-7)? at Object.exports.execFile (child_process.js:607:15)
I20140602-19:42:27.960(-7)? at packages/mocha-web/server.js:49
I20140602-19:42:27.960(-7)? at runWithEnvironment (packages/meteor/dynamics_nodejs.js:89)
Due to the way tests are no copied to the rsync mirror, changes to test files are no longer triggering reloads.
The solution will be to use velocity's file watching patterns.
Hi,
When I tried running:
$ mrt add mocha-web
I got the following error:
Installing Meteor
branch: https://github.com/meteor/meteor.git#master
Installing smart packages
/usr/local/lib/node_modules/meteorite/node_modules/ddp/node_modules/ws/lib/WebSocket.js:175
else throw new Error('not opened');
^
Error: not opened
at WebSocket.send (/usr/local/lib/node_modules/meteorite/node_modules/ddp/node_modules/ws/lib/WebSocket.js:175:16)
at DDPClient._send (/usr/local/lib/node_modules/meteorite/node_modules/ddp/lib/ddp-client.js:77:15)
at WebSocket. (/usr/local/lib/node_modules/meteorite/node_modules/ddp/lib/ddp-client.js:49:10)
at WebSocket.EventEmitter.emit (events.js:92:17)
at WebSocket.establishConnection (/usr/local/lib/node_modules/meteorite/node_modules/ddp/node_modules/ws/lib/WebSocket.js:576:8)
at ClientRequest. (/usr/local/lib/node_modules/meteorite/node_modules/ddp/node_modules/ws/lib/WebSocket.js:488:25)
at ClientRequest.g (events.js:175:14)
at ClientRequest.EventEmitter.emit (events.js:106:17)
at CleartextStream.socketOnData (http.js:1587:11)
at CleartextStream.read as _read
Any ideas?
Thanks,
Erick
Excellent work on this package folks! The handful of CSS rules that affect the tag were interfering with my app's design. I've accounted for it in my CSS, but it would be nice to not have to do that. Specifically the lines are:
mocha.css 4-6
mocha.css 238-246
Not sure how crucial those rules are, but it sure would be nice if they didn't have to exist ;).
Right now, the permissions for Collections often don't allow client-side insertions/deletions/etc. However, these are needed for a variety of test situations.
Currently I have to hack around them, but it would be very nice to have a supported way to safely allow test-data loading, such that:
Due to the way tests are no copied to the rsync mirror, changes to test files are no longer triggering reloads.
The solution will be to use velocity's file watching patterns.
I'm getting an error on startup with 0.6.0, related to the changes around NPM and the require
statement.
ReferenceError: require is not defined
at null.on_use_handler (/Code/js/meteor/apps/respondly/.meteor/meteorite/packages/mocha-web/package.js:19:14)
at _.extend.use (/.meteorite/meteors/timhaines/meteor/fce2a07e9a445dcdf3d2a7ef6f1d8b6d4c2e2205/tools/bundler.js:445:11)
at self.api.use (/.meteorite/meteors/timhaines/meteor/fce2a07e9a445dcdf3d2a7ef6f1d8b6d4c2e2205/tools/bundler.js:114:21)
at Array.forEach (native)
Thanks!
Hi there!
Hey, I'm being a ditz, and can't seem to get this to work. I've installed mocha-web via mrt, set the environment variable, added {{> mochaTestReport }}, and gotten the HTML test runner (yay!). But then it spits out ReferenceError: assert is not defined
.
Is this a Chai thing? I've tried various things like installing npm install chai
and adding the line var assert = require("assert")
to my test file. But nothing seems to be quite working.
Any ideas????
Thanks!
If I have a sub-directory of within the tests folder, eg:
/root
/tests
/foo
my_test.coffee
The following error occurs on startup:
Errors prevented startup:
Exception while bundling application:
Error: EISDIR, illegal operation on a directory
at Object.fs.readSync (fs.js:381:19)
at Object.fs.readFileSync (fs.js:208:28)
at _.extend.add_file (/Users/Phil/.meteorite/meteors/meteor/meteor/4d98d8cb4e5a95e9e98953f44c872c9332a042a3/app/lib/bundler.js:189:18)
at self.api.add_files (/Users/Phil/.meteorite/meteors/meteor/meteor/4d98d8cb4e5a95e9e98953f44c872c9332a042a3/app/lib/bundler.js:96:16)
at Array.forEach (native)
at Function._.each._.forEach (/Users/Phil/.meteorite/meteors/meteor/meteor/4d98d8cb4e5a95e9e98953f44c872c9332a042a3/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
at self.api.add_files (/Users/Phil/.meteorite/meteors/meteor/meteor/4d98d8cb4e5a95e9e98953f44c872c9332a042a3/app/lib/bundler.js:95:11)
at Array.forEach (native)
at Function._.each._.forEach (/Users/Phil/.meteorite/meteors/meteor/meteor/4d98d8cb4e5a95e9e98953f44c872c9332a042a3/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
at Object.self.api.add_files (/Users/Phil/.meteorite/meteors/meteor/meteor/4d98d8cb4e5a95e9e98953f44c872c9332a042a3/app/lib/bundler.js:94:9)
if i try to make a pending test as :
describe("true", function(){ it('should return true') });
i get this error
Cannot read property 'length' of undefined TypeError: Cannot read property 'length' of undefined
The user should be able to press a button in the velocity-html-reporter and generate sample tests.
Does anyone have examples of doing a dom, helper, or event handler test using mocha-web?
/cc @rissem @timhaines
I'm seeing this in the console upon using a fresh installation. Likely to go away when using iframes, but logging here in any case
PHANTOM-MOCHA-WEB: URLs that use the 'javascript:' protocol are not allowed in URL attribute values. Call UI._allowJavascriptUrls() to enable them.
Right now, mocha-web will run in any mirror. It should only run inside the mocha-web mirror.
Hello!
I've followed all the steps in the README and in the example app but all it seems to be doing is inserting a div with an id of mocha
into the DOM. It's not even running my tests.
Here is exactly what I'm typing in METEOR_MOCHA_TEST_DIR=tests meteor
. Tried METEOR_MOCHA_TEST_DIR="tests" meteor
as well as METEOR_MOCHA_TEST_DIR="tests" mrt
.
Any thoughts? I'm using Meteor 0.7.0.1.
Currently the tests from within the velocity html reporter iFrame are being run twice resulting in two copies of every test result.
Use meteor-mirror or something similar to run mocha-web tests inside their own app (not the same app as velocity)
I can see the complete method being called, but the reports section is empty for mocha web. Is this because it's running in the mirror and doesn't have access to the main reports?
Currently the phantomjs process is created with childProcess.execFile
which returns all of the console output at once after the client side tests have finished running. It would be better to continually receive output as the client side tests run. This may be as easy as just switching to childProcess.spawn
.
I'm not sure what's going on for me, but I assume it's working for you now you've done the update to 0.6.5
However, for me, when I run my existing app that was using mocha-web
and when I run a freshly pulled version of the demo repo:
https://github.com/mad-eye/leaderboard-mocha
I'm getting an error that looks like it's being emitted from the Meteor packer/linker when it attempts to pull all the packages together:
=> Running Meteor from a checkout -- overrides project version (0.6.5)
[[[[[ ~//TEMP/leaderboard-mocha ]]]]]
=> Errors prevented startup:
While building package `mocha-web`:
error: File not found: tests/test.coffee
Are you seeing anything like this? Thanks.
Currently, only files in the root of the test directory are ran.
@rissem Does mocha-web have a way to mark test results as client or server when reporting to Velocity? Querying VelocityTestReports, it does not appear so. I'm thinking this would be useful to add so we can flag and sort results in the reporter.
<h1>Client Tests</h1>
<div>
{{> mochaTestReport}}
</div>
<h1>Server Tests</h1>
<div>
{{> serverTestReport}}
</div>
the test reports do not show up on meteor 0.8.0, only show up when i downgrade to 0.6.5.
As is currently done for server side tests, use a custom mocha reporter to intercept test results and send them to velocity.
I can't seem to figure out the right syntax to load this module.
We're seeing a situation where when we add a new test file, it does not show up in the list of executing tests.
The speculation is that this is because packages are now cached with the linker work that dropped in 0.6.5
.
The new file is added, but perhaps the manifest of files dynamically created within the package.js
file is cached, and that file-loading routine is not run again.
Something like this seems to be going on, because a change to a file within the mocha-web
package itself causes the new test file to appear.
I've asked a question on the Meteor group about whether it's possible to declare a package as "do not cache", here:
https://groups.google.com/forum/?fromgroups#!topic/meteor-talk/aRvc-bYF8Bg
If that is possible, then that may be a simple answer to this.
Are you guys seeing the same behavior?
When all tests have been run
I realize this might be outside the scope of a package called "mocha-web", but I'd personally find it a lot more useful to run tests on the server than on the client (or in addition to on the client). Testing from the client means I have to deal with my Meteor methods doing XHRs and database writes and timing out and so on. If I could just call my methods from a server context, it would be a lot easier to make things run quickly and in isolation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.