Example #1
0
assert.isEmpty = function (actual, message) {
    assertMissingArguments(arguments, assert.isEmpty);
    if ((isObject(actual) && Object.keys(actual).length > 0) || actual.length > 0) {
        assert.fail(actual, 0, message || "expected {actual} to be empty", "length", assert.isEmpty);
    }
};
Example #2
0
 handleMarkdown: function() {
   assert.fail("should never run IndexDocument::handleMarkdown");
 },
Example #3
0
assert.lengthOf = function (actual, expected, message) {
    var len = isObject(actual) ? Object.keys(actual).length : actual.length;
    if (len !== expected) {
        assert.fail(actual, expected, message || "expected {actual} to have {expected} element(s)", "length", assert.length);
    }
};
Example #4
0
 }, function (err) {
   assert.fail(err);
   done();
 });
Example #5
0
 return proxy.to({ host: 'no.such.domain', port: 80 }, { data: 'hello, world!' }).then(function () {
     assert.fail('should not have resolved promise');
 }, function (reason) {
Example #6
0
 stream.on('drain', function() {
   assert.fail('\'drain\' event must not be emitted before ' +
               'stream.write() has been called at least once.');
 });
Example #7
0
 var to = setTimeout(function () {
     assert.fail('never ran');
 }, 5000);
Example #8
0
assert.isDefined = function (actual, message) {
    assertMissingArguments(arguments, assert.isDefined);
    if(actual === undefined) {
        assert.fail(actual, 0, message || "expected {actual} to be defined", "===", assert.isDefined);
    }
};
Example #9
0
assert.instanceOf = function (actual, expected, message) {
    if (! (actual instanceof expected)) {
        assert.fail(actual, expected, message || "expected {actual} to be an instance of {expected}", "instanceof", assert.instanceOf);
    }
};
Example #10
0
assert.epsilon = function (eps, actual, expected, message) {
    assertMissingArguments(arguments, assert.epsilon);
    if (Math.abs(actual - expected) > eps) {
        assert.fail(actual, expected, message || "expected {expected} \u00B1"+ eps +", but was {actual}");
    }
};
Example #11
0
assert.isUndefined = function (actual, message) {
    assertMissingArguments(arguments, assert.isUndefined);
    if (actual !== undefined) {
        assert.fail(actual, undefined, message || "expected {actual} to be {expected}", "===", assert.isUndefined);
    }
};
Example #12
0
assert.isNotNull = function (actual, message) {
    assertMissingArguments(arguments, assert.isNotNull);
    if (actual === null) {
        assert.fail(actual, null, message || "expected non-null value, got {actual}", "===", assert.isNotNull);
    }
};
Example #13
0
assert.isNull = function (actual, message) {
    assertMissingArguments(arguments, assert.isNull);
    if (actual !== null) {
        assert.fail(actual, null, message || "expected {expected}, got {actual}", "===", assert.isNull);
    }
};
Example #14
0
assert.isNaN = function (actual, message) {
    assertMissingArguments(arguments, assert.isNaN);
    if (actual === actual) {
        assert.fail(actual, 'NaN', message || "expected {actual} to be NaN", "===", assert.isNaN);
    }
};
Example #15
0
 /**
  * Check if the AST was changed
  * @param {ASTNode} beforeAST AST node before running
  * @param {ASTNode} afterAST AST node after running
  * @returns {void}
  * @private
  */
 function assertASTDidntChange(beforeAST, afterAST) {
     if (!lodash.isEqual(beforeAST, afterAST)) {
         assert.fail(null, null, "Rule should not modify AST.");
     }
 }
Example #16
0
function assertMissingArguments(args, caller) {
    if (args.length === 0) {
        assert.fail("", "", "expected number of arguments to be greater than zero", "", caller);
    }
}
Example #17
0
        /**
         * Check if the template is invalid or not
         * all invalid cases go through this.
         * @param {string|Object} item Item to run the rule against
         * @returns {void}
         * @private
         */
        function testInvalidTemplate(item) {
            assert.ok(item.errors || item.errors === 0,
                `Did not specify errors for an invalid test of ${ruleName}`);

            const result = runRuleForItem(item);
            const messages = result.messages;


            if (typeof item.errors === "number") {
                assert.strictEqual(messages.length, item.errors, util.format("Should have %d error%s but had %d: %s",
                    item.errors, item.errors === 1 ? "" : "s", messages.length, util.inspect(messages)));
            } else {
                assert.strictEqual(
                    messages.length, item.errors.length,
                    util.format(
                        "Should have %d error%s but had %d: %s",
                        item.errors.length, item.errors.length === 1 ? "" : "s", messages.length, util.inspect(messages)
                    )
                );

                const hasMessageOfThisRule = messages.some(m => m.ruleId === ruleName);

                for (let i = 0, l = item.errors.length; i < l; i++) {
                    const error = item.errors[i];
                    const message = messages[i];

                    assert(!message.fatal, `A fatal parsing error occurred: ${message.message}`);
                    assert(hasMessageOfThisRule, "Error rule name should be the same as the name of the rule being tested");

                    if (typeof error === "string" || error instanceof RegExp) {

                        // Just an error message.
                        assertMessageMatches(message.message, error);
                    } else if (typeof error === "object") {

                        /*
                         * Error object.
                         * This may have a message, messageId, data, node type, line, and/or
                         * column.
                         */
                        if (hasOwnProperty(error, "message")) {
                            assert.ok(!hasOwnProperty(error, "messageId"), "Error should not specify both 'message' and a 'messageId'.");
                            assert.ok(!hasOwnProperty(error, "data"), "Error should not specify both 'data' and 'message'.");
                            assertMessageMatches(message.message, error.message);
                        } else if (hasOwnProperty(error, "messageId")) {
                            assert.ok(
                                hasOwnProperty(rule, "meta") && hasOwnProperty(rule.meta, "messages"),
                                "Error can not use 'messageId' if rule under test doesn't define 'meta.messages'."
                            );
                            if (!hasOwnProperty(rule.meta.messages, error.messageId)) {
                                const friendlyIDList = `[${Object.keys(rule.meta.messages).map(key => `'${key}'`).join(", ")}]`;

                                assert(false, `Invalid messageId '${error.messageId}'. Expected one of ${friendlyIDList}.`);
                            }
                            assert.strictEqual(
                                error.messageId,
                                message.messageId,
                                `messageId '${message.messageId}' does not match expected messageId '${error.messageId}'.`
                            );
                            if (hasOwnProperty(error, "data")) {

                                /*
                                 *  if data was provided, then directly compare the returned message to a synthetic
                                 *  interpolated message using the same message ID and data provided in the test.
                                 *  See https://github.com/eslint/eslint/issues/9890 for context.
                                 */
                                const unformattedOriginalMessage = rule.meta.messages[error.messageId];
                                const rehydratedMessage = interpolate(unformattedOriginalMessage, error.data);

                                assert.strictEqual(
                                    message.message,
                                    rehydratedMessage,
                                    `Hydrated message "${rehydratedMessage}" does not match "${message.message}"`
                                );
                            }
                        }

                        assert.ok(
                            hasOwnProperty(error, "data") ? hasOwnProperty(error, "messageId") : true,
                            "Error must specify 'messageId' if 'data' is used."
                        );

                        if (error.type) {
                            assert.strictEqual(message.nodeType, error.type, `Error type should be ${error.type}, found ${message.nodeType}`);
                        }

                        if (error.hasOwnProperty("line")) {
                            assert.strictEqual(message.line, error.line, `Error line should be ${error.line}`);
                        }

                        if (error.hasOwnProperty("column")) {
                            assert.strictEqual(message.column, error.column, `Error column should be ${error.column}`);
                        }

                        if (error.hasOwnProperty("endLine")) {
                            assert.strictEqual(message.endLine, error.endLine, `Error endLine should be ${error.endLine}`);
                        }

                        if (error.hasOwnProperty("endColumn")) {
                            assert.strictEqual(message.endColumn, error.endColumn, `Error endColumn should be ${error.endColumn}`);
                        }
                    } else {

                        // Message was an unexpected type
                        assert.fail(message, null, "Error should be a string, object, or RegExp.");
                    }
                }
            }

            if (item.hasOwnProperty("output")) {
                if (item.output === null) {
                    assert.strictEqual(
                        messages.filter(message => message.fix).length,
                        0,
                        "Expected no autofixes to be suggested"
                    );
                } else {
                    const fixResult = SourceCodeFixer.applyFixes(item.code, messages);

                    assert.strictEqual(fixResult.output, item.output, "Output is incorrect.");
                }
            }

            assertASTDidntChange(result.beforeAST, result.afterAST);
        }
Example #18
0
function assertTypeOf(actual, expected, message, caller) {
    if (typeOf(actual) !== expected) {
        assert.fail(actual, expected, message || "expected {actual} to be of type {expected}", "typeOf", caller);
    }
}
Example #19
0
var assert = require('assert');

assert.fail(1, 2, '', '==');
Example #20
0
assert.match = function (actual, expected, message) {
    assertMissingArguments(arguments, assert.match);
    if (! expected.test(actual)) {
        assert.fail(actual, expected, message || "expected {actual} to match {expected}", "match", assert.match);
    }
};
Example #21
0
 var result = notifier.start(250, undefined, function (err) {
   assert.fail(err, "[not undefined]", "should never have been called", "?");
 });
Example #22
0
assert.isFalse = function (actual, message) {
    assertMissingArguments(arguments, assert.isFalse);
    if (actual !== false) {
        assert.fail(actual, false, message || "expected {expected}, got {actual}", "===", assert.isFalse);
    }
};
 .then(function() {
   fail('it should have timed out');
 }).catch(function(e) {
Example #24
0
assert.isZero = function (actual, message) {
    assertMissingArguments(arguments, assert.isZero);
    if (actual !== 0) {
        assert.fail(actual, 0, message || "expected {expected}, got {actual}", "===", assert.isZero);
    }
};
Example #25
0
 return proxy.to({ host: 'localhost', port: 18000 }, { data: 'hello, world!' }).then(function () {
     assert.fail('should not have resolved promise');
 }, function (reason) {
Example #26
0
assert.isNotZero = function (actual, message) {
    assertMissingArguments(arguments, assert.isNotZero);
    if (actual === 0) {
        assert.fail(actual, 0, message || "expected non-zero value, got {actual}", "===", assert.isNotZero);
    }
};
Example #27
0
assert.isNotEmpty = function (actual, message) {
    if ((isObject(actual) && Object.keys(actual).length === 0) || actual.length === 0) {
        assert.fail(actual, 0, message || "expected {actual} to be not empty", "length", assert.isNotEmpty);
    }
};
Example #28
0
assert.lesser = function (actual, expected, message) {
    assertMissingArguments(arguments, assert.lesser);
    if (actual >= expected) {
        assert.fail(actual, expected, message || "expected {actual} to be lesser than {expected}", "<", assert.lesser);
    }
};
Example #29
0
assert.isBoolean = function (actual, message) {
    if (actual !== true && actual !== false) {
        assert.fail(actual, 'boolean', message || "expected {actual} to be a Boolean", "===", assert.isBoolean);
    }
};
Example #30
0
function expectSuccess() {
  assert.fail();
}