Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
Prettier all
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Aug 28, 2017
1 parent 6114e76 commit 6c1e6bd
Show file tree
Hide file tree
Showing 38 changed files with 1,712 additions and 1,381 deletions.
60 changes: 34 additions & 26 deletions lib/assertion-error.js
Expand Up @@ -4,9 +4,9 @@
* Copyright(c) 2013-2017 Denis Bardadym <bardadymchik@gmail.com>
* MIT Licensed
*/
import { merge } from 'should-util';
import { functionName } from './util';
import { format } from './format';
import { merge } from "should-util";
import { functionName } from "./util";
import { format } from "./format";

/**
* should AssertionError
Expand All @@ -19,18 +19,17 @@ export default function AssertionError(options) {
merge(this, options);

if (!options.message) {
Object.defineProperty(this, 'message', {
get: function() {
if (!this._message) {
this._message = this.generateMessage();
this.generatedMessage = true;
}
return this._message;
},
configurable: true,
enumerable: false
}
);
Object.defineProperty(this, "message", {
get: function() {
if (!this._message) {
this._message = this.generateMessage();
this.generatedMessage = true;
}
return this._message;
},
configurable: true,
enumerable: false
});
}

if (Error.captureStackTrace) {
Expand All @@ -44,11 +43,11 @@ export default function AssertionError(options) {
if (this.stackStartFunction) {
// try to strip useless frames
var fn_name = functionName(this.stackStartFunction);
var idx = out.indexOf('\n' + fn_name);
var idx = out.indexOf("\n" + fn_name);
if (idx >= 0) {
// once we have located the function frame
// we need to strip out everything before it (and its line)
var next_line = out.indexOf('\n', idx + 1);
var next_line = out.indexOf("\n", idx + 1);
out = out.substring(next_line + 1);
}
}
Expand All @@ -58,21 +57,19 @@ export default function AssertionError(options) {
}
}


var indent = ' ';
var indent = " ";
function prependIndent(line) {
return indent + line;
}

function indentLines(text) {
return text.split('\n').map(prependIndent).join('\n');
return text.split("\n").map(prependIndent).join("\n");
}


// assert.AssertionError instanceof Error
AssertionError.prototype = Object.create(Error.prototype, {
name: {
value: 'AssertionError'
value: "AssertionError"
},

generateMessage: {
Expand All @@ -81,12 +78,23 @@ AssertionError.prototype = Object.create(Error.prototype, {
return this.previous.message;
}
var actual = format(this.actual);
var expected = 'expected' in this ? ' ' + format(this.expected) : '';
var details = 'details' in this && this.details ? ' (' + this.details + ')' : '';
var expected = "expected" in this ? " " + format(this.expected) : "";
var details =
"details" in this && this.details ? " (" + this.details + ")" : "";

var previous = this.previous ? '\n' + indentLines(this.previous.message) : '';
var previous = this.previous
? "\n" + indentLines(this.previous.message)
: "";

return 'expected ' + actual + (this.negate ? ' not ' : ' ') + this.operator + expected + details + previous;
return (
"expected " +
actual +
(this.negate ? " not " : " ") +
this.operator +
expected +
details +
previous
);
}
}
});
15 changes: 13 additions & 2 deletions lib/assertion.js
Expand Up @@ -274,11 +274,22 @@ Assertion.addChain = function(name, onCall) {
Assertion.alias = function(from, to) {
var desc = Object.getOwnPropertyDescriptor(Assertion.prototype, from);
if (!desc) {
throw new Error("Alias " + from + " -> " + to + " could not be created as " + from + " not defined");
throw new Error(
"Alias " +
from +
" -> " +
to +
" could not be created as " +
from +
" not defined"
);
}
Object.defineProperty(Assertion.prototype, to, desc);

var desc2 = Object.getOwnPropertyDescriptor(PromisedAssertion.prototype, from);
var desc2 = Object.getOwnPropertyDescriptor(
PromisedAssertion.prototype,
from
);
if (desc2) {
Object.defineProperty(PromisedAssertion.prototype, to, desc2);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/config.js
Expand Up @@ -5,8 +5,8 @@
* MIT Licensed
*/

import format from 'should-format';
import { defaultTypeAdaptorStorage } from 'should-type-adaptors';
import format from "should-format";
import { defaultTypeAdaptorStorage } from "should-type-adaptors";

var config = {
typeAdaptors: defaultTypeAdaptorStorage,
Expand Down
40 changes: 23 additions & 17 deletions lib/ext/_assert.js
Expand Up @@ -27,9 +27,9 @@
// when used in node, this will actually load the util module we depend on
// versus loading the builtin util module as happens otherwise
// this is a bug in node module loading as far as I am concerned
import { Assertion } from './../assertion';
import { Assertion } from "./../assertion";

import _deepEqual from 'should-equal';
import _deepEqual from "should-equal";

var pSlice = Array.prototype.slice;

Expand Down Expand Up @@ -86,7 +86,7 @@ assert.fail = fail;
*/
function ok(value, message) {
if (!value) {
fail(value, true, message, '==', assert.ok);
fail(value, true, message, "==", assert.ok);
}
}
assert.ok = ok;
Expand All @@ -106,7 +106,7 @@ assert.ok = ok;
*/
assert.equal = function equal(actual, expected, message) {
if (actual != expected) {
fail(actual, expected, message, '==', assert.equal);
fail(actual, expected, message, "==", assert.equal);
}
};

Expand All @@ -123,7 +123,7 @@ assert.equal = function equal(actual, expected, message) {
*/
assert.notEqual = function notEqual(actual, expected, message) {
if (actual == expected) {
fail(actual, expected, message, '!=', assert.notEqual);
fail(actual, expected, message, "!=", assert.notEqual);
}
};

Expand All @@ -142,11 +142,10 @@ assert.notEqual = function notEqual(actual, expected, message) {
*/
assert.deepEqual = function deepEqual(actual, expected, message) {
if (_deepEqual(actual, expected).length !== 0) {
fail(actual, expected, message, 'deepEqual', assert.deepEqual);
fail(actual, expected, message, "deepEqual", assert.deepEqual);
}
};


// 8. The non-equivalence assertion tests for any deep inequality.
// assert.notDeepEqual(actual, expected, message_opt);
/**
Expand All @@ -162,7 +161,7 @@ assert.deepEqual = function deepEqual(actual, expected, message) {
*/
assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
if (_deepEqual(actual, expected).result) {
fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
fail(actual, expected, message, "notDeepEqual", assert.notDeepEqual);
}
};

Expand All @@ -179,7 +178,7 @@ assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
*/
assert.strictEqual = function strictEqual(actual, expected, message) {
if (actual !== expected) {
fail(actual, expected, message, '===', assert.strictEqual);
fail(actual, expected, message, "===", assert.strictEqual);
}
};

Expand All @@ -196,7 +195,7 @@ assert.strictEqual = function strictEqual(actual, expected, message) {
*/
assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
if (actual === expected) {
fail(actual, expected, message, '!==', assert.notStrictEqual);
fail(actual, expected, message, "!==", assert.notStrictEqual);
}
};

Expand All @@ -205,7 +204,7 @@ function expectedException(actual, expected) {
return false;
}

if (Object.prototype.toString.call(expected) == '[object RegExp]') {
if (Object.prototype.toString.call(expected) == "[object RegExp]") {
return expected.test(actual);
} else if (actual instanceof expected) {
return true;
Expand All @@ -219,7 +218,7 @@ function expectedException(actual, expected) {
function _throws(shouldThrow, block, expected, message) {
var actual;

if (typeof expected == 'string') {
if (typeof expected == "string") {
message = expected;
expected = null;
}
Expand All @@ -230,18 +229,25 @@ function _throws(shouldThrow, block, expected, message) {
actual = e;
}

message = (expected && expected.name ? ' (' + expected.name + ')' : '.') +
(message ? ' ' + message : '.');
message =
(expected && expected.name ? " (" + expected.name + ")" : ".") +
(message ? " " + message : ".");

if (shouldThrow && !actual) {
fail(actual, expected, 'Missing expected exception' + message);
fail(actual, expected, "Missing expected exception" + message);
}

if (!shouldThrow && expectedException(actual, expected)) {
fail(actual, expected, 'Got unwanted exception' + message);
fail(actual, expected, "Got unwanted exception" + message);
}

if ((shouldThrow && actual && expected && !expectedException(actual, expected)) || (!shouldThrow && actual)) {
if (
(shouldThrow &&
actual &&
expected &&
!expectedException(actual, expected)) ||
(!shouldThrow && actual)
) {
throw actual;
}
}
Expand Down
12 changes: 7 additions & 5 deletions lib/ext/assert.js
Expand Up @@ -5,9 +5,9 @@
* MIT Licensed
*/

import { merge } from 'should-util';
import assert from './_assert';
import AssertionError from '../assertion-error';
import { merge } from "should-util";
import assert from "./_assert";
import AssertionError from "../assertion-error";

export default function(should) {
var i = should.format;
Expand Down Expand Up @@ -40,7 +40,8 @@ export default function(should) {
should.exist = should.exists = function(obj, msg) {
if (null == obj) {
throw new AssertionError({
message: msg || ('expected ' + i(obj) + ' to exist'), stackStartFunction: should.exist
message: msg || "expected " + i(obj) + " to exist",
stackStartFunction: should.exist
});
}
};
Expand All @@ -64,7 +65,8 @@ export default function(should) {
should.not.exist = should.not.exists = function(obj, msg) {
if (null != obj) {
throw new AssertionError({
message: msg || ('expected ' + i(obj) + ' to not exist'), stackStartFunction: should.not.exist
message: msg || "expected " + i(obj) + " to not exist",
stackStartFunction: should.not.exist
});
}
};
Expand Down
12 changes: 6 additions & 6 deletions lib/ext/bool.js
Expand Up @@ -21,11 +21,11 @@ export default function(should, Assertion) {
*
* ({ a: 10}).should.not.be.true();
*/
Assertion.add('true', function(message) {
Assertion.add("true", function(message) {
this.is.exactly(true, message);
});

Assertion.alias('true', 'True');
Assertion.alias("true", "True");

/**
* Assert given object is exactly `false`.
Expand All @@ -40,11 +40,11 @@ export default function(should, Assertion) {
* (true).should.not.be.false();
* false.should.be.false();
*/
Assertion.add('false', function(message) {
Assertion.add("false", function(message) {
this.is.exactly(false, message);
});

Assertion.alias('false', 'False');
Assertion.alias("false", "False");

/**
* Assert given object is truthy according javascript type conversions.
Expand All @@ -62,8 +62,8 @@ export default function(should, Assertion) {
* (10).should.be.ok();
* (0).should.not.be.ok();
*/
Assertion.add('ok', function() {
this.params = { operator: 'to be truthy' };
Assertion.add("ok", function() {
this.params = { operator: "to be truthy" };

this.assert(this.obj);
});
Expand Down
16 changes: 15 additions & 1 deletion lib/ext/chain.js
Expand Up @@ -26,7 +26,21 @@ export default function(should, Assertion) {
* @alias Assertion#it
* @category assertion chaining
*/
['an', 'of', 'a', 'and', 'be', 'been', 'has', 'have', 'with', 'is', 'which', 'the', 'it'].forEach(function(name) {
[
"an",
"of",
"a",
"and",
"be",
"been",
"has",
"have",
"with",
"is",
"which",
"the",
"it"
].forEach(function(name) {
Assertion.addChain(name);
});
}

0 comments on commit 6c1e6bd

Please sign in to comment.