mirror of https://gitee.com/bigwinds/arangodb
Tests for the testgod!
This commit is contained in:
parent
4f3adeb879
commit
48abd07dc8
|
@ -0,0 +1,3 @@
|
|||
support
|
||||
test
|
||||
Makefile
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
0.3.0 / 2014-02-20
|
||||
==================
|
||||
|
||||
* renmaed to `index.js`
|
||||
* added repository to package.json
|
||||
* remove unused variable and merge
|
||||
* simpify isDate() and remove unnecessary semicolon.
|
||||
* Add .withArgs() syntax for building scenario
|
||||
* eql(): fix wrong order of actual vs. expected.
|
||||
* Added formatting for Error objects
|
||||
* Add support for 'regexp' type and eql comparison of regular expressions.
|
||||
* Better to follow the same coding style
|
||||
* Use 'showDiff' flag
|
||||
* Add 'actual' & 'expected' property to the thrown error
|
||||
* Pass .fail() unit test
|
||||
* Ignore 'script*' global leak in chrome
|
||||
* Exposed object stringification function
|
||||
* Use isRegExp in Assertion::throwException. Fix #25
|
||||
* Cleaned up local variables
|
||||
|
||||
0.2.0 / 2012-10-19
|
||||
==================
|
||||
|
||||
* fix isRegExp bug in some edge cases
|
||||
* add closure to all assertion messages deferring costly inspects
|
||||
until there is actually a failure
|
||||
* fix `make test` for recent mochas
|
||||
* add inspect() case for DOM elements
|
||||
* relax failure msg null check
|
||||
* add explicit failure through `expect().fail()`
|
||||
* clarified all `empty` functionality in README example
|
||||
* added docs for throwException fn/regexp signatures
|
||||
|
||||
0.1.2 / 2012-02-04
|
||||
==================
|
||||
|
||||
* Added regexp matching support for exceptions.
|
||||
* Added support for throwException callback.
|
||||
* Added `throwError` synonym to `throwException`.
|
||||
* Added object support for `.empty`.
|
||||
* Fixed `.a('object')` with nulls, and english error in error message.
|
||||
* Fix bug `indexOf` (IE). [hokaccha]
|
||||
* Fixed object property checking with `undefined` as value. [vovik]
|
||||
|
||||
0.1.1 / 2011-12-18
|
||||
==================
|
||||
|
||||
* Fixed typo
|
||||
|
||||
0.1.0 / 2011-12-18
|
||||
==================
|
||||
|
||||
* Initial import
|
|
@ -0,0 +1,263 @@
|
|||
# Expect
|
||||
|
||||
Minimalistic BDD assertion toolkit based on
|
||||
[should.js](http://github.com/visionmedia/should.js)
|
||||
|
||||
```js
|
||||
expect(window.r).to.be(undefined);
|
||||
expect({ a: 'b' }).to.eql({ a: 'b' })
|
||||
expect(5).to.be.a('number');
|
||||
expect([]).to.be.an('array');
|
||||
expect(window).not.to.be.an(Image);
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Cross-browser: works on IE6+, Firefox, Safari, Chrome, Opera.
|
||||
- Compatible with all test frameworks.
|
||||
- Node.JS ready (`require('expect.js')`).
|
||||
- Standalone. Single global with no prototype extensions or shims.
|
||||
|
||||
## How to use
|
||||
|
||||
### Node
|
||||
|
||||
Install it with NPM or add it to your `package.json`:
|
||||
|
||||
```
|
||||
$ npm install expect.js
|
||||
```
|
||||
|
||||
Then:
|
||||
|
||||
```js
|
||||
var expect = require('expect.js');
|
||||
```
|
||||
|
||||
### Browser
|
||||
|
||||
Expose the `expect.js` found at the top level of this repository.
|
||||
|
||||
```html
|
||||
<script src="expect.js"></script>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
**ok**: asserts that the value is _truthy_ or not
|
||||
|
||||
```js
|
||||
expect(1).to.be.ok();
|
||||
expect(true).to.be.ok();
|
||||
expect({}).to.be.ok();
|
||||
expect(0).to.not.be.ok();
|
||||
```
|
||||
|
||||
**be** / **equal**: asserts `===` equality
|
||||
|
||||
```js
|
||||
expect(1).to.be(1)
|
||||
expect(NaN).not.to.equal(NaN);
|
||||
expect(1).not.to.be(true)
|
||||
expect('1').to.not.be(1);
|
||||
```
|
||||
|
||||
**eql**: asserts loose equality that works with objects
|
||||
|
||||
```js
|
||||
expect({ a: 'b' }).to.eql({ a: 'b' });
|
||||
expect(1).to.eql('1');
|
||||
```
|
||||
|
||||
**a**/**an**: asserts `typeof` with support for `array` type and `instanceof`
|
||||
|
||||
```js
|
||||
// typeof with optional `array`
|
||||
expect(5).to.be.a('number');
|
||||
expect([]).to.be.an('array'); // works
|
||||
expect([]).to.be.an('object'); // works too, since it uses `typeof`
|
||||
|
||||
// constructors
|
||||
expect(5).to.be.a(Number);
|
||||
expect([]).to.be.an(Array);
|
||||
expect(tobi).to.be.a(Ferret);
|
||||
expect(person).to.be.a(Mammal);
|
||||
```
|
||||
|
||||
**match**: asserts `String` regular expression match
|
||||
|
||||
```js
|
||||
expect(program.version).to.match(/[0-9]+\.[0-9]+\.[0-9]+/);
|
||||
```
|
||||
|
||||
**contain**: asserts indexOf for an array or string
|
||||
|
||||
```js
|
||||
expect([1, 2]).to.contain(1);
|
||||
expect('hello world').to.contain('world');
|
||||
```
|
||||
|
||||
**length**: asserts array `.length`
|
||||
|
||||
```js
|
||||
expect([]).to.have.length(0);
|
||||
expect([1,2,3]).to.have.length(3);
|
||||
```
|
||||
|
||||
**empty**: asserts that an array is empty or not
|
||||
|
||||
```js
|
||||
expect([]).to.be.empty();
|
||||
expect({}).to.be.empty();
|
||||
expect({ length: 0, duck: 'typing' }).to.be.empty();
|
||||
expect({ my: 'object' }).to.not.be.empty();
|
||||
expect([1,2,3]).to.not.be.empty();
|
||||
```
|
||||
|
||||
**property**: asserts presence of an own property (and value optionally)
|
||||
|
||||
```js
|
||||
expect(window).to.have.property('expect')
|
||||
expect(window).to.have.property('expect', expect)
|
||||
expect({a: 'b'}).to.have.property('a');
|
||||
```
|
||||
|
||||
**key**/**keys**: asserts the presence of a key. Supports the `only` modifier
|
||||
|
||||
```js
|
||||
expect({ a: 'b' }).to.have.key('a');
|
||||
expect({ a: 'b', c: 'd' }).to.only.have.keys('a', 'c');
|
||||
expect({ a: 'b', c: 'd' }).to.only.have.keys(['a', 'c']);
|
||||
expect({ a: 'b', c: 'd' }).to.not.only.have.key('a');
|
||||
```
|
||||
|
||||
**throwException**/**throwError**: asserts that the `Function` throws or not when called
|
||||
|
||||
```js
|
||||
expect(fn).to.throwError(); // synonym of throwException
|
||||
expect(fn).to.throwException(function (e) { // get the exception object
|
||||
expect(e).to.be.a(SyntaxError);
|
||||
});
|
||||
expect(fn).to.throwException(/matches the exception message/);
|
||||
expect(fn2).to.not.throwException();
|
||||
```
|
||||
|
||||
**withArgs**: creates anonymous function to call fn with arguments
|
||||
|
||||
```js
|
||||
expect(fn).withArgs(invalid, arg).to.throwException();
|
||||
expect(fn).withArgs(valid, arg).to.not.throwException();
|
||||
```
|
||||
|
||||
**within**: asserts a number within a range
|
||||
|
||||
```js
|
||||
expect(1).to.be.within(0, Infinity);
|
||||
```
|
||||
|
||||
**greaterThan**/**above**: asserts `>`
|
||||
|
||||
```js
|
||||
expect(3).to.be.above(0);
|
||||
expect(5).to.be.greaterThan(3);
|
||||
```
|
||||
|
||||
**lessThan**/**below**: asserts `<`
|
||||
|
||||
```js
|
||||
expect(0).to.be.below(3);
|
||||
expect(1).to.be.lessThan(3);
|
||||
```
|
||||
|
||||
**fail**: explicitly forces failure.
|
||||
|
||||
```js
|
||||
expect().fail()
|
||||
expect().fail("Custom failure message")
|
||||
```
|
||||
|
||||
## Using with a test framework
|
||||
|
||||
For example, if you create a test suite with
|
||||
[mocha](http://github.com/visionmedia/mocha).
|
||||
|
||||
Let's say we wanted to test the following program:
|
||||
|
||||
**math.js**
|
||||
|
||||
```js
|
||||
function add (a, b) { return a + b; };
|
||||
```
|
||||
|
||||
Our test file would look like this:
|
||||
|
||||
```js
|
||||
describe('test suite', function () {
|
||||
it('should expose a function', function () {
|
||||
expect(add).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should do math', function () {
|
||||
expect(add(1, 3)).to.equal(4);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
If a certain expectation fails, an exception will be raised which gets captured
|
||||
and shown/processed by the test runner.
|
||||
|
||||
## Differences with should.js
|
||||
|
||||
- No need for static `should` methods like `should.strictEqual`. For example,
|
||||
`expect(obj).to.be(undefined)` works well.
|
||||
- Some API simplifications / changes.
|
||||
- API changes related to browser compatibility.
|
||||
|
||||
## Running tests
|
||||
|
||||
Clone the repository and install the developer dependencies:
|
||||
|
||||
```
|
||||
git clone git://github.com/LearnBoost/expect.js.git expect
|
||||
cd expect && npm install
|
||||
```
|
||||
|
||||
### Node
|
||||
|
||||
`make test`
|
||||
|
||||
### Browser
|
||||
|
||||
`make test-browser`
|
||||
|
||||
and point your browser(s) to `http://localhost:3000/test/`
|
||||
|
||||
## Credits
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
### 3rd-party
|
||||
|
||||
Heavily borrows from [should.js](http://github.com/visionmedia/should.js) by TJ
|
||||
Holowaychuck - MIT.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "expect.js",
|
||||
"version": "0.3.1",
|
||||
"description": "BDD style assertions for node and the browser.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/LearnBoost/expect.js.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "*",
|
||||
"serve": "*"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/LearnBoost/expect.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/LearnBoost/expect.js",
|
||||
"_id": "expect.js@0.3.1",
|
||||
"dist": {
|
||||
"shasum": "b0a59a0d2eff5437544ebf0ceaa6015841d09b5b",
|
||||
"tarball": "http://registry.npmjs.org/expect.js/-/expect.js-0.3.1.tgz"
|
||||
},
|
||||
"_from": "expect.js@*",
|
||||
"_npmVersion": "1.4.2",
|
||||
"_npmUser": {
|
||||
"name": "rauchg",
|
||||
"email": "rauchg@gmail.com"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "rauchg",
|
||||
"email": "rauchg@gmail.com"
|
||||
}
|
||||
],
|
||||
"directories": {},
|
||||
"_shasum": "b0a59a0d2eff5437544ebf0ceaa6015841d09b5b",
|
||||
"_resolved": "https://registry.npmjs.org/expect.js/-/expect.js-0.3.1.tgz",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
"coffee-script": "1.7.1",
|
||||
"decimal": "0.0.2",
|
||||
"docco": "0.6.3",
|
||||
"expect.js": "^0.3.1",
|
||||
"foxx_generator": "0.5.1",
|
||||
"htmlparser2": "3.7.2",
|
||||
"iced-coffee-script": "1.7.1-f",
|
||||
|
|
|
@ -90,7 +90,7 @@ extend(ConsoleLogs.prototype, {
|
|||
}
|
||||
|
||||
if (exists(cfg.message)) {
|
||||
query = query.filter(qb.LIKE('entry.message', qb.str('%' + cfg.fileName + '%'), true));
|
||||
query = query.filter(qb.LIKE('entry.message', qb.str('%' + cfg.message + '%'), true));
|
||||
}
|
||||
|
||||
query = query.sort('entry.time', 'ASC');
|
||||
|
@ -107,11 +107,11 @@ extend(ConsoleLogs.prototype, {
|
|||
|
||||
var result = db._query(query).toArray();
|
||||
|
||||
if (cfg.opts.sort && cfg.opts.sort.toUpperCase() === 'ASC') {
|
||||
return result;
|
||||
if (cfg.opts.sort && cfg.opts.sort.toUpperCase() === 'DESC') {
|
||||
return result.reverse();
|
||||
}
|
||||
|
||||
return result.reverse();
|
||||
return result;
|
||||
},
|
||||
list: function (opts) {
|
||||
return this._query({opts: opts});
|
||||
|
@ -147,11 +147,11 @@ function Console(mount, tracing) {
|
|||
this.warn = this.custom('WARN', 1);
|
||||
this.error = this.custom('ERROR', 2);
|
||||
|
||||
this.assert._level = 'ERROR';
|
||||
this.dir._level = 'INFO';
|
||||
this.log._level = 'INFO';
|
||||
this.time._level = 'INFO';
|
||||
this.trace._level = 'TRACE';
|
||||
this.assert.level = 'ERROR';
|
||||
this.dir.level = 'INFO';
|
||||
this.log.level = 'INFO';
|
||||
this.time.level = 'INFO';
|
||||
this.trace.level = 'TRACE';
|
||||
}
|
||||
|
||||
extend(Console.prototype, {
|
||||
|
@ -206,7 +206,7 @@ extend(Console.prototype, {
|
|||
operator: '==',
|
||||
stackStartFunction: this.assert
|
||||
});
|
||||
this._log(this.assert._level, err.stack, this.assert);
|
||||
this._log(this.assert.level, err.stack, this.assert);
|
||||
if (this._assertThrows) {
|
||||
throw err;
|
||||
}
|
||||
|
@ -214,11 +214,11 @@ extend(Console.prototype, {
|
|||
},
|
||||
|
||||
dir: function (obj) {
|
||||
this._log(this.dir._level, util.inspect(obj));
|
||||
this._log(this.dir.level, util.inspect(obj));
|
||||
},
|
||||
|
||||
log: function () {
|
||||
this._log(this.log._level, util.format.apply(null, arguments));
|
||||
this._log(this.log.level, util.format.apply(null, arguments));
|
||||
},
|
||||
|
||||
time: function (label) {
|
||||
|
@ -226,11 +226,11 @@ extend(Console.prototype, {
|
|||
},
|
||||
|
||||
timeEnd: function (label) {
|
||||
if (!this._timers.hasOwnProperty(label)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(this._timers, label)) {
|
||||
throw new Error('No such label: ' + label);
|
||||
}
|
||||
this._log(
|
||||
this.time._level,
|
||||
this.time.level,
|
||||
util.format('%s: %dms', label, Date.now() - this._timers[label]),
|
||||
this.time
|
||||
);
|
||||
|
@ -241,7 +241,7 @@ extend(Console.prototype, {
|
|||
var trace = new Error(message);
|
||||
trace.name = 'Trace';
|
||||
Error.captureStackTrace(trace, this.trace);
|
||||
this._log(this.trace._level, trace.stack);
|
||||
this._log(this.trace.level, trace.stack);
|
||||
},
|
||||
|
||||
custom: function (level, weight) {
|
||||
|
|
|
@ -0,0 +1,343 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tests for Foxx console
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2015 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Alan Plum
|
||||
/// @author Copyright 2015, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var jsunity = require('jsunity');
|
||||
var expect = require('expect.js');
|
||||
var util = require('util');
|
||||
var Console = require('org/arangodb/foxx/console').Console;
|
||||
var db = require('org/arangodb').db;
|
||||
var qb = require('aqb');
|
||||
|
||||
var mountPath = '##TEST##';
|
||||
|
||||
function ls() {
|
||||
if (!db._foxxlog) {
|
||||
return [];
|
||||
}
|
||||
return db._query(
|
||||
qb.for('entry').in('_foxxlog')
|
||||
.filter(qb.eq('entry.mount', qb.str(mountPath)))
|
||||
.sort('entry.time', 'ASC')
|
||||
.return('entry')
|
||||
).toArray();
|
||||
}
|
||||
|
||||
function rmrf() {
|
||||
if (!db._foxxlog) {
|
||||
return [];
|
||||
}
|
||||
return db._query(
|
||||
qb.for('entry').in('_foxxlog')
|
||||
.filter(qb.eq('entry.mount', qb.str(mountPath)))
|
||||
.remove('entry').in('_foxxlog')
|
||||
).toArray();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function ConsoleTestSuite () {
|
||||
var console;
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp: function () {
|
||||
console = new Console(mountPath);
|
||||
rmrf();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown: function () {
|
||||
rmrf();
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tests
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testConsoleLogLogsMessage: function () {
|
||||
rmrf();
|
||||
console.log('hi');
|
||||
var logs = ls();
|
||||
expect(logs.length).to.be(1);
|
||||
expect(logs[0]).to.have.property('level', 'INFO');
|
||||
expect(logs[0]).to.have.property('levelNum', console._logLevels.INFO);
|
||||
expect(logs[0]).to.have.property('message', 'hi');
|
||||
},
|
||||
|
||||
testConsoleLogUsesFormat: function () {
|
||||
rmrf();
|
||||
console.log('%s prevails', 'the goddess');
|
||||
console.log('%s plus', 1, 2);
|
||||
var logs = ls();
|
||||
expect(logs[0]).to.have.property('message', 'the goddess prevails');
|
||||
expect(logs[1]).to.have.property('message', '1 plus 2');
|
||||
},
|
||||
|
||||
testConsoleLogLogsTime: function () {
|
||||
rmrf();
|
||||
var min = Date.now();
|
||||
console.log('hi');
|
||||
var max = Date.now();
|
||||
var logs = ls();
|
||||
expect(logs[0]).to.have.property('time');
|
||||
expect(logs[0].time).to.be.a('number');
|
||||
expect(logs[0].time).not.to.be.lessThan(min);
|
||||
expect(logs[0].time).not.to.be.greaterThan(max);
|
||||
},
|
||||
|
||||
testConsoleTimeLogsDuration: function () {
|
||||
rmrf();
|
||||
var start = Date.now();
|
||||
console.time('hi');
|
||||
var min = Date.now();
|
||||
console.timeEnd('hi');
|
||||
var max = Date.now();
|
||||
var logs = ls();
|
||||
var match = logs[0].message.match(/^([^:]+):\s+(\d+)ms$/);
|
||||
expect(match).to.be.ok();
|
||||
expect(match[1]).to.equal('hi');
|
||||
expect(Number(match[2])).not.to.be.lessThan(min - start);
|
||||
expect(Number(match[2])).not.to.be.greaterThan(max - start);
|
||||
},
|
||||
|
||||
testConsoleTimeThrowsForInvalidLabel: function () {
|
||||
expect(function () {
|
||||
console.timeEnd('this is a label that does not exist');
|
||||
}).to.throwError();
|
||||
},
|
||||
|
||||
testConsoleDirUsesInspect: function () {
|
||||
var args = [
|
||||
'lol',
|
||||
{_PRINT: function (ctx) {ctx.output += 'hello';}}
|
||||
];
|
||||
rmrf();
|
||||
args.forEach(function (arg) {
|
||||
console.dir(arg);
|
||||
});
|
||||
var logs = ls();
|
||||
args.forEach(function (arg, i) {
|
||||
expect(logs[i]).to.have.property('message', util.inspect(arg));
|
||||
});
|
||||
},
|
||||
|
||||
testConsoleAssertDoesNotThrow: function () {
|
||||
rmrf();
|
||||
console.setAssertThrows(false);
|
||||
expect(function () {
|
||||
console.assert(false, 'potato');
|
||||
}).not.to.throwError();
|
||||
var logs = ls();
|
||||
expect(logs.length).to.equal(1);
|
||||
expect(logs[0]).to.have.property('level', 'ERROR');
|
||||
expect(logs[0]).to.have.property('levelNum', console._logLevels.ERROR);
|
||||
expect(logs[0].message).to.match(/AssertionError: potato/);
|
||||
},
|
||||
|
||||
testConsoleAssertThrows: function () {
|
||||
rmrf();
|
||||
console.setAssertThrows(true);
|
||||
expect(function () {
|
||||
console.assert(false, 'potato');
|
||||
}).to.throwError(function (e) {
|
||||
expect(e.name).to.be('AssertionError');
|
||||
expect(e.message).to.be('potato');
|
||||
});
|
||||
var logs = ls();
|
||||
expect(logs.length).to.equal(1);
|
||||
expect(logs[0].message).to.match(/AssertionError: potato/);
|
||||
},
|
||||
|
||||
testConsoleLogLevelPreventsLogging: function () {
|
||||
rmrf();
|
||||
console._logLevels.POTATO = -999;
|
||||
console.setLogLevel(-2);
|
||||
console.log.level = 'POTATO';
|
||||
console.log('potato');
|
||||
console.log.level = 'INFO';
|
||||
delete console._logLevels.POTATO;
|
||||
var logs = ls();
|
||||
expect(logs).to.be.empty();
|
||||
},
|
||||
|
||||
testConsoleTracingAddsInfo: function () {
|
||||
rmrf();
|
||||
console.setTracing(false);
|
||||
console.log('without tracing');
|
||||
console.setTracing(true);
|
||||
console.log('with tracing');
|
||||
console.setTracing(false);
|
||||
var logs = ls();
|
||||
expect(logs[0]).not.to.have.property('stack');
|
||||
expect(logs[1]).to.have.property('stack');
|
||||
expect(logs[1].stack).to.be.an('array');
|
||||
expect(logs[1].stack[0]).to.have.property('fileName');
|
||||
expect(logs[1].stack[0]).to.have.property('lineNumber');
|
||||
expect(logs[1].stack[0]).to.have.property('columnNumber');
|
||||
},
|
||||
|
||||
testCustomLogLevels: function () {
|
||||
rmrf();
|
||||
var log = console.custom('BATMAN', 9000);
|
||||
log('potato');
|
||||
var logs = ls();
|
||||
expect(logs.length).to.equal(1);
|
||||
expect(logs[0]).to.have.property('level', 'BATMAN');
|
||||
expect(logs[0]).to.have.property('levelNum', 9000);
|
||||
expect(logs[0]).to.have.property('message', 'potato');
|
||||
},
|
||||
|
||||
testTrace: function () {
|
||||
rmrf();
|
||||
console.trace('wat');
|
||||
var logs = ls();
|
||||
expect(logs.length).to.equal(1);
|
||||
expect(logs[0]).to.have.property('level', 'TRACE');
|
||||
expect(logs[0]).to.have.property('levelNum', console._logLevels.TRACE);
|
||||
expect(logs[0].message).to.match(/^Trace: wat\n\s+at/);
|
||||
},
|
||||
|
||||
testLogsListWithDefaults: function () {
|
||||
rmrf();
|
||||
console.log('sup');
|
||||
console.log('banana');
|
||||
var logs = console.logs.list();
|
||||
expect(logs.length).to.be(2);
|
||||
expect(logs[0]).to.have.property('message', 'sup');
|
||||
expect(logs[1]).to.have.property('message', 'banana');
|
||||
},
|
||||
|
||||
testLogsListWithSortDESC: function () {
|
||||
rmrf();
|
||||
console.log('sup');
|
||||
console.log('banana');
|
||||
var logs = console.logs.list({sort: 'DESC'});
|
||||
expect(logs.length).to.be(2);
|
||||
expect(logs[0]).to.have.property('message', 'banana');
|
||||
expect(logs[1]).to.have.property('message', 'sup');
|
||||
},
|
||||
|
||||
testLogsListWithLimit: function () {
|
||||
rmrf();
|
||||
console.log('sup');
|
||||
console.log('banana');
|
||||
var logs = console.logs.list({limit: 1});
|
||||
expect(logs.length).to.be(1);
|
||||
expect(logs[0]).to.have.property('message', 'sup');
|
||||
},
|
||||
|
||||
testLogsListWithLimitAndOffset: function () {
|
||||
rmrf();
|
||||
console.log('sup');
|
||||
console.log('banana');
|
||||
var logs = console.logs.list({limit: 1, offset: 1});
|
||||
expect(logs.length).to.be(1);
|
||||
expect(logs[0]).to.have.property('message', 'banana');
|
||||
},
|
||||
|
||||
testLogsListWithMinLevel: function () {
|
||||
rmrf();
|
||||
var logs;
|
||||
console.debug('lol');
|
||||
console.error('hey');
|
||||
logs = console.logs.list({minLevel: 'DEBUG'});
|
||||
expect(logs.length).to.be(2);
|
||||
logs = console.logs.list({minLevel: console._logLevels.DEBUG + 1});
|
||||
expect(logs.length).to.be(1);
|
||||
expect(logs[0]).to.have.property('message', 'hey');
|
||||
logs = console.logs.list({minLevel: console._logLevels.ERROR + 1});
|
||||
expect(logs.length).to.be(0);
|
||||
},
|
||||
|
||||
testLogsListWithLevel: function () {
|
||||
rmrf();
|
||||
var logs;
|
||||
console.debug('lol');
|
||||
console.error('hey');
|
||||
logs = console.logs.list({level: 'DEBUG'});
|
||||
expect(logs.length).to.be(1);
|
||||
expect(logs[0]).to.have.property('message', 'lol');
|
||||
},
|
||||
|
||||
testLogsSearchByFileNameFailsWithoutTracing: function () {
|
||||
console.setTracing(false);
|
||||
expect(function () {
|
||||
console.logs.searchByFileName('lol');
|
||||
}).to.throwError(function (e) {
|
||||
expect(e.message).to.match(/tracing/i);
|
||||
});
|
||||
},
|
||||
|
||||
testLogsSearchByFileName: function () {
|
||||
rmrf();
|
||||
console.setTracing(true);
|
||||
db._foxxlog.save({
|
||||
mount: mountPath,
|
||||
time: Date.now(),
|
||||
stack: [
|
||||
{fileName: 'abcdef'}
|
||||
]
|
||||
});
|
||||
expect(console.logs.searchByFileName('bcd')).to.have.property('length', 1);
|
||||
expect(console.logs.searchByFileName('ab')).to.have.property('length', 1);
|
||||
expect(console.logs.searchByFileName('ef')).to.have.property('length', 1);
|
||||
expect(console.logs.searchByFileName('fail')).to.have.property('length', 0);
|
||||
},
|
||||
|
||||
testLogsSearchByMessage: function () {
|
||||
rmrf();
|
||||
console.log('abcdef');
|
||||
expect(console.logs.searchByMessage('bcd')).to.have.property('length', 1);
|
||||
expect(console.logs.searchByMessage('ab')).to.have.property('length', 1);
|
||||
expect(console.logs.searchByMessage('ef')).to.have.property('length', 1);
|
||||
expect(console.logs.searchByMessage('fail')).to.have.property('length', 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(ConsoleTestSuite);
|
||||
|
||||
return jsunity.done();
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
|
||||
// End:
|
||||
|
Loading…
Reference in New Issue