foobarfighter / foounit Goto Github PK
View Code? Open in Web Editor NEWA simple but powerful cross-platform BDD test framework
License: Other
A simple but powerful cross-platform BDD test framework
License: Other
All nested tests under an xdescribe block should be marked as pending. This is much nicer than commenting out an entire spec file.
Here are some ideas
// when calling env right before a describe or an 'it' block it only runs that test in that particular environment
env('node', 'browser');
describe('runs in node and the browser but not in air', function (){
...
});
or
// env can double as a describe
env('node', 'this doubles as a describe block', function (){
});
This needs a much better name though.
You are mentioning BDD everywhere on your website foounit.org and in the documentation. For a ignorant like me, it would be nice to have a quick introduction or a least some links to what that means. Hope I'm not being to nitpicking.
This may only be true for before blocks that run asynchronous blocks. Example (waitFor fails):
describe('foounit.server.loader', function (){
var server, client;
before(function (){
server = TestServer.start('0.0.0.0', 5999);
client = new TestClient('0.0.0.0.', 5999);
client.get('/status');
waitFor(function (){
var response = client.inbox.takeNext();
console.log(response.body);
expect(response.body.indexOf('status:')).to(beGt, -1);
});
});
after(function (){
server.stop();
client.stop();
});
it('passes', function (){
console.log('w00t!');
});
});
waitFor should show the last error message from the block, not just timeout exceeded.
I find myself repeating suite.js in every project that I create that requires multi-environment support. I would be nice if there was a foounit cmdline util that just runs the suite as one might expect.
// TODO: This would be cool.
run(function (){
client.get('/status');
});
// ensure would rerun the "run" block previous after it timed-out
// it would continue to rerun the "run" block until it timed-out N times
ensure(function (){
response = client.inbox.takeNext();
expect(response.body).to(include, 'status:');
});
Right now two befores in the same group will replace the first before with the second before. FAIL.
Hey man. Loving foounit so far!
I just wanted to let you know an issue I ran into working to add foounit browser tests to EpicEditor - which relies on Marked.
Seems like passing a param with the name module
will break packages that rely on that keyword to check environment. More and more packages are doing things like this to try to be flexible enough to run in multiple contexts. In this case, it looks like Marked is added to the incorrect - or at least different/unexpected - scope.
(function(){
if (typeof module !== 'undefined') {
module.exports = marked;
} else {
this.marked = marked;
}
}).call(this);
(function (window, undefined) {
// Some other module
})(window);
this.require = function (path){
var code = get(path)
, module = { exports: {} }
, funcString = '(function (foounit, module, exports, __dirname, __filename){' + code + '});';
try {
var func = leval(funcString, path);
func.call({}, foounit, module, module.exports, dirname(path), basename(path));
} catch (e){
console.error('Failed to load path: ' + path + ': ' + e.message, e);
}
return module.exports;
};
I couldn't see where this was being used so I just removed references to module
and exports
as a temporary fix.
Let me know if I am missing something here. Maybe there is another way to wrap the code so that it doesn't cause conflicts, or maybe we should be setting up differently on our end?
Thanks.
This currently happens when loading using the XHR loading strategy
When using mock to test ajax calls I ran into this issue.
var req = {
url: 'foo'
, method: 'POST'
, beforeSend: function() {
expect(this.method).to(equal, 'POST');
expect(this.type).to(equal, 'POST');
}
}
req.beforeSend = mock(req, 'beforeSend', req.beforeSend);
makeRequest(req);
waitFor(function() {
expect(req.beforeSend).to(haveBeenCalled);
}, 1000);
This fails because in the beforeSend function, this
is actually not the original request object, but a new object that has been "normalized" by adding/modifying some values. But once beforeSend is mocked, it is always called with the original context. Instead the stub function should be called with the current value of this
.
foounit.report and foounit.reportExample should call foounit.onFinished and foounit.onExampleFinished respectably.
Also, to save stress it would be cool if the IE tracebacks were really apologetic:
"IE6 failed at running this test, but it fails at lots of things, it's probably not you. We're very sorry, here's a link to a picture of a kitten. And a traceback:"
Right now it looks like each test gets a unique context (e.g. this
). But the context should be shared by the before()
and after()
methods. This enables you to set up test-specific state and clean it up without polluting each actual test or polluting the closure scope. See example.
describe('testing the context', function() {
before(function() {
this.foo = 'unit';
});
after(function() {
this.foo = null;
});
it('should have the context set', function() {
expect(this.foo).to(be, 'unit');
});
});
The test context should probably be cleared out after each test too. e.g. all properties set to null.
Foounit has waitFor and waitForTimeout keywords for doing asynchronous testing. But these aren't good for the simple use case of running a simple function once. What I'm doing is mocking ajax calls. Here's a simplified example.
var fakeAjax = {
send: function(req) {
var fakexhr;
foounit.setTimeout(function() {
req.success && req.success('data', 'success', fakeXHR);
}, 10);
}
}
The problem comes in when I want to put expect statements inside the success function. Since setTimeout isn't test aware, the errors propagate to the top of the runtime but do not make the test fail. Here's the simplest test for this issue.
foounit.add(function (kw){ with (kw){
describe('waitFor', function() {
it('fails if timeout throws', function() {
var end = false;
foounit.setTimeout(function() {
end = true;
expect(false).to(beTrue);
}, 100);
waitFor(function() {
expect(end).to(beTrue);
}, 1000);
});
});
}});
This test passes, but the expect in setTimeout should be caught and cause it to fail.
We don't get great stack trace info in all of the browsers.
Creates a mocked function with an empty implementation
Example:
var func = function (){};
mock(func);
expect(func).to(haveBeenCalled)
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.