Socket
Socket
Sign inDemoInstall

mocha

Package Overview
Dependencies
4
Maintainers
1
Versions
192
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.11.0 to 0.12.0

lib/context.js

1

lib/hook.js

@@ -24,2 +24,3 @@

Runnable.call(this, title, fn);
this.type = 'hook';
}

@@ -26,0 +27,0 @@

@@ -18,2 +18,3 @@

exports.Runnable = require('./runnable');
exports.Context = require('./context');
exports.Runner = require('./runner');

@@ -20,0 +21,0 @@ exports.Suite = require('./suite');

3

lib/runnable.js

@@ -30,3 +30,2 @@

this.timedOut = false;
this.context = this;
}

@@ -108,3 +107,3 @@

, start = new Date
, ctx = this.context
, ctx = this.ctx
, finished

@@ -111,0 +110,0 @@ , emitted;

@@ -159,3 +159,3 @@

self.currentRunnable = hook;
hook.context = self.test;
hook.ctx.test(self.test);

@@ -269,2 +269,3 @@ self.emit('hook', hook);

try {
test.ctx.test(test);
test.on('error', function(err){

@@ -271,0 +272,0 @@ self.fail(test, err);

@@ -31,3 +31,3 @@

exports.create = function(parent, title){
var suite = new Suite(title);
var suite = new Suite(title, parent.ctx);
suite.parent = parent;

@@ -40,10 +40,13 @@ title = suite.fullTitle();

/**
* Initialize a new `Suite` with the given `title`.
* Initialize a new `Suite` with the given
* `title` and `ctx`.
*
* @param {String} title
* @param {Context} ctx
* @api private
*/
function Suite(title) {
function Suite(title, ctx) {
this.title = title;
this.ctx = ctx;
this.suites = [];

@@ -124,2 +127,3 @@ this.tests = [];

hook.timeout(this.timeout());
hook.ctx = this.ctx;
this._beforeAll.push(hook);

@@ -142,2 +146,3 @@ this.emit('beforeAll', hook);

hook.timeout(this.timeout());
hook.ctx = this.ctx;
this._afterAll.push(hook);

@@ -160,2 +165,3 @@ this.emit('afterAll', hook);

hook.timeout(this.timeout());
hook.ctx = this.ctx;
this._beforeEach.push(hook);

@@ -178,2 +184,3 @@ this.emit('beforeEach', hook);

hook.timeout(this.timeout());
hook.ctx = this.ctx;
this._afterEach.push(hook);

@@ -212,2 +219,3 @@ this.emit('afterEach', hook);

test.timeout(this.timeout());
test.ctx = this.ctx;
this.tests.push(test);

@@ -214,0 +222,0 @@ this.emit('test', test);

@@ -33,1 +33,18 @@

Test.prototype.__proto__ = Runnable.prototype;
/**
* Inspect the context void of private properties.
*
* @return {String}
* @api private
*/
Test.prototype.inspect = function(){
return JSON.stringify(this, function(key, val){
return '_' == key[0]
? undefined
: 'parent' == key
? '#<Suite>'
: val;
}, 2);
};
{
"name": "mocha"
, "version": "0.11.0"
, "version": "0.12.0"
, "description": "simple, flexible, fun test framework"

@@ -5,0 +5,0 @@ , "keywords": ["test", "bdd", "tdd", "tap"]

@@ -71,6 +71,12 @@

;(function(){
var suite = new mocha.Suite
var suite = new mocha.Suite('', new mocha.Context)
, utils = mocha.utils
, Reporter = mocha.reporters.HTML
$(function(){
$('code').each(function(){
$(this).html(highlight($(this).text()));
});
});
/**

@@ -77,0 +83,0 @@ * Highlight the given string of `js`.

@@ -5,4 +5,15 @@

before(function(){
this.age = 2;
})
after(function(){
this.age.should.equal(2);
this.name.should.equal('Tobi');
this.inspect().should.equal('{\n "age": 2,\n "name": "Tobi"\n}');
})
beforeEach(function(){
this.name = 'Tobi';
this.age.should.equal(2);
})

@@ -17,6 +28,7 @@

this.name.should.equal('Tobi');
this.age.should.equal(2);
})
it('should be unique to the test-case', function(){
this.should.not.equal(prev);
it('should provide the same object', function(){
this.should.equal(prev);
})

@@ -29,2 +41,3 @@

this.name = 'Tobi';
this.age.should.equal(2);
done();

@@ -44,4 +57,4 @@ })

it('should be unique to the test-case', function(done){
this.should.not.equal(prev);
it('should provide the same object', function(done){
this.should.equal(prev);
done();

@@ -48,0 +61,0 @@ })

@@ -0,2 +1,4 @@

var mocha = require('../')
, Context = mocha.Context
, Suite = mocha.Suite

@@ -6,50 +8,4 @@ , Test = mocha.Test;

describe('Suite', function(){
describe('when initialized', function(){
describe('.clone()', function(){
beforeEach(function(){
this.suite = new Suite('A Suite');
});
it('is initialized with a title', function(){
this.suite.title.should.equal('A Suite');
});
it('the suites array is empty', function(){
this.suite.suites.should.be.empty;
});
it('the tests array is empty', function(){
this.suite.tests.should.be.empty;
});
it('the _beforeEach array is empty', function(){
this.suite._beforeEach.should.be.empty;
});
it('the _beforeAll array is empty', function(){
this.suite._beforeEach.should.be.empty;
});
it('the _afterEach array is empty', function(){
this.suite._afterEach.should.be.empty;
});
it('the _afterAll array is empty', function(){
this.suite._afterAll.should.be.empty;
});
it('the root is false', function(){
this.suite.root.should.be.false;
});
it('the _timeout is 2000', function(){
this.suite._timeout.should.equal(2000);
});
it('the _bail is false', function(){
this.suite._bail.should.be.false;
});
});
describe('cloning', function(){
beforeEach(function(){
this.suite = new Suite('To be cloned');

@@ -66,45 +22,40 @@ this.suite._timeout = 3043;

describe('copies', function(){
it('the title', function(){
this.suite.clone().title.should.equal('To be cloned');
});
it('should copy the title', function(){
this.suite.clone().title.should.equal('To be cloned');
});
it('the timeout value', function(){
this.suite.clone().timeout().should.equal(3043);
});
it('should copy the timeout value', function(){
this.suite.clone().timeout().should.equal(3043);
});
it('the bail value', function(){
this.suite.clone().bail().should.be.true;
});
it('should copy the bail value', function(){
this.suite.clone().bail().should.be.true;
});
describe('does NOT copy', function(){
it('the values from the suites array', function(){
this.suite.clone().suites.should.be.empty;
});
it('should not copy the values from the suites array', function(){
this.suite.clone().suites.should.be.empty;
});
it('the values from the tests array', function(){
this.suite.clone().tests.should.be.empty;
});
it('should not copy the values from the tests array', function(){
this.suite.clone().tests.should.be.empty;
});
it('the values from the _beforeEach array', function(){
this.suite.clone()._beforeEach.should.be.empty;
});
it('should not copy the values from the _beforeEach array', function(){
this.suite.clone()._beforeEach.should.be.empty;
});
it('the values from the _beforeAll array', function(){
this.suite.clone()._beforeAll.should.be.empty;
});
it('should not copy the values from the _beforeAll array', function(){
this.suite.clone()._beforeAll.should.be.empty;
});
it('the values from the _afterEach array', function(){
this.suite.clone()._afterEach.should.be.empty;
});
it('should not copy the values from the _afterEach array', function(){
this.suite.clone()._afterEach.should.be.empty;
});
it('the values from the _afterAll array', function(){
this.suite.clone()._afterAll.should.be.empty;
});
it('should not copy the values from the _afterAll array', function(){
this.suite.clone()._afterAll.should.be.empty;
});
});
describe('timeout', function(){
describe('.timeout()', function(){
beforeEach(function(){

@@ -115,3 +66,3 @@ this.suite = new Suite('A Suite');

describe('when no argument is passed', function(){
it('returns the _timeout value', function(){
it('should return the timeout value', function(){
this.suite.timeout().should.equal(2000);

@@ -122,3 +73,3 @@ });

describe('when argument is passed', function(){
it('returns the Suite object', function(){
it('should return the Suite object', function(){
var newSuite = this.suite.timeout(5000);

@@ -130,3 +81,3 @@ newSuite.timeout().should.equal(5000);

describe('bail', function(){
describe('.bail()', function(){
beforeEach(function(){

@@ -138,3 +89,3 @@ this.suite = new Suite('A Suite');

describe('when no argument is passed', function(){
it('returns the _bail value', function(){
it('should return the bail value', function(){
this.suite.bail().should.be.true;

@@ -145,3 +96,3 @@ });

describe('when argument is passed', function(){
it('returns the Suite object', function(){
it('should return the Suite object', function(){
var newSuite = this.suite.bail(false);

@@ -153,3 +104,3 @@ newSuite.bail().should.be.false;

describe('beforeAll', function(){
describe('.beforeAll()', function(){
beforeEach(function(){

@@ -172,3 +123,3 @@ this.suite = new Suite('A Suite');

describe('afterAll', function(){
describe('.afterAll()', function(){
beforeEach(function(){

@@ -191,3 +142,3 @@ this.suite = new Suite('A Suite');

describe('beforeEach', function(){
describe('.beforeEach()', function(){
beforeEach(function(){

@@ -210,3 +161,3 @@ this.suite = new Suite('A Suite');

describe('afterEach', function(){
describe('.afterEach()', function(){
beforeEach(function(){

@@ -229,47 +180,47 @@ this.suite = new Suite('A Suite');

describe('addSuite', function(){
describe('.addSuite()', function(){
beforeEach(function(){
this.suite = new Suite('A Suite');
this.suite.timeout(4002);
this.suiteToAdd = new Suite('Suite to Add');
this.suite.addSuite(this.suiteToAdd);
this.first = new Suite('First suite');
this.first.timeout(4002);
this.second = new Suite('Second suite');
this.first.addSuite(this.second);
});
it('sets the parent on the added Suite', function(){
this.suiteToAdd.parent.should.equal(this.suite);
this.second.parent.should.equal(this.first);
});
it('copies the timeout value', function(){
this.suiteToAdd.timeout().should.equal(4002);
this.second.timeout().should.equal(4002);
});
it('adds the suite to the suites collection', function(){
this.suite.suites.should.have.length(1);
this.suite.suites[0].should.equal(this.suiteToAdd);
this.first.suites.should.have.length(1);
this.first.suites[0].should.equal(this.second);
});
});
describe('addTest', function(){
beforeEach(function(){
this.suite = new Suite('A Suite');
this.suite.timeout(4002);
this.test = new Test('Suite to Add');
this.suite.addTest(this.test);
});
// describe('.addTest()', function(){
// beforeEach(function(){
// this.suite = new Suite('A Suite', new Context);
// this.suite.timeout(4002);
// this.test = new Test('test');
// this.suite.addTest(this.test);
// });
//
// it('sets the parent on the added test', function(){
// this.test.parent.should.equal(this.suite);
// });
//
// it('copies the timeout value', function(){
// this.test.timeout().should.equal(4002);
// });
//
// it('adds the test to the tests collection', function(){
// this.suite.tests.should.have.length(1);
// this.suite.tests[0].should.equal(this.test);
// });
// });
it('sets the parent on the added test', function(){
this.test.parent.should.equal(this.suite);
});
it('copies the timeout value', function(){
this.test.timeout().should.equal(4002);
});
it('adds the test to the tests collection', function(){
this.suite.tests.should.have.length(1);
this.suite.tests[0].should.equal(this.test);
});
});
describe('fullTitle', function(){
describe('.fullTitle()', function(){
beforeEach(function(){

@@ -294,3 +245,3 @@ this.suite = new Suite('A Suite');

describe('total', function(){
describe('.total()', function(){
beforeEach(function(){

@@ -300,4 +251,4 @@ this.suite = new Suite('A Suite');

describe('when there are no other suites or tests under the suite', function(){
it('returns 0', function(){
describe('when there are no nested suites or tests', function(){
it('should return 0', function(){
this.suite.total().should.equal(0);

@@ -307,4 +258,4 @@ });

describe('when there are two tests under the suite', function(){
it('returns 2', function(){
describe('when there are several tests in the suite', function(){
it('should return the number', function(){
this.suite.addTest(new Test('a child test'));

@@ -311,0 +262,0 @@ this.suite.addTest(new Test('another child test'));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc