diff --git a/package.json b/package.json index 5d6d6c2..6c5cb6d 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,14 @@ "name": "ui-harness", "version": "3.16.2", "description": "Create, isolate and test modular UI components in React.", - "main": "./lib/server", + "main": "./lib", + "typings": "./lib/index.d.ts", "scripts": { + "build": "npm run build:babel && npm run build:copy-types", + "build:babel": "./node_modules/babel-cli/bin/babel.js src --out-dir lib --source-maps", + "build:typescript": "./node_modules/typescript/bin/tsc", + "build:copy-types": "cp src/index.d.ts lib/index.d.ts", "build:watch": "npm run build -- --watch", - "build": "./node_modules/babel-cli/bin/babel.js src --out-dir lib --source-maps", "dev": "QUICK_BUILD=true ./node_modules/.bin/nodemon -x \"./node_modules/babel-cli/bin/babel-node.js start.js\"", "lint": "eslint --ext .js,.jsx ./src && tslint src/**/*.ts{,x}", "prepublish": "npm test && npm run lint && rm -rf lib && npm run build", @@ -76,7 +80,7 @@ "sinon": "^1.16.1", "tslint": "^3.11.0", "tslint-react": "^0.4.0", - "typescript": "^1.9.0-dev.20160617-1.0", + "typescript": "^2.1.0-dev.20160716", "typings": "^1.3.0" }, "repository": { @@ -97,5 +101,10 @@ "bugs": { "url": "https://github.com/philcockfield/ui-harness/issues" }, - "homepage": "http://uiharness.com" + "homepage": "http://uiharness.com", + "files": [ + "lib", + "typings.json", + "LICENSE" + ] } diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..f0d7d78 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,55 @@ + +declare namespace UIHarness { + import React = __React; + type IUIHComponent = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; + + interface ICropMarks { + (enabled: boolean): IUIHarnessContext; + size(value: number): IUIHarnessContext; + offset(value: number): IUIHarnessContext; + } + + class IUIHarnessContext { + public toValues(): {}; + public reset(options: {}): void; + public props(value: {}): {}; + public context(value: {}): {}; + public component(component: IUIHComponent): this; + public unload(): this; + + public log(...value: any[]): this; + + // property setters + public children(children: React.ReactType[] | React.ReactType): this; + public childContextTypes(value: {}): this; + public width(value: string | number): this; + public height(value: string | number): this; + public cropMarks: ICropMarks; // tslint:disable-line:member-ordering + public margin(value: number): this; + public align(value: string): this; // TODO: Type this.align() better + public header(value: string): this; + public footer(value: string): this; + public hr(enabled: boolean): this; + public backdrop(value: string | number): this; + public background(value: string | number): this; + public scroll(value: boolean | 'x' | 'y' | 'x:y'): this; + public style(value: React.CSSProperties): this; + } + + interface IActionType { (this: IUIHarnessContext): void; } + + interface IBDDFunction { + (label: string, action?: IActionType): void; + (action: IActionType): void; + } + +} + +export declare var describe: UIHarness.IBDDFunction; +export declare var before: UIHarness.IBDDFunction; +export declare var section: UIHarness.IBDDFunction; +export declare var it: UIHarness.IBDDFunction; + +declare var defaultExport: { start: any, build: any }; +export default defaultExport; + diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..8aa3cef --- /dev/null +++ b/src/index.js @@ -0,0 +1,14 @@ +import server from './server/index.js'; +import bdd from 'js-bdd'; + +// Server API - Maintain backwards compatibility +export default { + start: server.start, + build: server.build, +}; + +export const before = bdd.before; +export const describe = bdd.describe; +export const it = bdd.it; +export const section = bdd.section; + diff --git a/src/specs/typescript.spec.tsx b/src/specs/typescript.spec.tsx index ed5bf87..8b8cd5b 100644 --- a/src/specs/typescript.spec.tsx +++ b/src/specs/typescript.spec.tsx @@ -1,30 +1,6 @@ +import { before, describe, it } from '../'; import * as React from 'react'; - -/* - UIHarness type definitions for now -*/ - -type UIComponentType = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; -declare class IUIHarnessContext { - public component: (component: UIComponentType) => this; - public header: (title: string) => this; -} - -type ActionType = (this: IUIHarnessContext) => void; -type BDDType = (labelOrAction: string | ActionType, action?: ActionType) => void; - -declare var describe: BDDType; -declare var before: BDDType; -declare var section: BDDType; -declare var it: BDDType; - -/* Type definitions end */ - - - - - // tslint:disable-next-line // Using class as enums cannot use strings. http://stackoverflow.com/questions/15490560/create-an-enum-with-string-values-in-typescript class UIBGColors { @@ -49,10 +25,9 @@ const TypeScriptComponent = ({ return
; }; -describe('TypeScript', function (this: IUIHarnessContext): void { +describe('TypeScript', function (): void { // Temporary fix until UIHarness core is typed correctly - const self: IUIHarnessContext = this; - self.header(`## A React component written in TypeScript.`); + this.header(`## A React component written in TypeScript.`); before(() => this.component(