Skip to content

Distribute power-assert.d.ts(index.d.ts) type definition files using npm #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "empower";
import "power-assert-formatter";
import "./typings/power-assert";
export * from "power-assert";
export {default} from "power-assert";
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@
"expect.js": "^0.3.1",
"licensify": "^2.0.1",
"qunit-tap": "^1.5.0",
"qunitjs": "1.14.0"
"qunitjs": "1.14.0",
"typescript": "^1.6.2"
},
"files": [
"CHANGELOG.md",
"MIT-LICENSE.txt",
"README.md",
"index.js",
"index.d.ts",
"typings/**/*.d.ts",
"build/power-assert.js",
"package.json",
"test"
Expand All @@ -77,15 +80,16 @@
"scripts": {
"bower": "bower install --config.interactive=false",
"build": "npm prune && npm dedupe && browserify -p licensify --standalone assert ./index.js | dereserve | derequire > build/power-assert.js",
"clean": "rm -rf ./espowered_tests && rm -rf ./build",
"clean": "rm -rf ./espowered_tests && rm -rf ./build && rm test/test-typings.js",
"setup-dir": "mkdir -p ./build && mkdir -p ./espowered_tests/tobe_instrumented && cp -r test/not_tobe_instrumented/ ./espowered_tests/not_tobe_instrumented/",
"setup-espower": "for i in $(find ./test/tobe_instrumented -name '*_test.js'); do babel --plugins babel-plugin-espower --blacklist strict $i > ./espowered_tests/tobe_instrumented/$(basename $i); done",
"setup": "npm run clean && npm run setup-dir && npm run setup-espower && npm run build",
"test-unit": "mocha --reporter dot --require ./enable_power_assert.js ./test/**/*_test.js",
"test-generated": "mocha --reporter dot ./espowered_tests/**/*_test.js",
"test-browser": "mocha-phantomjs --reporter dot test/test-browser.html",
"test-amd": "mocha-phantomjs --reporter dot test/test-amd.html",
"test-all": "npm run test-unit && npm run test-generated && npm run test-browser && npm run test-amd",
"test-typings": "node node_modules/typescript/lib/tsc -p ./ && node test/test-typings && rm test/test-typings.js",
"test-all": "npm run test-unit && npm run test-generated && npm run test-browser && npm run test-amd && npm run test-typings",
"test": "npm run setup && npm run test-all"
}
}
81 changes: 81 additions & 0 deletions test/test-typings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import assert from "../";

assert(1 + 1 - 2 === 0, "The universe isn't how it should.");

assert.deepEqual({x: {y: 3}}, {x: {y: 3}}, "DEEP WENT DERP");

assert.equal(3, "3", "uses == comparator");

assert.notStrictEqual(2, "2", "uses === comparator");

assert.throws(() => {
throw "a hammer at your face";
}, undefined, "DODGED IT");

assert.doesNotThrow(() => {
if (false) {
throw "a hammer at your face";
}
}, undefined, "What the...*crunch*");


var customizedAssert1 = assert.customize({
output: {
maxDepth: 2
}
});

customizedAssert1(1 + 1 - 2 === 0, "The universe isn't how it should.");

customizedAssert1.deepEqual({x: {y: 3}}, {x: {y: 3}}, "DEEP WENT DERP");

customizedAssert1.equal(3, "3", "uses == comparator");

customizedAssert1.notStrictEqual(2, "2", "uses === comparator");

customizedAssert1.throws(() => {
throw "a hammer at your face";
}, undefined, "DODGED IT");

customizedAssert1.doesNotThrow(() => {
if (false) {
throw "a hammer at your face";
}
}, undefined, "What the...*crunch*");


var customizedAssert2 = assert.customize({
assertion: {
destructive: false,
modifyMessageOnRethrow: true,
saveContextOnRethrow: true,
patterns: [
'assert(value, [message])',
'assert.ok(value, [message])',
'assert.equal(actual, expected, [message])',
'assert.notEqual(actual, expected, [message])',
'assert.strictEqual(actual, expected, [message])',
'assert.notStrictEqual(actual, expected, [message])',
'assert.deepEqual(actual, expected, [message])',
'assert.notDeepEqual(actual, expected, [message])'
]
},
output: {
lineDiffThreshold: 5,
maxDepth: 1,
anonymous: 'Object',
circular: '#@Circular#',
lineSeparator: '\n',
ambiguousEastAsianCharWidth: 2,
widthOf: () => false,
stringify: () => false,
diff: () => false,
writerClass: null,
renderers: [
'./built-in/file',
'./built-in/assertion',
'./built-in/diagram',
'./built-in/binary-expression'
]
}
});
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true
},
"files": [
"index.d.ts",
"test/test-typings"
]
}
61 changes: 61 additions & 0 deletions typings/power-assert.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Type definitions for power-assert
// Project: https://github.com/twada/power-assert
// Definitions by: vvakame <https://github.com/vvakame>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

declare function assert(value:any, message?:string):void;
declare namespace assert {
export class AssertionError implements Error {
name:string;
message:string;
actual:any;
expected:any;
operator:string;
generatedMessage:boolean;

constructor(options?:{message?: string; actual?: any; expected?: any; operator?: string; stackStartFunction?: Function});
}

export function fail(actual?:any, expected?:any, message?:string, operator?:string):void;

export function ok(value:any, message?:string):void;

export function equal(actual:any, expected:any, message?:string):void;

export function notEqual(actual:any, expected:any, message?:string):void;

export function deepEqual(actual:any, expected:any, message?:string):void;

export function notDeepEqual(acutal:any, expected:any, message?:string):void;

export function strictEqual(actual:any, expected:any, message?:string):void;

export function notStrictEqual(actual:any, expected:any, message?:string):void;

export var throws:{
(block:Function, message?:string): void;
(block:Function, error:Function, message?:string): void;
(block:Function, error:RegExp, message?:string): void;
(block:Function, error:(err:any) => boolean, message?:string): void;
};

export var doesNotThrow:{
(block:Function, message?:string): void;
(block:Function, error:Function, message?:string): void;
(block:Function, error:RegExp, message?:string): void;
(block:Function, error:(err:any) => boolean, message?:string): void;
};

export function ifError(value:any):void;

export interface Options {
assertion?: empower.Options;
output?: powerAssertFormatter.Options;
}

export function customize(options:Options):typeof assert;
}

declare module "power-assert" {
export default assert;
}