From 91f680205a01094da6d71ea38b6fd46fc55be40f Mon Sep 17 00:00:00 2001 From: Ben Lichtman Date: Tue, 28 Jan 2020 11:09:29 -0800 Subject: [PATCH] Revert "[assert] Add support for TypeScript's Assertion Functions" (#41916) * Revert "[assert] Add support for TypeScript's Assertion Functions (#41616)" This reverts commit 1eb97992fe9fd91a678e042a1ff178c8d5eb4310. * Update oracledb tests --- types/asenv/asenv-tests.ts | 4 +- types/assert/assert-tests.ts | 42 ---- types/assert/index.d.ts | 17 +- types/bintrees/bintrees-tests.ts | 15 +- types/bookshelf/bookshelf-tests.ts | 4 +- types/bser/test/tests.ts | 36 ++- types/cbor/cbor-tests.ts | 6 +- .../express-handlebars-tests.ts | 1 + types/fbemitter/fbemitter-tests.ts | 118 +++++---- types/hapi/v16/test/server/info.ts | 6 +- types/libpq/libpq-tests.ts | 224 +++++++++--------- types/memcached/memcached-tests.ts | 14 +- types/multireducer/multireducer-tests.ts | 4 +- types/oracledb/oracledb-tests.ts | 33 +-- types/oracledb/v3/index.d.ts | 2 +- types/oracledb/v3/oracledb-tests.ts | 20 +- types/pako/pako-tests.ts | 14 +- types/pigpio/pigpio-tests.ts | 78 +++--- types/project-oxford/project-oxford-tests.ts | 166 +++++++------ types/range_check/range_check-tests.ts | 4 +- .../rgrove__parse-xml-tests.ts | 13 +- types/sanctuary/sanctuary-tests.ts | 9 +- types/seed-random/seed-random-tests.ts | 21 +- .../set-cookie-parser-tests.ts | 70 +++--- .../sort-object-keys-tests.ts | 10 +- types/superagent/superagent-tests.ts | 6 +- types/superagent/v2/superagent-tests.ts | 4 +- .../whatwg-mimetype/whatwg-mimetype-tests.ts | 4 +- types/xmlpoke/xmlpoke-tests.ts | 40 ++-- types/yadda/yadda-tests.ts | 3 + 30 files changed, 451 insertions(+), 537 deletions(-) diff --git a/types/asenv/asenv-tests.ts b/types/asenv/asenv-tests.ts index a2e88cd1bb..0448672d10 100644 --- a/types/asenv/asenv-tests.ts +++ b/types/asenv/asenv-tests.ts @@ -1,7 +1,5 @@ import { unlessProduction, isDevelopment, isTest, isProduction, getEnv, setEnv } from 'asenv'; - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function equal(actual: T, expected: T, message?: string): void; +import { equal, throws } from 'assert'; // Test isDevelopment() setEnv('development'); diff --git a/types/assert/assert-tests.ts b/types/assert/assert-tests.ts index 13f68f04ce..3f795f0552 100644 --- a/types/assert/assert-tests.ts +++ b/types/assert/assert-tests.ts @@ -9,45 +9,3 @@ assert.throws(() => {}, /Regex test/); assert.throws(() => {}, () => {}, "works wonderfully"); assert['fail'](true, true, "works like a charm"); - -{ - const a = null as any; - assert.ifError(a); - a; // $ExpectType null | undefined -} - -{ - const a = true as boolean; - assert(a); - a; // $ExpectType true -} - -{ - const a = 13 as number | null | undefined; - assert(a); - a; // $ExpectType number -} - -{ - const a = true as boolean; - assert.ok(a); - a; // $ExpectType true -} - -{ - const a = 13 as number | null | undefined; - assert.ok(a); - a; // $ExpectType number -} - -{ - const a = 'test' as any; - assert.strictEqual(a, 'test'); - a; // $ExpectType string -} - -{ - const a = { b: 2 } as any; - assert.deepStrictEqual(a, { b: 2 }); - a; // $ExpectType { b: number; } -} diff --git a/types/assert/index.d.ts b/types/assert/index.d.ts index 71944b2332..f436b7b4fd 100644 --- a/types/assert/index.d.ts +++ b/types/assert/index.d.ts @@ -3,32 +3,25 @@ // Definitions by: Nico Gallinal // Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.7 -declare function assert(value: any, message?: string): asserts value; +declare function assert(value: any, message?: string): void; declare namespace assert { function fail(actual?: any, expected?: any, message?: string, operator?: string): void; - function ok(value: any, message?: string): asserts value; + function ok(value: any, message?: string): void; - /** @deprecated Use `strictEqual` instead */ function equal(actual: any, expected: any, message?: string): void; - /** @deprecated Use `notStrictEqual` instead */ function notEqual(actual: any, expected: any, message?: string): void; - /** @deprecated Use `deepStrictEqual` instead */ function deepEqual(actual: any, expected: any, message?: string): void; - /** @deprecated Use `notDeepStrictEqual` instead */ function notDeepEqual(actual: any, expected: any, message?: string): void; - function deepStrictEqual(actual: any, expected: T, message?: string): asserts actual is T; + function deepStrictEqual(actual: any, expected: any, message?: string): void; - function notDeepStrictEqual(actual: any, expected: any, message?: string): void; - - function strictEqual(actual: any, expected: T, message?: string): asserts actual is T; + function strictEqual(actual: any, expected: any, message?: string): void; function notStrictEqual(actual: any, expected: any, message?: string): void; @@ -38,7 +31,7 @@ declare namespace assert { function doesNotThrow(block: () => void, message?: string): void; function doesNotThrow(block: () => void, error: (() => void) | ((err: any) => boolean) | RegExp, message?: string): void; - function ifError(value: any): asserts value is null | undefined; + function ifError(value: any): void; class AssertionError implements Error { name: string; diff --git a/types/bintrees/bintrees-tests.ts b/types/bintrees/bintrees-tests.ts index fa15dff55d..84b75c98be 100644 --- a/types/bintrees/bintrees-tests.ts +++ b/types/bintrees/bintrees-tests.ts @@ -1,10 +1,8 @@ /// +import assert = require('assert'); import { BinTree, RBTree } from 'bintrees'; -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T): void; - -// Declaring shims removes mocha dependency. These tests are never executed, only typechecked, so this is fine. +// Declaring shims removes mocha dependency. These tests are never executed, only typechecked, so this is fine. declare function describe(description: string, callback: () => void): void; declare function it(description: string, callback: () => void): void; @@ -16,7 +14,7 @@ describe('bintrees', () => { treeA.insert(3); treeA.remove(3); - assertEqual(treeA.size, 1); + assert.equal(treeA.size, 1); }); it('builds a tree of strings', () => { @@ -28,8 +26,8 @@ describe('bintrees', () => { treeB.insert('are'); // ignored treeB.remove('how'); - assertEqual(treeB.size, 2); - assertEqual(treeB.min(), 'hi'); + assert.equal(treeB.size, 2); + assert.equal(treeB.min(), 'hi'); }); it('maintains a tree of objects', () => { @@ -49,6 +47,7 @@ describe('bintrees', () => { ids.push(val.id); }); - assertEqual(ids, [100, 105, 110]); + assert.deepEqual(ids, [100, 105, 110]); }); }); + diff --git a/types/bookshelf/bookshelf-tests.ts b/types/bookshelf/bookshelf-tests.ts index e44d326953..81c42f7680 100644 --- a/types/bookshelf/bookshelf-tests.ts +++ b/types/bookshelf/bookshelf-tests.ts @@ -1,11 +1,9 @@ import Knex = require('knex'); import Bookshelf = require('bookshelf'); +import assert = require('assert'); import * as express from 'express'; import * as _ from "lodash"; -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; - /** * The examples/tests below follow Bookshelf documentation chapter after chapter: http://bookshelfjs.org/ */ diff --git a/types/bser/test/tests.ts b/types/bser/test/tests.ts index 444472dc39..2037e0517b 100644 --- a/types/bser/test/tests.ts +++ b/types/bser/test/tests.ts @@ -1,8 +1,6 @@ import * as bser from "bser"; import Int64 from "node-int64"; - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T, message?: string): void; +import * as assert from "assert"; // This is a hard-coded template representation from the C test suite const template = @@ -13,7 +11,7 @@ const template = "\x1e\x0c\x03\x19"; const val = bser.loadFromBuffer(template); -assertEqual(val, [ +assert.deepStrictEqual(val, [ { name: "fred", age: 20 }, { name: "pete", age: 30 }, { age: 25 } @@ -22,7 +20,7 @@ assertEqual(val, [ function roundtrip(val: any) { const encoded = bser.dumpToBuffer(val); const decoded = bser.loadFromBuffer(encoded); - assertEqual(decoded, val); + assert.deepStrictEqual(decoded, val); } const values_to_test = [ @@ -58,31 +56,31 @@ roundtrip(values_to_test); // Verify Accumulator edge cases const acc = new bser.Accumulator(8); acc.append("hello"); -assertEqual(acc.readAvail(), 5); -assertEqual(acc.readOffset, 0); -assertEqual(acc.readString(3), "hel"); -assertEqual(acc.readOffset, 3); -assertEqual(acc.readAvail(), 2); -assertEqual(acc.writeAvail(), 3); +assert.equal(acc.readAvail(), 5); +assert.equal(acc.readOffset, 0); +assert.equal(acc.readString(3), "hel"); +assert.equal(acc.readOffset, 3); +assert.equal(acc.readAvail(), 2); +assert.equal(acc.writeAvail(), 3); // This should trigger a shunt and not make the buffer bigger acc.reserve(5); -assertEqual(acc.readOffset, 0, "shunted"); -assertEqual(acc.readAvail(), 2, "still have 2 available to read"); -assertEqual(acc.writeAvail(), 6, "2 left to read out of 8 total space"); -assertEqual(acc.peekString(2), "lo", "have the correct remainder"); +assert.equal(acc.readOffset, 0, "shunted"); +assert.equal(acc.readAvail(), 2, "still have 2 available to read"); +assert.equal(acc.writeAvail(), 6, "2 left to read out of 8 total space"); +assert.equal(acc.peekString(2), "lo", "have the correct remainder"); // Don't include keys that have undefined values const res = bser.dumpToBuffer({ expression: undefined }); -assertEqual(bser.loadFromBuffer(res), {}); +assert.deepStrictEqual(bser.loadFromBuffer(res), {}); // Dump numbers without fraction to integers let buffer; buffer = bser.dumpToBuffer(1); -assertEqual(buffer.toString("hex"), "000105020000000301"); +assert.equal(buffer.toString("hex"), "000105020000000301"); buffer = bser.dumpToBuffer(1.0); -assertEqual(buffer.toString("hex"), "000105020000000301"); +assert.equal(buffer.toString("hex"), "000105020000000301"); // Dump numbers with fraction to double buffer = bser.dumpToBuffer(1.1); -assertEqual(buffer.toString("hex"), "00010509000000079a9999999999f13f"); +assert.equal(buffer.toString("hex"), "00010509000000079a9999999999f13f"); diff --git a/types/cbor/cbor-tests.ts b/types/cbor/cbor-tests.ts index 96e729a51e..388e82abee 100644 --- a/types/cbor/cbor-tests.ts +++ b/types/cbor/cbor-tests.ts @@ -1,14 +1,12 @@ import cbor = require('cbor'); +import assert = require('assert'); import fs = require('fs'); -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; - let encoded = cbor.encode(true); // returns cbor.decodeFirst(encoded, (error, obj) => { // error != null if there was an error // obj is the unpacked object - assert(obj === true); + assert.ok(obj === true); }); // Use integers as keys? diff --git a/types/express-handlebars/express-handlebars-tests.ts b/types/express-handlebars/express-handlebars-tests.ts index 285815faab..86479c7909 100644 --- a/types/express-handlebars/express-handlebars-tests.ts +++ b/types/express-handlebars/express-handlebars-tests.ts @@ -1,5 +1,6 @@ import express = require('express'); import exphbs = require('express-handlebars'); +import assert = require('assert'); var app = express(); diff --git a/types/fbemitter/fbemitter-tests.ts b/types/fbemitter/fbemitter-tests.ts index 2645c6471c..22f39bc21c 100644 --- a/types/fbemitter/fbemitter-tests.ts +++ b/types/fbemitter/fbemitter-tests.ts @@ -8,9 +8,7 @@ import { EventEmitter, EventSubscription } from 'fbemitter'; import * as util from 'util'; - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T): void; +import * as assert from 'assert'; // Stub mocha functions const {describe, it, before, after, beforeEach, afterEach} = null as any as { @@ -30,8 +28,8 @@ describe('EventEmitter', function tests() { var moop = new Beast() , meap = new Beast(); - assertEqual(moop instanceof Beast, true); - assertEqual(moop instanceof EventEmitter, true); + assert.strictEqual(moop instanceof Beast, true); + assert.strictEqual(moop instanceof EventEmitter, true); moop.listeners('click'); meap.listeners('click'); @@ -50,8 +48,8 @@ describe('EventEmitter', function tests() { , e = new EventEmitter(); e.addListener('foo', function (bar: string) { - assertEqual(bar, 'bar'); - assertEqual(this, context); + assert.strictEqual(bar, 'bar'); + assert.strictEqual(this, context); done(); }, context); @@ -69,8 +67,8 @@ describe('EventEmitter', function tests() { } e.once('args', function () { - assertEqual(arguments.length, args.length); - assertEqual(Array.prototype.slice.call(arguments), args); + assert.strictEqual(arguments.length, args.length); + assert.deepStrictEqual(Array.prototype.slice.call(arguments), args); }); e.emit.apply(e, (['args'] as any[]).concat(args)); @@ -88,23 +86,23 @@ describe('EventEmitter', function tests() { } e.once('args', function () { - assertEqual(arguments.length, args.length); - assertEqual(Array.prototype.slice.call(arguments), args); + assert.strictEqual(arguments.length, args.length); + assert.deepStrictEqual(Array.prototype.slice.call(arguments), args); }); e.once('args', function () { - assertEqual(arguments.length, args.length); - assertEqual(Array.prototype.slice.call(arguments), args); + assert.strictEqual(arguments.length, args.length); + assert.deepStrictEqual(Array.prototype.slice.call(arguments), args); }); e.once('args', function () { - assertEqual(arguments.length, args.length); - assertEqual(Array.prototype.slice.call(arguments), args); + assert.strictEqual(arguments.length, args.length); + assert.deepStrictEqual(Array.prototype.slice.call(arguments), args); }); e.once('args', function () { - assertEqual(arguments.length, args.length); - assertEqual(Array.prototype.slice.call(arguments), args); + assert.strictEqual(arguments.length, args.length); + assert.deepStrictEqual(Array.prototype.slice.call(arguments), args); }); e.emit.apply(e, (['args'] as any[]).concat(args)); @@ -116,13 +114,13 @@ describe('EventEmitter', function tests() { var e = new EventEmitter(); e.addListener('foo', function (bar: string) { - assertEqual(this, { foo: 'bar' }); - assertEqual(bar, 'bar'); + assert.deepStrictEqual(this, { foo: 'bar' }); + assert.strictEqual(bar, 'bar'); }, { foo: 'bar' }); e.addListener('foo', function (bar: string) { - assertEqual(this, { bar: 'baz' }); - assertEqual(bar, 'bar'); + assert.deepStrictEqual(this, { bar: 'baz' }); + assert.strictEqual(bar, 'bar'); }, { bar: 'baz' }); e.emit('foo', 'bar'); @@ -142,18 +140,18 @@ describe('EventEmitter', function tests() { e.once('write', writer, 'banana'); e.emit('write'); - assertEqual(pattern, 'foobazbarbanana'); + assert.strictEqual(pattern, 'foobazbarbanana'); }); it('receives the emitted events', function (done) { var e = new EventEmitter(); e.addListener('data', function (a: string, b: EventEmitter, c: Date, d: void, undef: void) { - assertEqual(a, 'foo'); - assertEqual(b, e); - assertEqual(c instanceof Date, true); - assertEqual(undef, undefined); - assertEqual(arguments.length, 3); + assert.strictEqual(a, 'foo'); + assert.strictEqual(b, e); + assert.strictEqual(c instanceof Date, true); + assert.strictEqual(undef, undefined); + assert.strictEqual(arguments.length, 3); done(); }); @@ -175,7 +173,7 @@ describe('EventEmitter', function tests() { e.emit('foo'); - assertEqual(pattern.join(';'), 'foo1;foo2'); + assert.strictEqual(pattern.join(';'), 'foo1;foo2'); }); }); @@ -184,8 +182,8 @@ describe('EventEmitter', function tests() { it('returns an empty array if no listeners are specified', function () { var e = new EventEmitter(); - assertEqual(e.listeners('foo') instanceof Array, true); - assertEqual(e.listeners('foo').length, 0); + assert.strictEqual(e.listeners('foo') instanceof Array, true); + assert.strictEqual(e.listeners('foo').length, 0); }); it('returns an array of function', function () { @@ -194,10 +192,10 @@ describe('EventEmitter', function tests() { function foo() {} e.addListener('foo', foo); - assertEqual(e.listeners('foo') instanceof Array, true); - assertEqual(e.listeners('foo').length, 1); + assert.strictEqual(e.listeners('foo') instanceof Array, true); + assert.strictEqual(e.listeners('foo').length, 1); console.log(e.listeners('foo')[0]); - assertEqual(e.listeners('foo')[0], foo); + assert.strictEqual(e.listeners('foo')[0], foo); }); it('is not vulnerable to modifications', function () { @@ -207,10 +205,10 @@ describe('EventEmitter', function tests() { e.addListener('foo', foo); - assertEqual(e.listeners('foo')[0], foo); + assert.strictEqual(e.listeners('foo')[0], foo); e.listeners('foo').length = 0; - assertEqual(e.listeners('foo')[0], foo); + assert.strictEqual(e.listeners('foo')[0], foo); }); }); @@ -229,8 +227,8 @@ describe('EventEmitter', function tests() { e.emit('foo'); e.emit('foo'); - assertEqual(e.listeners('foo').length, 0); - assertEqual(calls, 1); + assert.strictEqual(e.listeners('foo').length, 0); + assert.strictEqual(calls, 1); }); it('only emits once if emits are nested inside the listener', function () { @@ -243,8 +241,8 @@ describe('EventEmitter', function tests() { }); e.emit('foo'); - assertEqual(e.listeners('foo').length, 0); - assertEqual(calls, 1); + assert.strictEqual(e.listeners('foo').length, 0); + assert.strictEqual(calls, 1); }); it('only emits once for multiple events', function () { @@ -271,10 +269,10 @@ describe('EventEmitter', function tests() { e.emit('foo'); e.emit('foo'); - assertEqual(e.listeners('foo').length, 1); - assertEqual(multi, 5); - assertEqual(foo, 1); - assertEqual(bar, 1); + assert.strictEqual(e.listeners('foo').length, 1); + assert.strictEqual(multi, 5); + assert.strictEqual(foo, 1); + assert.strictEqual(bar, 1); }); it('only emits once with context', function (done) { @@ -282,8 +280,8 @@ describe('EventEmitter', function tests() { , e = new EventEmitter(); e.once('foo', function (bar: string) { - assertEqual(this, context); - assertEqual(bar, 'bar'); + assert.strictEqual(this, context); + assert.strictEqual(bar, 'bar'); done(); }, context); @@ -300,18 +298,18 @@ describe('EventEmitter', function tests() { var bar1 = e.addListener('bar', function () {}); var bar2 = e.addListener('bar', bar); - assertEqual(e.listeners('foo').length, 1); - assertEqual(e.listeners('bar').length, 2); + assert.strictEqual(e.listeners('foo').length, 1); + assert.strictEqual(e.listeners('bar').length, 2); foo.remove(); - assertEqual(e.listeners('foo').length, 0); - assertEqual(e.listeners('bar').length, 2); + assert.strictEqual(e.listeners('foo').length, 0); + assert.strictEqual(e.listeners('bar').length, 2); bar2.remove(); - assertEqual(e.listeners('bar').length, 1); + assert.strictEqual(e.listeners('bar').length, 1); bar1.remove(); - assertEqual(e.listeners('bar').length, 0); + assert.strictEqual(e.listeners('bar').length, 0); }); }); @@ -325,15 +323,15 @@ describe('EventEmitter', function tests() { e.addListener('aaa', function () { throw new Error('oops'); }); e.removeAllListeners('foo'); - assertEqual(e.listeners('foo').length, 0); - assertEqual(e.listeners('bar').length, 1); - assertEqual(e.listeners('aaa').length, 1); + assert.strictEqual(e.listeners('foo').length, 0); + assert.strictEqual(e.listeners('bar').length, 1); + assert.strictEqual(e.listeners('aaa').length, 1); e.removeAllListeners('bar'); e.removeAllListeners('aaa'); - assertEqual(e.listeners('foo').length, 0); - assertEqual(e.listeners('bar').length, 0); - assertEqual(e.listeners('aaa').length, 0); + assert.strictEqual(e.listeners('foo').length, 0); + assert.strictEqual(e.listeners('bar').length, 0); + assert.strictEqual(e.listeners('aaa').length, 0); }); it('just nukes everything', function () { @@ -345,9 +343,9 @@ describe('EventEmitter', function tests() { e.addListener('aaa', function () { throw new Error('oops'); }); e.removeAllListeners(); - assertEqual(e.listeners('foo').length, 0); - assertEqual(e.listeners('bar').length, 0); - assertEqual(e.listeners('aaa').length, 0); + assert.strictEqual(e.listeners('foo').length, 0); + assert.strictEqual(e.listeners('bar').length, 0); + assert.strictEqual(e.listeners('aaa').length, 0); }); }); diff --git a/types/hapi/v16/test/server/info.ts b/types/hapi/v16/test/server/info.ts index e469a2f3a0..eaf1b39747 100644 --- a/types/hapi/v16/test/server/info.ts +++ b/types/hapi/v16/test/server/info.ts @@ -1,10 +1,8 @@ + // From https://hapijs.com/api/16.1.1#serverinfo +import assert = require('assert'); import * as Hapi from 'hapi'; - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; - const server = new Hapi.Server(); var options: Hapi.ServerConnectionOptions = { port: 80 }; server.connection(options); diff --git a/types/libpq/libpq-tests.ts b/types/libpq/libpq-tests.ts index 8f62a38b9e..7d19e910cd 100644 --- a/types/libpq/libpq-tests.ts +++ b/types/libpq/libpq-tests.ts @@ -1,14 +1,8 @@ import { Buffer } from 'buffer'; +import assert = require('assert'); import * as async from 'async'; import PQ = require('libpq'); -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: any, message?: string): void; -declare function assertEqual(actual: T, expected: T, message?: string): void; -declare function assertIfError(value: any): void; -declare function assertNotEqual(actual: T, expected: T, message?: string): void; -declare function assertThrows(fn: () => void, message?: string): void; - // Stub mocha functions const {describe, it, before, after, beforeEach, afterEach} = null as any as { [s: string]: ((s: string, cb: (done: any) => void) => void) & ((cb: (done: any) => void) => void) & {only: any, skip: any}; @@ -84,9 +78,9 @@ describe('async connection', () => { const pq = new PQ(); assert(!pq.connected, 'should have connected set to falsy'); pq.connect(err => { - assertIfError(err); + assert.ifError(err); pq.exec('SELECT NOW()'); - assertEqual(pq.ntuples(), 1); + assert.equal(pq.ntuples(), 1); done(); }); }); @@ -111,7 +105,7 @@ describe('async connection', () => { const activeDomain = process.domain; assert(activeDomain, 'Should have an active domain'); pq.connect(() => { - assertEqual(process.domain, activeDomain, 'Active domain is lost'); + assert.strictEqual(process.domain, activeDomain, 'Active domain is lost'); done(); }); }); @@ -141,14 +135,14 @@ describe('async simple query', () => { assert(pq.setNonBlocking(true)); pq.writable(() => { const success = pq.sendQuery('SELECT 1'); - assertEqual(pq.flush(), 0, 'Should have flushed all data to socket'); + assert.strictEqual(pq.flush(), 0, 'Should have flushed all data to socket'); assert(success, pq.errorMessage()); consume(pq, () => { - assertIfError(pq.errorMessage()); + assert.ifError(pq.errorMessage()); assert(pq.getResult()); - assertEqual(pq.getResult(), false); - assertEqual(pq.ntuples(), 1); - assertEqual(pq.getvalue(0, 0), '1'); + assert.strictEqual(pq.getResult(), false); + assert.strictEqual(pq.ntuples(), 1); + assert.strictEqual(pq.getvalue(0, 0), '1'); done(); }); }); @@ -157,13 +151,13 @@ describe('async simple query', () => { it('dispatches parameterized query', (done: Function) => { const success = pq.sendQueryParams('SELECT $1::text as name', ['Brian']); assert(success, pq.errorMessage()); - assertEqual(pq.flush(), 0, 'Should have flushed query text & parameters'); + assert.strictEqual(pq.flush(), 0, 'Should have flushed query text & parameters'); consume(pq, () => { - assertIfError(pq.errorMessage()); + assert.ifError(pq.errorMessage()); assert(pq.getResult()); - assertEqual(pq.getResult(), false); - assertEqual(pq.ntuples(), 1); - assertEqual(pq.getvalue(0, 0), 'Brian'); + assert.strictEqual(pq.getResult(), false); + assert.strictEqual(pq.ntuples(), 1); + assert.equal(pq.getvalue(0, 0), 'Brian'); done(); }); }); @@ -172,35 +166,35 @@ describe('async simple query', () => { const statementName = 'async-get-name'; const success = pq.sendPrepare(statementName, 'SELECT $1::text as name', 1); assert(success, pq.errorMessage()); - assertEqual(pq.flush(), 0, 'Should have flushed query text'); + assert.strictEqual(pq.flush(), 0, 'Should have flushed query text'); consume(pq, () => { - assertIfError(pq.errorMessage()); + assert.ifError(pq.errorMessage()); // first time there should be a result assert(pq.getResult()); // call 'getResult' until it returns false indicating // there is no more input to consume - assertEqual(pq.getResult(), false); + assert.strictEqual(pq.getResult(), false); // since we only prepared a statement there should be // 0 tuples in the result - assertEqual(pq.ntuples(), 0); + assert.equal(pq.ntuples(), 0); // now execute the previously prepared statement const success = pq.sendQueryPrepared(statementName, ['Brian']); assert(success, pq.errorMessage()); - assertEqual(pq.flush(), 0, 'Should have flushed parameters'); + assert.strictEqual(pq.flush(), 0, 'Should have flushed parameters'); consume(pq, () => { - assertIfError(pq.errorMessage()); + assert.ifError(pq.errorMessage()); // consume the result of the query execution assert(pq.getResult()); - assertEqual(pq.ntuples(), 1); - assertEqual(pq.getvalue(0, 0), 'Brian'); + assert.equal(pq.ntuples(), 1); + assert.equal(pq.getvalue(0, 0), 'Brian'); // call 'getResult' again to ensure we're finished - assertEqual(pq.getResult(), false); + assert.strictEqual(pq.getResult(), false); done(); }); }); @@ -214,11 +208,11 @@ describe('cancel a request', () => { const sent = pq.sendQuery('pg_sleep(5000)'); assert(sent, 'should have sent'); const canceled = pq.cancel(); - assertEqual(canceled, true, 'should have canceled'); + assert.strictEqual(canceled, true, 'should have canceled'); const hasResult = pq.getResult(); assert(hasResult, 'should have a result'); - assertEqual(pq.resultStatus(), 'PGRES_FATAL_ERROR'); - assertEqual(pq.getResult(), false); + assert.equal(pq.resultStatus(), 'PGRES_FATAL_ERROR'); + assert.equal(pq.getResult(), false); pq.exec('SELECT NOW()'); done(); }); @@ -255,37 +249,37 @@ describe('COPY IN', () => { it('check existing data assuptions', () => { pq.exec('SELECT COUNT(*) FROM test_data'); - assertEqual(pq.getvalue(0, 0), '3'); + assert.equal(pq.getvalue(0, 0), 3); }); it('copies data in', () => { const success = pq.exec('COPY test_data FROM stdin'); - assertEqual(pq.resultStatus(), 'PGRES_COPY_IN'); + assert.equal(pq.resultStatus(), 'PGRES_COPY_IN'); const buffer = new Buffer("bob\t100\n", 'utf8'); const res1 = pq.putCopyData(buffer); - assertEqual(res1, 1); + assert.strictEqual(res1, 1); const res2 = pq.putCopyEnd(); - assertEqual(res2, 1); + assert.strictEqual(res2, 1); while (pq.getResult()) { } pq.exec('SELECT COUNT(*) FROM test_data'); - assertEqual(pq.getvalue(0, 0), '4'); + assert.equal(pq.getvalue(0, 0), 4); }); it('can cancel copy data in', () => { const success = pq.exec('COPY test_data FROM stdin'); - assertEqual(pq.resultStatus(), 'PGRES_COPY_IN'); + assert.equal(pq.resultStatus(), 'PGRES_COPY_IN'); const buffer = new Buffer("bob\t100\n", 'utf8'); const res1 = pq.putCopyData(buffer); - assertEqual(res1, 1); + assert.strictEqual(res1, 1); const res2 = pq.putCopyEnd('cancel!'); - assertEqual(res2, 1); + assert.strictEqual(res2, 1); while (pq.getResult()) { } @@ -296,7 +290,7 @@ describe('COPY IN', () => { ); pq.exec('SELECT COUNT(*) FROM test_data'); - assertEqual(pq.getvalue(0, 0), '4'); + assert.equal(pq.getvalue(0, 0), 4); }); }); @@ -316,16 +310,16 @@ describe('COPY OUT', () => { const getRow = (pq: PQ, expected: string) => { const result = pq.getCopyData(false); assert(result instanceof Buffer, 'Result should be a buffer'); - assertEqual(result.toString('utf8'), expected); + assert.equal(result.toString('utf8'), expected); }; it('copies data out', () => { pq.exec('COPY test_data TO stdin'); - assertEqual(pq.resultStatus(), 'PGRES_COPY_OUT'); + assert.equal(pq.resultStatus(), 'PGRES_COPY_OUT'); getRow(pq, 'brian\t32\n'); getRow(pq, 'aaron\t30\n'); getRow(pq, '\t\\N\n'); - assertEqual( pq.getCopyData(), -1); + assert.strictEqual( pq.getCopyData(), -1); }); }); @@ -333,28 +327,28 @@ describe('without being connected', () => { it('exec fails', () => { const pq = new PQ(); pq.exec(); - assertEqual(pq.resultStatus(), 'PGRES_FATAL_ERROR'); + assert.equal(pq.resultStatus(), 'PGRES_FATAL_ERROR'); assert(pq.errorMessage()); }); it('fails on async query', () => { const pq = new PQ(); const success = pq.sendQuery('blah'); - assertEqual(success, false); - assertEqual(pq.resultStatus(), 'PGRES_FATAL_ERROR'); + assert.strictEqual(success, false); + assert.equal(pq.resultStatus(), 'PGRES_FATAL_ERROR'); assert(pq.errorMessage()); }); it('throws when reading while not connected', () => { const pq = new PQ(); - assertThrows(() => { + assert.throws(() => { pq.startReader(); }); }); it('throws when writing while not connected', () => { const pq = new PQ(); - assertThrows(() => { + assert.throws(() => { pq.writable(() => { }); }); @@ -378,7 +372,7 @@ describe('error info', () => { it('everything is null', () => { pq.exec('SELECT NOW()'); assert(!pq.errorMessage(), pq.errorMessage()); - assertEqual(pq.ntuples(), 1); + assert.equal(pq.ntuples(), 1); assert(pq.resultErrorFields(), undefined); }); }); @@ -388,23 +382,23 @@ describe('error info', () => { pq.exec('INSERT INTO test_data VALUES(1, NOW())'); assert(pq.errorMessage()); const err = pq.resultErrorFields(); - assertNotEqual(err, null); - assertEqual(err.severity, 'ERROR'); - assertEqual(err.sqlState, '42804'); - assertEqual(err.messagePrimary, 'column "age" is of type integer but expression is of type timestamp with time zone'); - assertEqual(err.messageDetail, undefined); - assertEqual(err.messageHint, 'You will need to rewrite or cast the expression.'); - assertEqual(err.statementPosition, '33'); - assertEqual(err.internalPosition, undefined); - assertEqual(err.internalQuery, undefined); - assertEqual(err.context, undefined); - assertEqual(err.schemaName, undefined); - assertEqual(err.tableName, undefined); - assertEqual(err.dataTypeName, undefined); - assertEqual(err.constraintName, undefined); - assertEqual(err.sourceFile, "parse_target.c"); + assert.notEqual(err, null); + assert.equal(err.severity, 'ERROR'); + assert.equal(err.sqlState, 42804); + assert.equal(err.messagePrimary, 'column "age" is of type integer but expression is of type timestamp with time zone'); + assert.equal(err.messageDetail, undefined); + assert.equal(err.messageHint, 'You will need to rewrite or cast the expression.'); + assert.equal(err.statementPosition, 33); + assert.equal(err.internalPosition, undefined); + assert.equal(err.internalQuery, undefined); + assert.equal(err.context, undefined); + assert.equal(err.schemaName, undefined); + assert.equal(err.tableName, undefined); + assert.equal(err.dataTypeName, undefined); + assert.equal(err.constraintName, undefined); + assert.equal(err.sourceFile, "parse_target.c"); assert(parseInt(err.sourceLine, 10)); - assertEqual(err.sourceFunction, "transformAssignedExpr"); + assert.equal(err.sourceFunction, "transformAssignedExpr"); }); }); }); @@ -413,7 +407,7 @@ describe('escapeLiteral', () => { it('fails to escape when the server is not connected', () => { const pq = new PQ(); const result = pq.escapeLiteral('test'); - assertEqual(result, null); + assert.strictEqual(result, null); assert(pq.errorMessage()); }); @@ -421,14 +415,14 @@ describe('escapeLiteral', () => { const pq = new PQ(); pq.connectSync(); const result = pq.escapeLiteral('bang'); - assertEqual(result, "'bang'"); + assert.equal(result, "'bang'"); }); it('escapes a bad string', () => { const pq = new PQ(); pq.connectSync(); const result = pq.escapeLiteral("'; TRUNCATE TABLE blah;"); - assertEqual(result, "'''; TRUNCATE TABLE blah;'"); + assert.equal(result, "'''; TRUNCATE TABLE blah;'"); }); }); @@ -436,7 +430,7 @@ describe('escapeIdentifier', () => { it('fails when the server is not connected', () => { const pq = new PQ(); const result = pq.escapeIdentifier('test'); - assertEqual(result, null); + assert.strictEqual(result, null); assert(pq.errorMessage()); }); @@ -444,7 +438,7 @@ describe('escapeIdentifier', () => { const pq = new PQ(); pq.connectSync(); const result = pq.escapeIdentifier('bang'); - assertEqual(result, '"bang"'); + assert.equal(result, '"bang"'); }); }); @@ -482,7 +476,7 @@ describe('connect async', () => { const connect = (cb: Function) => { pqs.forEach((pq) => { pq.connect((err) => { - assertIfError(err); + assert.ifError(err); count++; pq.startReader(); if (count === total) { @@ -535,14 +529,14 @@ describe('set & get non blocking', () => { }); it('is initially set to false', () => { - assertEqual(pq.isNonBlocking(), false); + assert.strictEqual(pq.isNonBlocking(), false); }); it('can switch back and forth', () => { - assertEqual(pq.setNonBlocking(true), true); - assertEqual(pq.isNonBlocking(), true); - assertEqual(pq.setNonBlocking(), true); - assertEqual(pq.isNonBlocking(), false); + assert.strictEqual(pq.setNonBlocking(true), true); + assert.strictEqual(pq.isNonBlocking(), true); + assert.strictEqual(pq.setNonBlocking(), true); + assert.strictEqual(pq.isNonBlocking(), false); }); }); @@ -560,15 +554,15 @@ describe('LISTEN/NOTIFY', () => { it('works', () => { notifier.exec("NOTIFY testing, 'My Payload'"); let notice = listener.notifies(); - assertEqual(notice, null); + assert.equal(notice, null); listener.exec('LISTEN testing'); notifier.exec("NOTIFY testing, 'My Second Payload'"); listener.exec('SELECT NOW()'); notice = listener.notifies(); assert(notice, 'listener should have had a notification come in'); - assertEqual(notice.relname, 'testing', 'missing relname == testing'); - assertEqual(notice.extra, 'My Second Payload'); + assert.equal(notice.relname, 'testing', 'missing relname == testing'); + assert.equal(notice.extra, 'My Second Payload'); assert(notice.be_pid); }); @@ -597,15 +591,15 @@ describe('result accessors', () => { }); it('has ntuples', () => { - assertEqual(pq.ntuples(), 1); + assert.strictEqual(pq.ntuples(), 1); }); it('has cmdStatus', () => { - assertEqual(pq.cmdStatus(), 'INSERT 0 1'); + assert.equal(pq.cmdStatus(), 'INSERT 0 1'); }); it('has command tuples', () => { - assertEqual(pq.cmdTuples(), '1'); + assert.strictEqual(pq.cmdTuples(), '1'); }); }); @@ -614,15 +608,15 @@ describe('Retrieve server version from connection', () => { const pq = new PQ(); pq.connectSync(); const version = pq.serverVersion(); - assertEqual(typeof version, 'number'); + assert.equal(typeof version, 'number'); assert(version > 60000); }); it('return zero when not connected', () => { const pq = new PQ(); const version = pq.serverVersion(); - assertEqual(typeof version, 'number'); - assertEqual(version, 0); + assert.equal(typeof version, 'number'); + assert.equal(version, 0); }); }); @@ -641,7 +635,7 @@ describe('getting socket', () => { it('returns -1 when not connected', () => { const pq = new PQ(); - assertEqual(pq.socket(), -1); + assert.equal(pq.socket(), -1); }); it('returns value when connected', () => { @@ -654,11 +648,11 @@ describe('connecting with bad credentials', () => { try { new PQ().connectSync('asldkfjlasdf'); } catch (e) { - assertEqual(e.toString().indexOf('connection pointer is NULL'), -1); + assert.equal(e.toString().indexOf('connection pointer is NULL'), -1); return; } - throw new Error('Should have thrown an exception'); + assert.fail(null, null, 'Should have thrown an exception', ''); }); }); @@ -694,31 +688,31 @@ describe('result checking', () => { it('executes query', () => { pq.exec('SELECT NOW() as my_col'); - assertEqual(pq.resultStatus(), 'PGRES_TUPLES_OK'); + assert.equal(pq.resultStatus(), 'PGRES_TUPLES_OK'); }); it('has 1 tuple', () => { - assertEqual(pq.ntuples(), 1); + assert.equal(pq.ntuples(), 1); }); it('has 1 field', () => { - assertEqual(pq.nfields(), 1); + assert.strictEqual(pq.nfields(), 1); }); it('has column name', () => { - assertEqual(pq.fname(0), 'my_col'); + assert.equal(pq.fname(0), 'my_col'); }); it('has oid type of timestamptz', () => { - assertEqual(pq.ftype(0), 1184); + assert.strictEqual(pq.ftype(0), 1184); }); it('has value as a date', () => { const now = new Date(); const val = pq.getvalue(0); const date = new Date(Date.parse(val)); - assertEqual(date.getFullYear(), now.getFullYear()); - assertEqual(date.getMonth(), now.getMonth()); + assert.equal(date.getFullYear(), now.getFullYear()); + assert.equal(date.getMonth(), now.getMonth()); }); it('can manually clear result multiple times', () => { @@ -747,20 +741,20 @@ describe('low-level query integration tests', () => { }); it('has correct tuples', () => { - assertEqual(pq.ntuples(), 3); + assert.strictEqual(pq.ntuples(), 3); }); it('has correct field count', () => { - assertEqual(pq.nfields(), 2); + assert.strictEqual(pq.nfields(), 2); }); it('has correct rows', () => { - assertEqual(pq.getvalue(0, 0), 'brian'); - assertEqual(pq.getvalue(1, 1), '30'); - assertEqual(pq.getvalue(2, 0), ''); - assertEqual(pq.getisnull(2, 0), false); - assertEqual(pq.getvalue(2, 1), ''); - assertEqual(pq.getisnull(2, 1), true); + assert.strictEqual(pq.getvalue(0, 0), 'brian'); + assert.strictEqual(pq.getvalue(1, 1), '30'); + assert.strictEqual(pq.getvalue(2, 0), ''); + assert.strictEqual(pq.getisnull(2, 0), false); + assert.strictEqual(pq.getvalue(2, 1), ''); + assert.strictEqual(pq.getisnull(2, 1), true); }); }); }); @@ -781,21 +775,21 @@ describe('sync query with parameters', () => { it('works with single string parameter', () => { const queryText = 'SELECT $1::text as name'; pq.execParams(queryText, ['Brian']); - assertEqual(pq.ntuples(), 1); - assertEqual(pq.getvalue(0, 0), 'Brian'); + assert.strictEqual(pq.ntuples(), 1); + assert.strictEqual(pq.getvalue(0, 0), 'Brian'); }); it('works with a number parameter', () => { const queryText = 'SELECT $1::int as age'; pq.execParams(queryText, [32]); - assertEqual(pq.ntuples(), 1); - assertEqual(pq.getvalue(0, 0), '32'); + assert.strictEqual(pq.ntuples(), 1); + assert.strictEqual(pq.getvalue(0, 0), '32'); }); it('works with multiple parameters', () => { const queryText = 'INSERT INTO test_data(name, age) VALUES($1, $2)'; pq.execParams(queryText, ['Barkley', 4]); - assertEqual(pq.resultErrorMessage(), ''); + assert.equal(pq.resultErrorMessage(), ''); }); }); @@ -817,18 +811,18 @@ describe('prepare and execPrepared', () => { describe('preparing a statement', () => { it('works properly', () => { pq.prepare(statementName, 'SELECT $1::text as name', 1); - assertIfError(pq.resultErrorMessage()); - assertEqual(pq.resultStatus(), 'PGRES_COMMAND_OK'); + assert.ifError(pq.resultErrorMessage()); + assert.equal(pq.resultStatus(), 'PGRES_COMMAND_OK'); }); }); describe('executing a prepared statement', () => { it('works properly', () => { pq.execPrepared(statementName, ['Brian']); - assertIfError(pq.resultErrorMessage()); - assertEqual(pq.ntuples(), 1); - assertEqual(pq.nfields(), 1); - assertEqual(pq.getvalue(0, 0), 'Brian'); + assert.ifError(pq.resultErrorMessage()); + assert.strictEqual(pq.ntuples(), 1); + assert.strictEqual(pq.nfields(), 1); + assert.strictEqual(pq.getvalue(0, 0), 'Brian'); }); }); }); diff --git a/types/memcached/memcached-tests.ts b/types/memcached/memcached-tests.ts index 7b25025e99..6ae024d4b5 100644 --- a/types/memcached/memcached-tests.ts +++ b/types/memcached/memcached-tests.ts @@ -1,7 +1,5 @@ import Memcached = require('memcached'); - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; +import assert = require('assert'); function isString(expected?: string): void { if (expected !== undefined && typeof expected !== 'string') { @@ -154,7 +152,7 @@ function test_get() { function test_getMulti() { memcached.getMulti(['foo', 'bar'], function(err, data) { isVoid(this); - assert(typeof data === 'object'); + assert(typeof data, 'object'); }); } function test_cas() { @@ -292,14 +290,14 @@ function test_incr() { })) .then(() => new Promise(resolve => { memcached.incr(key, value, function(err, result) { - assert(result === 4); + assert.deepStrictEqual(result, 4); isCommandData(this); resolve(); }); })) .then(() => new Promise(resolve => { memcached.incr('noexists', value, function(err, result) { - assert(result === false); + assert.deepStrictEqual(result, false); isCommandData(this); resolve(); }); @@ -320,14 +318,14 @@ function test_decr() { })) .then(() => new Promise(resolve => { memcached.decr(key, value, function(err, result) { - assert(result === 0); + assert.deepStrictEqual(result, 0); isCommandData(this); resolve(); }); })) .then(() => new Promise(resolve => { memcached.decr('noexists', value, function(err, result) { - assert(result === false); + assert.deepStrictEqual(result, false); isCommandData(this); resolve(); }); diff --git a/types/multireducer/multireducer-tests.ts b/types/multireducer/multireducer-tests.ts index 1b91fe0f01..e5392d2863 100644 --- a/types/multireducer/multireducer-tests.ts +++ b/types/multireducer/multireducer-tests.ts @@ -1,7 +1,5 @@ import multireducer from 'multireducer'; - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function deepEqual(actual: T, expected: T): void; +import { deepEqual } from 'assert'; const initialState = { a: 1, b: 2, c: 3 }; diff --git a/types/oracledb/oracledb-tests.ts b/types/oracledb/oracledb-tests.ts index 2d53e0856f..252f7e1915 100644 --- a/types/oracledb/oracledb-tests.ts +++ b/types/oracledb/oracledb-tests.ts @@ -1,10 +1,13 @@ import * as oracledb from 'oracledb'; -import defaultOracledb from 'oracledb'; -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean, message?: string): void; -declare function assertEqual(actual: T, expected: T, message?: string): void; +import defaultOracledb from 'oracledb'; +// import dotenv from 'dotenv'; +import assert from 'assert'; + + + +// dotenv.config(); /* @@ -44,7 +47,7 @@ const testBreak = (connection: oracledb.Connection): Promise => [2], (error: oracledb.DBError): void => { // ORA-01013: user requested cancel of current operation - assert(typeof error.message === 'string', 'message not defined for DB error'); + assert(error.message.includes('ORA-01013'), 'message not defined for DB error'); assert(error.errorNum !== undefined, 'errorNum not defined for DB error'); assert(error.offset !== undefined, 'offset not defined for DB error'); @@ -65,7 +68,7 @@ const testGetStatmentInfo = async (connection: oracledb.Connection): Promise :myDate'); - assertEqual( + assert.deepStrictEqual( info.metaData[0], { name: '1', @@ -79,7 +82,7 @@ const testGetStatmentInfo = async (connection: oracledb.Connection): Promise s === 'MYDATE') >= 0, 'connection.getStatementInfo() has invalid bindNames field in its response', ); assert(info.statementType === 1, 'connection.getStatementInfo() has invalid statementType field in its response'); @@ -111,7 +114,7 @@ const testQueryStream = async (connection: oracledb.Connection): Promise = }); stream.on('metadata', metadata => { - assertEqual(metadata[0], { + assert.deepStrictEqual(metadata[0], { name: '1', }); }); @@ -157,7 +160,7 @@ const testResultSet = async (connection: oracledb.Connection): Promise => }, ); - assertEqual(result.metaData[0], { name: '1' }); + assert.deepStrictEqual(result.metaData[0], { name: '1' }); const { resultSet, lastRowid } = result; @@ -166,13 +169,13 @@ const testResultSet = async (connection: oracledb.Connection): Promise => const row = await resultSet.getRow(); - assertEqual(row, [1]); + assert.deepStrictEqual(row, [1]); console.log('Testing resultSet.getRows()...'); const rows = await resultSet.getRows(1); - assertEqual(rows, [[2]]); + assert.deepStrictEqual(rows, [[2]]); console.log('Testing resultSet.close()...'); @@ -335,7 +338,7 @@ const version4Tests = async () => { console.log(results.one); const GeomType = await connection.getDbObjectClass("MDSYS.SDO_GEOMETRY"); - + const geom = new GeomType( { SDO_GTYPE: 2003, @@ -358,7 +361,7 @@ const version4Tests = async () => { new geom.attributes.test.typeClass({}); geom.S_GTYPE = 2003; - + await connection.execute( `INSERT INTO testgeometry (id, geometry) VALUES (:id, :g)`, {id: 1, g: geom} @@ -372,7 +375,7 @@ const version4Tests = async () => { }); console.log(sub.regId); - + const queue = await connection.getQueue('test', { payloadType: 'test' }) @@ -403,7 +406,7 @@ const version4Tests = async () => { const lob = await connection.createLob(2); await lob.getData(); - + const plsql = ` DECLARE c1 SYS_REFCURSOR; diff --git a/types/oracledb/v3/index.d.ts b/types/oracledb/v3/index.d.ts index 6d5b9e6b03..727cd242fd 100644 --- a/types/oracledb/v3/index.d.ts +++ b/types/oracledb/v3/index.d.ts @@ -2896,4 +2896,4 @@ declare namespace OracleDB { function getPool(poolAlias?: string): Pool; } -export = OracleDB; +export = OracleDB; \ No newline at end of file diff --git a/types/oracledb/v3/oracledb-tests.ts b/types/oracledb/v3/oracledb-tests.ts index 90d8d84a4e..fda5cecb7f 100644 --- a/types/oracledb/v3/oracledb-tests.ts +++ b/types/oracledb/v3/oracledb-tests.ts @@ -1,8 +1,8 @@ import * as oracledb from 'oracledb'; +import * as dotenv from 'dotenv'; +import * as assert from 'assert'; -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean, message?: string): void; -declare function assertEqual(actual: any, expected: any, message?: string): void; +dotenv.config(); /* @@ -42,7 +42,7 @@ const testBreak = (connection: oracledb.Connection): Promise => [2], (error: oracledb.DBError): void => { // ORA-01013: user requested cancel of current operation - assert(typeof error.message === 'string', 'message not defined for DB error'); + assert(error.message.includes('ORA-01013'), 'message not defined for DB error'); assert(error.errorNum !== undefined, 'errorNum not defined for DB error'); assert(error.offset !== undefined, 'offset not defined for DB error'); @@ -63,7 +63,7 @@ const testGetStatmentInfo = async (connection: oracledb.Connection): Promise :myDate'); - assertEqual( + assert.deepStrictEqual( info.metaData[0], { name: '1', @@ -77,7 +77,7 @@ const testGetStatmentInfo = async (connection: oracledb.Connection): Promise s === 'MYDATE') >= 0, 'connection.getStatementInfo() has invalid bindNames field in its response', ); assert(info.statementType === 1, 'connection.getStatementInfo() has invalid statementType field in its response'); @@ -105,7 +105,7 @@ const testQueryStream = async (connection: oracledb.Connection): Promise = }); stream.on('metadata', metadata => { - assertEqual(metadata[0], { + assert.deepStrictEqual(metadata[0], { name: '1', }); }); @@ -149,7 +149,7 @@ const testResultSet = async (connection: oracledb.Connection): Promise => }, ); - assertEqual(result.metaData[0], { name: '1' }); + assert.deepStrictEqual(result.metaData[0], { name: '1' }); const { resultSet } = result; @@ -157,13 +157,13 @@ const testResultSet = async (connection: oracledb.Connection): Promise => const row = await resultSet.getRow(); - assertEqual(row, [1]); + assert.deepStrictEqual(row, [1]); console.log('Testing resultSet.getRows()...'); const rows = await resultSet.getRows(1); - assertEqual(rows, [[2]]); + assert.deepStrictEqual(rows, [[2]]); console.log('Testing resultSet.close()...'); diff --git a/types/pako/pako-tests.ts b/types/pako/pako-tests.ts index 28f1bea7e7..b77bcfb69f 100644 --- a/types/pako/pako-tests.ts +++ b/types/pako/pako-tests.ts @@ -1,7 +1,5 @@ import pako = require("pako"); - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T): void; +import * as assert from "assert"; const chunk1 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]); const chunk2 = new Uint8Array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]); @@ -43,10 +41,10 @@ deflator.push(data, true); const inflator = new pako.Inflate({ to: 'string' }); inflator.push(deflator.result, true); -assertEqual(inflator.err, 0); -assertEqual(inflator.result, data); +assert.equal(inflator.err, 0); +assert.equal(inflator.result, data); const header = inflator.header; -assertEqual(header.time, 1234567); -assertEqual(header.os, 15); -assertEqual(header.name, 'test name'); +assert.equal(header.time, 1234567); +assert.equal(header.os, 15); +assert.equal(header.name, 'test name'); diff --git a/types/pigpio/pigpio-tests.ts b/types/pigpio/pigpio-tests.ts index 0ae5e66385..f756058b03 100644 --- a/types/pigpio/pigpio-tests.ts +++ b/types/pigpio/pigpio-tests.ts @@ -1,7 +1,5 @@ import * as pigpio from 'pigpio'; - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T, message?: string): void; +import * as assert from 'assert'; (function alert_pwm_measurement(): void { const Gpio = pigpio.Gpio; @@ -127,7 +125,7 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; let iv: NodeJS.Timer; bank1.clear(1 << 18 | 1 << 17); - assertEqual((bank1.read() >> 17) & 0x3, 0, 'expected 0'); + assert.strictEqual((bank1.read() >> 17) & 0x3, 0, 'expected 0'); iv = setInterval(function timer(): void { const bits = (bank1.read() >> 17) & 0x3; @@ -135,22 +133,22 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; switch (bits) { case 0: bank1.set(1 << 17); - assertEqual((bank1.read() >> 17) & 0x3, 1, 'expected 1'); + assert.strictEqual((bank1.read() >> 17) & 0x3, 1, 'expected 1'); break; case 1: bank1.clear(1 << 17); bank1.set(1 << 18); - assertEqual((bank1.read() >> 17) & 0x3, 2, 'expected 2'); + assert.strictEqual((bank1.read() >> 17) & 0x3, 2, 'expected 2'); break; case 2: bank1.set(1 << 17); bank1.set(1 << 18); - assertEqual((bank1.read() >> 17) & 0x3, 3, 'expected 3'); + assert.strictEqual((bank1.read() >> 17) & 0x3, 3, 'expected 3'); break; case 3: bank1.clear(1 << 17); bank1.clear(1 << 18); - assertEqual((bank1.read() >> 17) & 0x3, 0, 'expected 0'); + assert.strictEqual((bank1.read() >> 17) & 0x3, 0, 'expected 0'); break; } }, 250); @@ -229,25 +227,25 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; const gpio7 = new Gpio(7, { mode: Gpio.INPUT }); const gpio8 = new Gpio(8, { mode: Gpio.OUTPUT }); - assertEqual(gpio7.getMode(), Gpio.INPUT, 'expected INPUT mode for gpio7'); - assertEqual(gpio8.getMode(), Gpio.OUTPUT, 'expected OUTPUT mode for gpio8'); + assert.strictEqual(gpio7.getMode(), Gpio.INPUT, 'expected INPUT mode for gpio7'); + assert.strictEqual(gpio8.getMode(), Gpio.OUTPUT, 'expected OUTPUT mode for gpio8'); gpio8.mode(Gpio.INPUT); - assertEqual(gpio8.getMode(), Gpio.INPUT, 'expected INPUT mode for gpio8'); + assert.strictEqual(gpio8.getMode(), Gpio.INPUT, 'expected INPUT mode for gpio8'); gpio7.mode(Gpio.OUTPUT); - assertEqual(gpio7.getMode(), Gpio.OUTPUT, 'expected OUTPUT mode for gpio7'); + assert.strictEqual(gpio7.getMode(), Gpio.OUTPUT, 'expected OUTPUT mode for gpio7'); gpio7.mode(Gpio.INPUT); - assertEqual(gpio7.getMode(), Gpio.INPUT, 'expected INPUT mode for gpio7'); + assert.strictEqual(gpio7.getMode(), Gpio.INPUT, 'expected INPUT mode for gpio7'); })(); (function gpio_numbers(): void { const Gpio = pigpio.Gpio; - assertEqual(Gpio.MIN_GPIO, 0, 'expected Gpio.MIN_GPIO to be 0'); - assertEqual(Gpio.MAX_GPIO, 53, 'expected Gpio.MAX_GPIO to be 53'); - assertEqual(Gpio.MAX_USER_GPIO, 31, 'expected Gpio.MAX_USER_GPIO to be 31'); + assert.strictEqual(Gpio.MIN_GPIO, 0, 'expected Gpio.MIN_GPIO to be 0'); + assert.strictEqual(Gpio.MAX_GPIO, 53, 'expected Gpio.MAX_GPIO to be 53'); + assert.strictEqual(Gpio.MAX_USER_GPIO, 31, 'expected Gpio.MAX_USER_GPIO to be 31'); })(); (function isr_enable_disable(): void { @@ -771,9 +769,9 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; const Gpio = pigpio.Gpio; const input = new Gpio(22, { mode: Gpio.INPUT, pullUpDown: Gpio.PUD_UP }); - assertEqual(input.digitalRead(), 1, 'expected gpio22 to be 1'); + assert.strictEqual(input.digitalRead(), 1, 'expected gpio22 to be 1'); input.pullUpDown(Gpio.PUD_DOWN); - assertEqual(input.digitalRead(), 0, 'expected gpio22 to be 0'); + assert.strictEqual(input.digitalRead(), 0, 'expected gpio22 to be 0'); })(); (function pulse_led(): void { @@ -785,7 +783,7 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; led.pwmWrite(dutyCycle); const dutyCycleRead: number = led.getPwmDutyCycle(); - assertEqual(dutyCycleRead, dutyCycle, + assert.strictEqual(dutyCycleRead, dutyCycle, 'expected dutyCycle to be ' + dutyCycle + ', not ' + dutyCycleRead ); @@ -806,34 +804,34 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; const led = new Gpio(18, { mode: Gpio.OUTPUT }); let dutyCycle: number; - assertEqual(led.getPwmRange(), 255, 'expected pwm range to be 255'); - assertEqual(led.getPwmRealRange(), 250, 'expected pwm real range to be 250'); - assertEqual(led.getPwmFrequency(), 800, 'expected get pwm frequency to be 800'); + assert.strictEqual(led.getPwmRange(), 255, 'expected pwm range to be 255'); + assert.strictEqual(led.getPwmRealRange(), 250, 'expected pwm real range to be 250'); + assert.strictEqual(led.getPwmFrequency(), 800, 'expected get pwm frequency to be 800'); led.pwmRange(125); - assertEqual(led.getPwmRange(), 125, 'expected pwm range to be 125'); - assertEqual(led.getPwmRealRange(), 250, 'expected pwm real range to be 250'); - assertEqual(led.getPwmFrequency(), 800, 'expected get pwm frequency to be 800'); + assert.strictEqual(led.getPwmRange(), 125, 'expected pwm range to be 125'); + assert.strictEqual(led.getPwmRealRange(), 250, 'expected pwm real range to be 250'); + assert.strictEqual(led.getPwmFrequency(), 800, 'expected get pwm frequency to be 800'); led.pwmFrequency(2000); - assertEqual(led.getPwmRange(), 125, 'expected pwm range to be 125'); - assertEqual(led.getPwmRealRange(), 100, 'expected pwm real range to be 100'); - assertEqual(led.getPwmFrequency(), 2000, 'expected get pwm frequency to be 2000'); + assert.strictEqual(led.getPwmRange(), 125, 'expected pwm range to be 125'); + assert.strictEqual(led.getPwmRealRange(), 100, 'expected pwm real range to be 100'); + assert.strictEqual(led.getPwmFrequency(), 2000, 'expected get pwm frequency to be 2000'); dutyCycle = Math.floor(led.getPwmRange() / 2); led.pwmWrite(dutyCycle); - assertEqual(led.getPwmDutyCycle(), dutyCycle, 'expected duty cycle to be ' + dutyCycle); + assert.strictEqual(led.getPwmDutyCycle(), dutyCycle, 'expected duty cycle to be ' + dutyCycle); led.hardwarePwmWrite(1e7, 500000); - assertEqual(led.getPwmRange(), 1e6, 'expected pwm range to be 1e6'); - assertEqual(led.getPwmRealRange(), 25, 'expected pwm real range to be 25'); - assertEqual(led.getPwmFrequency(), 1e7, 'expected get pwm frequency to be 1e7'); - assertEqual(led.getPwmDutyCycle(), 500000, 'expected duty cycle to be 500000'); + assert.strictEqual(led.getPwmRange(), 1e6, 'expected pwm range to be 1e6'); + assert.strictEqual(led.getPwmRealRange(), 25, 'expected pwm real range to be 25'); + assert.strictEqual(led.getPwmFrequency(), 1e7, 'expected get pwm frequency to be 1e7'); + assert.strictEqual(led.getPwmDutyCycle(), 500000, 'expected duty cycle to be 500000'); led.digitalWrite(0); - assertEqual(led.getPwmRange(), 125, 'expected pwm range to be 125'); - assertEqual(led.getPwmRealRange(), 100, 'expected pwm real range to be 100'); - assertEqual(led.getPwmFrequency(), 2000, 'expected get pwm frequency to be 2000'); + assert.strictEqual(led.getPwmRange(), 125, 'expected pwm range to be 125'); + assert.strictEqual(led.getPwmRealRange(), 100, 'expected pwm real range to be 100'); + assert.strictEqual(led.getPwmFrequency(), 2000, 'expected get pwm frequency to be 2000'); }); (function servo_control(): void { @@ -843,7 +841,7 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; let pulseWidth = 500; motor.servoWrite(0); - assertEqual(motor.getServoPulseWidth(), 0, + assert.strictEqual(motor.getServoPulseWidth(), 0, 'expected pulseWidth to be 0' ); @@ -851,7 +849,7 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; motor.servoWrite(pulseWidth); const pulseWidthRead = motor.getServoPulseWidth(); - assertEqual(pulseWidthRead, pulseWidth, + assert.strictEqual(pulseWidthRead, pulseWidth, 'expected pulseWidth to be ' + pulseWidth + ', not ' + pulseWidthRead ); @@ -887,7 +885,7 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; setTimeout(() => { const endTick: number = pigpio.getTick(); const diff: number = pigpio.tickDiff(startTick, endTick); - assertEqual(diff > 0, true, 'expected tick count to increase across a timer call'); + assert.ok(diff > 0, 'expected tick count to increase across a timer call'); }, 50); })(); @@ -919,7 +917,7 @@ declare function assertEqual(actual: T, expected: T, message?: string): void; }, 500); setTimeout(() => { - assertEqual(count, 1, 'expected 1 alert function call instead of ' + count); + assert.strictEqual(count, 1, 'expected 1 alert function call instead of ' + count); console.log(" success..."); process.exit(0); }, 1000); diff --git a/types/project-oxford/project-oxford-tests.ts b/types/project-oxford/project-oxford-tests.ts index 3408ac6623..8b1dbec466 100644 --- a/types/project-oxford/project-oxford-tests.ts +++ b/types/project-oxford/project-oxford-tests.ts @@ -1,11 +1,9 @@ import oxford = require("project-oxford"); +import assert = require('assert'); import _Promise = require('bluebird'); import fs = require('fs'); -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: any, message?: string): void; - // Stub mocha functions const {describe, it, before, after, beforeEach, afterEach} = null as any as { [s: string]: ((s: string, cb: (done: any) => void) => void) & ((cb: (done: any) => void) => void) & {only: any, skip: any}; @@ -35,13 +33,13 @@ describe('Project Oxford Face API Test', function () { analyzesGender: true, analyzesHeadPose: true }).then(function (response) { - assert(response[0].faceId); - assert(response[0].faceRectangle); - assert(response[0].faceLandmarks); - assert(response[0].attributes.gender); - assert(response[0].attributes.headPose); + assert.ok(response[0].faceId); + assert.ok(response[0].faceRectangle); + assert.ok(response[0].faceLandmarks); + assert.ok(response[0].attributes.gender); + assert.ok(response[0].attributes.headPose); - assert(response[0].attributes.gender === 'male'); + assert.equal(response[0].attributes.gender, 'male'); done(); }); }); @@ -54,13 +52,13 @@ describe('Project Oxford Face API Test', function () { analyzesGender: true, analyzesHeadPose: true }).then(function (response) { - assert(response[0].faceId); - assert(response[0].faceRectangle); - assert(response[0].faceLandmarks); - assert(response[0].attributes.gender); - assert(response[0].attributes.headPose); + assert.ok(response[0].faceId); + assert.ok(response[0].faceRectangle); + assert.ok(response[0].faceLandmarks); + assert.ok(response[0].attributes.gender); + assert.ok(response[0].attributes.headPose); - assert(response[0].attributes.gender === 'male'); + assert.equal(response[0].attributes.gender, 'male'); done(); }); }); @@ -73,13 +71,13 @@ describe('Project Oxford Face API Test', function () { analyzesGender: true, analyzesHeadPose: true }).then(function (response) { - assert(response[0].faceId); - assert(response[0].faceRectangle); - assert(response[0].faceLandmarks); - assert(response[0].attributes.gender); - assert(response[0].attributes.headPose); + assert.ok(response[0].faceId); + assert.ok(response[0].faceRectangle); + assert.ok(response[0].faceLandmarks); + assert.ok(response[0].attributes.gender); + assert.ok(response[0].attributes.headPose); - assert(response[0].attributes.gender === 'male'); + assert.equal(response[0].attributes.gender, 'male'); done(); }); }); @@ -94,14 +92,14 @@ describe('Project Oxford Face API Test', function () { detects.push(client.face.detect({ path: './test/images/face1.jpg', }).then(function(response) { - assert(response[0].faceId) + assert.ok(response[0].faceId) billFaces.push(response[0].faceId); })); detects.push(client.face.detect({ path: './test/images/face2.jpg', }).then(function(response) { - assert(response[0].faceId) + assert.ok(response[0].faceId) billFaces.push(response[0].faceId); })); @@ -126,10 +124,10 @@ describe('Project Oxford Face API Test', function () { faceIds.push(face.faceId); }); - assert(faceIds.length === 6); + assert.equal(faceIds.length, 6); }).then(function() { client.face.grouping(faceIds).then(function (response) { - assert(response.messyGroup); + assert.ok(response.messyGroup); done(); }); }); @@ -140,12 +138,12 @@ describe('Project Oxford Face API Test', function () { it('verifies a face against another face', function (done) { this.timeout(10000); - assert(billFaces.length === 2); + assert.equal(billFaces.length, 2); client.face.verify(billFaces).then(function (response) { - assert(response); - assert((response.isIdentical === true || response.isIdentical === false)); - assert(response.confidence); + assert.ok(response); + assert.ok((response.isIdentical === true || response.isIdentical === false)); + assert.ok(response.confidence); done(); }); }); @@ -175,39 +173,39 @@ describe('Project Oxford Face API Test', function () { it('creates a PersonGroup', function (done) { client.face.personGroup.create(personGroupId, 'po-node-test-group', 'test-data').then(function (response) { - assert(true, "void response expected"); + assert.ok(true, "void response expected"); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); it('lists PersonGroups', function (done) { client.face.personGroup.list().then(function (response) { - assert(response); - assert((response.length > 0)); - assert(response[0].personGroupId); + assert.ok(response); + assert.ok((response.length > 0)); + assert.ok(response[0].personGroupId); done(); }); }); it('gets a PersonGroup', function (done) { client.face.personGroup.get(personGroupId).then(function (response) { - assert(response.personGroupId === personGroupId); - assert(response.name === 'po-node-test-group'); - assert(response.userData === 'test-data'); + assert.equal(response.personGroupId, personGroupId); + assert.equal(response.name, 'po-node-test-group'); + assert.equal(response.userData, 'test-data'); done(); }); }); it('updates a PersonGroup', function (done) { client.face.personGroup.update(personGroupId, 'po-node-test-group2', 'test-data2').then(function (response) { - assert(true, "void response expected");; + assert.ok(true, "void response expected");; done(); }).catch(function (response) { - assert(response === 'PersonGroupTrainingNotFinished') + assert.equal(response, 'PersonGroupTrainingNotFinished') }); }); @@ -215,27 +213,27 @@ describe('Project Oxford Face API Test', function () { client.face.personGroup.trainingStatus(personGroupId).then(function (response) { done(); }).catch(function (response) { - assert(response.code === 'PersonGroupNotTrained'); + assert.equal(response.code, 'PersonGroupNotTrained'); done(); }); }); it('starts a PersonGroup\'s training', function (done) { client.face.personGroup.trainingStart(personGroupId).then(function (response) { - assert(response.status === 'running'); + assert.equal(response.status, 'running'); done(); }).catch(function (response) { - assert(response.status === 'running'); + assert.equal(response.status, 'running'); done(); }); }); it('deletes a PersonGroup', function (done) { client.face.personGroup.delete(personGroupId).then(function (response) { - assert(true, "void response"); + assert.ok(true, "void response"); done(); }).catch(function (response) { - assert(response.code === 'PersonGroupTrainingNotFinished'); + assert.equal(response.code, 'PersonGroupTrainingNotFinished'); done(); }); }); @@ -246,11 +244,11 @@ describe('Project Oxford Face API Test', function () { it('creates a PersonGroup for the Person', function (done) { client.face.personGroup.create(personGroupId2, 'po-node-test-group', 'test-data') .then(function (response) { - assert(true, "void response expected"); + assert.ok(true, "void response expected"); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -258,23 +256,23 @@ describe('Project Oxford Face API Test', function () { it('creates a Person', function (done) { client.face.person.create(personGroupId2, [billFaces[0]], 'test-bill', 'test-data') .then(function (response) { - assert(response.personId); + assert.ok(response.personId); billPersonId = response.personId; done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); it('gets a Person', function (done) { client.face.person.get(personGroupId2, billPersonId).then(function (response) { - assert(response.personId); + assert.ok(response.personId); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -282,7 +280,7 @@ describe('Project Oxford Face API Test', function () { it('updates a Person', function (done) { client.face.person.update(personGroupId2, billPersonId, [billFaces[0]], 'test-bill', 'test-data') .then(function (response) { - assert(true, "void response expected"); + assert.ok(true, "void response expected"); done(); }) }); @@ -290,11 +288,11 @@ describe('Project Oxford Face API Test', function () { it('adds a face to a Person', function (done) { client.face.person.addFace(personGroupId2, billPersonId, billFaces[1], 'test-data') .then(function (response) { - assert(true, "void response expected"); + assert.ok(true, "void response expected"); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -302,12 +300,12 @@ describe('Project Oxford Face API Test', function () { it('gets a face from a Person', function (done) { client.face.person.getFace(personGroupId2, billPersonId, billFaces[1]) .then(function (response) { - assert(response.userData); - assert(response.userData === 'test-data'); + assert.ok(response.userData); + assert.equal(response.userData, 'test-data'); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -315,11 +313,11 @@ describe('Project Oxford Face API Test', function () { it('updates a face on a Person', function (done) { client.face.person.updateFace(personGroupId2, billPersonId, billFaces[1], 'test-data') .then(function (response) { - assert(true, "void response expected"); + assert.ok(true, "void response expected"); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -327,11 +325,11 @@ describe('Project Oxford Face API Test', function () { it('deletes a face on a Person', function (done) { client.face.person.deleteFace(personGroupId2, billPersonId, billFaces[1]) .then(function (response) { - assert(true, "void response expected"); + assert.ok(true, "void response expected"); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -339,11 +337,11 @@ describe('Project Oxford Face API Test', function () { it('lists Persons', function (done) { client.face.person.list(personGroupId2) .then(function (response) { - assert(response[0].personId); + assert.ok(response[0].personId); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -351,11 +349,11 @@ describe('Project Oxford Face API Test', function () { it('deletes a Person', function (done) { client.face.person.delete(personGroupId2, billPersonId) .then(function (response) { - assert(true, "void response expected"); + assert.ok(true, "void response expected"); done(); }) .catch(function (error) { - assert(false, JSON.stringify(error)); + assert.ok(false, JSON.stringify(error)); done(); }); }); @@ -387,13 +385,13 @@ describe('Project Oxford Vision API Test', function () { Categories: true }) .then(function (response) { - assert(response); - assert(response.categories); - assert(response.adult); - assert(response.metadata); - assert(response.faces); - assert(response.color); - assert(response.imageType); + assert.ok(response); + assert.ok(response.categories); + assert.ok(response.adult); + assert.ok(response.metadata); + assert.ok(response.faces); + assert.ok(response.color); + assert.ok(response.imageType); done(); }) }); @@ -409,13 +407,13 @@ describe('Project Oxford Vision API Test', function () { Categories: true }) .then(function (response) { - assert(response); - assert(response.categories); - assert(response.adult); - assert(response.metadata); - assert(response.faces); - assert(response.color); - assert(response.imageType); + assert.ok(response); + assert.ok(response.categories); + assert.ok(response.adult); + assert.ok(response.metadata); + assert.ok(response.faces); + assert.ok(response.color); + assert.ok(response.imageType); done(); }); }); @@ -431,7 +429,7 @@ describe('Project Oxford Vision API Test', function () { }) .then(function (response) { var stats = fs.statSync('./test/output/thumb2.jpg'); - assert((stats.size > 0)); + assert.ok((stats.size > 0)); done(); }); }); @@ -447,7 +445,7 @@ describe('Project Oxford Vision API Test', function () { }) .then(function (response) { var stats = fs.statSync('./test/output/thumb1.jpg'); - assert((stats.size > 0)); + assert.ok((stats.size > 0)); done(); }); }); @@ -460,8 +458,8 @@ describe('Project Oxford Vision API Test', function () { detectOrientation: true }) .then(function (response) { - assert(response.language); - assert(response.regions); + assert.ok(response.language); + assert.ok(response.regions); done(); }); }); @@ -474,8 +472,8 @@ describe('Project Oxford Vision API Test', function () { detectOrientation: true }) .then(function (response) { - assert(response.language); - assert(response.orientation); + assert.ok(response.language); + assert.ok(response.orientation); done(); }); }); diff --git a/types/range_check/range_check-tests.ts b/types/range_check/range_check-tests.ts index 5f3dc7c794..00c314fdf8 100644 --- a/types/range_check/range_check-tests.ts +++ b/types/range_check/range_check-tests.ts @@ -1,8 +1,6 @@ +import assert = require('assert'); import rangeCheck = require('range_check'); -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; - // isIP (same function as validIp and valid_ip) assert(rangeCheck.isIP('10.0.1.5')); // True diff --git a/types/rgrove__parse-xml/rgrove__parse-xml-tests.ts b/types/rgrove__parse-xml/rgrove__parse-xml-tests.ts index 4e2cbe4cd3..797465da3c 100644 --- a/types/rgrove__parse-xml/rgrove__parse-xml-tests.ts +++ b/types/rgrove__parse-xml/rgrove__parse-xml-tests.ts @@ -1,13 +1,8 @@ /// +import assert = require('assert'); import parseXml = require('@rgrove/parse-xml'); const doc = parseXml(''); - -// $ExpectType "document" -doc.type; - -// $ExpectType string -doc.children[0].type; - -// $ExpectType string -(doc.children[0] as parseXml.Element).name; +doc.type === "document"; +assert.equal(doc.children[0].type, "element"); +assert.equal((doc.children[0] as parseXml.Element).name, "party"); diff --git a/types/sanctuary/sanctuary-tests.ts b/types/sanctuary/sanctuary-tests.ts index dab3381bd5..a38f9d6384 100644 --- a/types/sanctuary/sanctuary-tests.ts +++ b/types/sanctuary/sanctuary-tests.ts @@ -1,11 +1,10 @@ /// +import * as assert from "assert"; import { create, env } from "sanctuary"; const checkTypes = process.env["NODE_ENV"] !== "production"; const S = create({checkTypes, env}); -// $ExpectType number -S.reduce(S.add)(0)([1, 2, 3, 4, 5]); - -// $ExpectType string -S.flip(S.concat)('foo')('bar'); +assert.equal(S.map(S.concat('@'))(['foo', 'bar', 'baz']), ["@foo", "@bar", "@baz"]); +assert.equal(S.reduce(S.add)(0)([1, 2, 3, 4, 5]), 15); +assert.equal(S.flip(S.concat)('foo')('bar'), "barfoo"); diff --git a/types/seed-random/seed-random-tests.ts b/types/seed-random/seed-random-tests.ts index 06daa88ff2..9872f63dfa 100644 --- a/types/seed-random/seed-random-tests.ts +++ b/types/seed-random/seed-random-tests.ts @@ -1,21 +1,26 @@ /// +import * as assert from 'assert'; import * as seed from 'seed-random'; -const trueRandomA = seed(); // $ExpectType () => number -const trueRandomB = seed(); // $ExpectType () => number +const trueRandomA = seed(); +const trueRandomB = seed(); +assert(trueRandomA() !== trueRandomB()); -const fakeRandomA = seed('foo'); // $ExpectType () => number -const fakeRandomB = seed('foo'); // $ExpectType () => number +const fakeRandomA = seed('foo'); +const fakeRandomB = seed('foo'); +assert(fakeRandomA() === fakeRandomB()); -const fakeRandomC = seed('foo', {entropy: true}); // $ExpectType () => number -const fakeRandomD = seed('foo', {entropy: true}); // $ExpectType () => number +const fakeRandomC = seed('foo', {entropy: true}); +const fakeRandomD = seed('foo', {entropy: true}); +assert(fakeRandomC() !== fakeRandomD()); // override global Math.random seed('foo', {global: true}); -const numA = Math.random(); // $ExpectType number +const numA = Math.random(); seed('foo', {global: true}); -const numB = Math.random(); // $ExpectType number +const numB = Math.random(); +assert(numA === numB); // reset to default Math.random seed.resetGlobal(); diff --git a/types/set-cookie-parser/set-cookie-parser-tests.ts b/types/set-cookie-parser/set-cookie-parser-tests.ts index da1b5b8a2e..5c5d952afc 100644 --- a/types/set-cookie-parser/set-cookie-parser-tests.ts +++ b/types/set-cookie-parser/set-cookie-parser-tests.ts @@ -1,55 +1,53 @@ +import * as assert from "assert"; import * as http from "http"; import setCookie = require("set-cookie-parser"); -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T, message?: string): void; - // Call parse function on imported object var input = "foo=bar;"; var cookies = setCookie.parse(input); -assertEqual(cookies.length, 1); -assertEqual(cookies[0].name, "foo"); -assertEqual(cookies[0].value, "bar"); +assert.equal(cookies.length, 1); +assert.equal(cookies[0].name, "foo"); +assert.equal(cookies[0].value, "bar"); // Required properties only test var requiredOnly = "foo=bar;"; cookies = setCookie(requiredOnly); -assertEqual(cookies.length, 1); -assertEqual(cookies[0].name, "foo"); -assertEqual(cookies[0].value, "bar"); +assert.equal(cookies.length, 1); +assert.equal(cookies[0].name, "foo"); +assert.equal(cookies[0].value, "bar"); // Optional properties included test var optionalIncluded = "foo=bar; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure; SameSite=Strict"; cookies = setCookie(optionalIncluded); -assertEqual(cookies.length, 1); -assertEqual(cookies[0].name, "foo"); -assertEqual(cookies[0].value, "bar"); -assertEqual(cookies[0].domain, ".example.com"); -assertEqual(cookies[0].path, "/"); -assertEqual(cookies[0].expires, new Date('Tue Jul 01 2025 06:01:11 GMT-0400 (EDT)')); -assertEqual(cookies[0].maxAge, 1000); -assertEqual(cookies[0].httpOnly, true); -assertEqual(cookies[0].secure, true); -assertEqual(cookies[0].sameSite, "Strict"); +assert.equal(cookies.length, 1); +assert.equal(cookies[0].name, "foo"); +assert.equal(cookies[0].value, "bar"); +assert.equal(cookies[0].domain, ".example.com"); +assert.equal(cookies[0].path, "/"); +assert.deepEqual(cookies[0].expires, new Date('Tue Jul 01 2025 06:01:11 GMT-0400 (EDT)')); +assert.equal(cookies[0].maxAge, 1000); +assert.equal(cookies[0].httpOnly, true); +assert.equal(cookies[0].secure, true); +assert.equal(cookies[0].sameSite, "Strict"); // Array of strings test var arrayOfCookies = ["bam=baz", "foo=bar"]; cookies = setCookie(arrayOfCookies); -assertEqual(cookies.length, 2); -assertEqual(cookies[0].name, "bam"); -assertEqual(cookies[0].value, "baz"); -assertEqual(cookies[1].name, "foo"); -assertEqual(cookies[1].value, "bar"); +assert.equal(cookies.length, 2); +assert.equal(cookies[0].name, "bam"); +assert.equal(cookies[0].value, "baz"); +assert.equal(cookies[1].name, "foo"); +assert.equal(cookies[1].value, "bar"); // HTTP response message test var message = {} as http.IncomingMessage; message.headers = { "set-cookie": ["bam=baz", "foo=bar"] }; cookies = setCookie(message); -assertEqual(cookies.length, 2); -assertEqual(cookies[0].name, "bam"); -assertEqual(cookies[0].value, "baz"); -assertEqual(cookies[1].name, "foo"); -assertEqual(cookies[1].value, "bar"); +assert.equal(cookies.length, 2); +assert.equal(cookies[0].name, "bam"); +assert.equal(cookies[0].value, "baz"); +assert.equal(cookies[1].name, "foo"); +assert.equal(cookies[1].value, "bar"); // Create new cookie with only required properties var requiredOnlyCookie: setCookie.Cookie = { @@ -70,16 +68,16 @@ var optionalIncludedCookie: setCookie.Cookie = { }; var cookiesString = setCookie.splitCookiesString(null) -assertEqual(cookiesString, []) +assert.deepStrictEqual(cookiesString, []) cookiesString = setCookie.splitCookiesString([]) -assertEqual(cookiesString, []) +assert.deepStrictEqual(cookiesString, []) cookiesString = setCookie.splitCookiesString([ 'foo=bar; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure', 'baz=buz; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure', ]) -assertEqual(cookiesString, [ +assert.deepStrictEqual(cookiesString, [ 'foo=bar; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure', 'baz=buz; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure', ]) @@ -87,17 +85,17 @@ assertEqual(cookiesString, [ cookiesString = setCookie.splitCookiesString( 'foo=bar; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure, baz=buz; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure', ) -assertEqual(cookiesString, [ +assert.deepStrictEqual(cookiesString, [ 'foo=bar; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure', 'baz=buz; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 2025 10:01:11 GMT; HttpOnly; Secure', ]) // Use decodeValues=false option var notDecodedValueCookies = setCookie.parse('user=%D0%98%D0%BB%D1%8C%D1%8F%20%D0%97%D0%B0%D0%B9%D1%86%D0%B5%D0%B2; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 3000 10:01:11 GMT; HttpOnly; Secure', { decodeValues: false }); -assertEqual(notDecodedValueCookies[0].value, '%D0%98%D0%BB%D1%8C%D1%8F%20%D0%97%D0%B0%D0%B9%D1%86%D0%B5%D0%B2'); +assert.equal(notDecodedValueCookies[0].value, '%D0%98%D0%BB%D1%8C%D1%8F%20%D0%97%D0%B0%D0%B9%D1%86%D0%B5%D0%B2'); var decodedValueCookies = setCookie.parse('user=%D0%98%D0%BB%D1%8C%D1%8F%20%D0%97%D0%B0%D0%B9%D1%86%D0%B5%D0%B2; Max-Age=1000; Domain=.example.com; Path=/; Expires=Tue, 01 Jul 3000 10:01:11 GMT; HttpOnly; Secure', { decodeValues: true }); -assertEqual(decodedValueCookies[0].value, 'Илья Зайцев'); +assert.equal(decodedValueCookies[0].value, 'Илья Зайцев'); // Use map=true option var expectedCookiesMap: setCookie.CookieMap = { @@ -109,4 +107,4 @@ var expectedCookiesMap: setCookie.CookieMap = { } }; var cookiesMap = setCookie.parse('foo=bar; Max-Age=1000; Domain=.example.com;', { map: true }); -assertEqual(cookiesMap, expectedCookiesMap); +assert.deepStrictEqual(cookiesMap, expectedCookiesMap); diff --git a/types/sort-object-keys/sort-object-keys-tests.ts b/types/sort-object-keys/sort-object-keys-tests.ts index 4dac2bd400..fd2148decf 100644 --- a/types/sort-object-keys/sort-object-keys-tests.ts +++ b/types/sort-object-keys/sort-object-keys-tests.ts @@ -1,9 +1,7 @@ +import assert = require('assert'); import sortObject = require('sort-object-keys'); -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T): void; - -assertEqual(JSON.stringify({ +assert.equal(JSON.stringify({ c: 1, b: 1, d: 1, @@ -15,7 +13,7 @@ assertEqual(JSON.stringify({ d: 1, })); -assertEqual(JSON.stringify(sortObject({ +assert.equal(JSON.stringify(sortObject({ c: 1, b: 1, d: 1, @@ -33,7 +31,7 @@ function removeKeyAncCompareIndex(keyA: string, keyB: string) { return a - b; } -assertEqual(JSON.stringify(sortObject({ +assert.equal(JSON.stringify(sortObject({ "key-1": 1, "key-3": 1, "key-10": 1, diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index 92b5716243..25e10a62ad 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -1,11 +1,9 @@ // via: http://visionmedia.github.io/superagent/ import request = require('superagent'); import * as fs from 'fs'; +import assert = require('assert'); import { Agent } from 'https'; -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; - // Examples taken from https://github.com/visionmedia/superagent/blob/gh-pages/docs/index.md // and https://github.com/visionmedia/superagent/blob/master/Readme.md @@ -462,7 +460,7 @@ request .get('/user/1') .on('response', res => { try { - assert('bar' === res.body.foo); + assert.equal('bar', res.body.foo); } catch (e) { /* ignore */ } }) .end(); diff --git a/types/superagent/v2/superagent-tests.ts b/types/superagent/v2/superagent-tests.ts index a0abd54fe2..32fd6fe333 100644 --- a/types/superagent/v2/superagent-tests.ts +++ b/types/superagent/v2/superagent-tests.ts @@ -2,11 +2,9 @@ import request = require('superagent'); import * as fs from 'fs'; +import assert = require('assert'); import { Agent } from 'https'; -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; - // Examples taken from https://github.com/visionmedia/superagent/blob/gh-pages/docs/index.md // and https://github.com/visionmedia/superagent/blob/master/Readme.md diff --git a/types/whatwg-mimetype/whatwg-mimetype-tests.ts b/types/whatwg-mimetype/whatwg-mimetype-tests.ts index c30b38aed6..5b5ab0f8ab 100644 --- a/types/whatwg-mimetype/whatwg-mimetype-tests.ts +++ b/types/whatwg-mimetype/whatwg-mimetype-tests.ts @@ -1,9 +1,7 @@ /// +import assert = require("assert"); import MIMEType = require('whatwg-mimetype'); -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assert(value: boolean): void; - const mt = MIMEType.parse("text/plain"); assert(mt !== null); diff --git a/types/xmlpoke/xmlpoke-tests.ts b/types/xmlpoke/xmlpoke-tests.ts index b62a2cc81b..04cab2aa1f 100644 --- a/types/xmlpoke/xmlpoke-tests.ts +++ b/types/xmlpoke/xmlpoke-tests.ts @@ -1,70 +1,68 @@ import xmlpoke = require('xmlpoke'); - -// Declaring shims removes assert dependency. These tests are never executed, only typechecked, so this is fine. -declare function assertEqual(actual: T, expected: T): void; +import assert = require('assert'); let result: string; // add with xpath, value result = xmlpoke('', xml => xml.add('/a/b', 'c')); -assertEqual(result, 'c'); +assert.equal(result, 'c'); // add with xpath, Transform const addfn: XmlPoke.Transform = (node, value) => 'c'; result = xmlpoke('', xml => xml.add('/a/b', addfn)); -assertEqual(result, 'c'); +assert.equal(result, 'c'); // add with xpath, CDataValue const cdataval: XmlPoke.CDataValue = new xmlpoke.CDataValue('c'); result = xmlpoke('', xml => xml.add('/a/b', cdataval)); -assertEqual(result, ''); +assert.equal(result, ''); // add with xpath, XMLVal const xmlval = new xmlpoke.XmlString(''); result = xmlpoke('', xml => xml.add('/a/b', xmlval)); -assertEqual(result, ''); +assert.equal(result, ''); // add with map result = xmlpoke('', xml => xml.add({ '/a/b': 'c' })); -assertEqual(result, 'c'); +assert.equal(result, 'c'); // set with xpath, value result = xmlpoke('b', xml => xml.set('/a', 'c')); -assertEqual(result, 'c'); +assert.equal(result, 'c'); // set with map result = xmlpoke('b', xml => xml.set({ '/a': 'c' })); -assertEqual(result, 'c'); +assert.equal(result, 'c'); // set with xpath that doesn't exist (no-op) result = xmlpoke('bval', xml => xml.set('/a/c', 'cval')); -assertEqual(result, 'bval'); +assert.equal(result, 'bval'); // setOrAdd with xpath, value result = xmlpoke('', xml => xml.setOrAdd('/a/b', 'c')); -assertEqual(result, 'c'); +assert.equal(result, 'c'); // setOrAdd with map result = xmlpoke('', xml => xml.setOrAdd({ '/a/b': 'c' })); -assertEqual(result, 'c'); +assert.equal(result, 'c'); // setOrAdd with xpath that doesn't exist: add result = xmlpoke('bval', xml => xml.setOrAdd('/a/c', 'cval')); -assertEqual(result, 'bvalcval'); +assert.equal(result, 'bvalcval'); // remove result = xmlpoke('', xml => xml.remove('//b')); -assertEqual(result, ''); +assert.equal(result, ''); // clear result = xmlpoke('', xml => xml.clear('/a')); -assertEqual(result, ''); +assert.equal(result, ''); // withBasePath, addNamespace, errorOnNoMatches result = xmlpoke('', xml => @@ -72,13 +70,13 @@ result = xmlpoke('', xml => .addNamespace('x', 'http://example.com/x') .errorOnNoMatches() .set('/x', (node, value) => { - assertEqual(typeof node, 'object'); - assertEqual((node.constructor as any).name, 'Element'); - assertEqual(value, 'hello'); + assert.equal(typeof node, 'object'); + assert.equal((node.constructor as any).name, 'Element'); + assert.equal(value, 'hello'); return 'y'; })); -assertEqual(result, 'y'); +assert.equal(result, 'y'); // ensure result = xmlpoke('', xml => xml.ensure('a/b')); -assertEqual(result, ''); +assert.equal(result, ''); diff --git a/types/yadda/yadda-tests.ts b/types/yadda/yadda-tests.ts index 17e55df090..cccb613a30 100644 --- a/types/yadda/yadda-tests.ts +++ b/types/yadda/yadda-tests.ts @@ -1,5 +1,7 @@ /// +import * as assert from "assert"; + import * as Yadda from "yadda"; const English = Yadda.localisation.English; @@ -185,6 +187,7 @@ const bottlesLibrary = English.library() console.log("%s bottle falls", number_of_falling_bottles); }) .then("there are $NUM green bottles standing on the wall", (number_of_bottles: string) => { + assert.strictEqual(Number(number_of_bottles), wall.bottles); wall.printStatus(); });