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