Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Move global DSL type definitions into an index file. #93

Closed
wants to merge 15 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
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet - new version. That has async/await I assume. Will update my other references to this too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, still open microsoft/TypeScript#9175

"typings": "^1.3.0"
},
"repository": {
Expand All @@ -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"
]
}
55 changes: 55 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freak'in BEAUTIFUL!!!! 🎱

14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;

31 changes: 3 additions & 28 deletions src/specs/typescript.spec.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -49,10 +25,9 @@ const TypeScriptComponent = ({
return <div style={ style } />;
};

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(<TypeScriptComponent />));

Expand Down
16 changes: 11 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"target": "es6",
"sourceMap": true,
"module": "commonjs",
Expand All @@ -8,19 +10,23 @@
"jsx": "react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true,
"strictNullChecks": true,
"outDir": "dist"
"strictNullChecks": true
},
"include": [
"typings/index.d.ts",
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"src/specs", // Comment this line to check type definitions in specs
"node_modules"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true
}
}
}
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"quotemark": [
true, "single"
],
"jsx-no-lambda": true
"jsx-no-lambda": true,
"no-namespace": false
}
}