From bafdeeaa0562e2c63b713760f14581f644e9f584 Mon Sep 17 00:00:00 2001 From: Paul Shannon Date: Thu, 1 Jun 2017 18:18:31 -0700 Subject: [PATCH 1/2] Added A-Frame typings clean-up aframe DT header using files in tsconfig.json removing name from package.json removing version from package.json removing scripts from package.json removing types from package.json Moved package.json to tests to support ease of use Telling DT to ignore tests removing unix standard blank line at end of UNUSED_FILES.txt dtslint seems to want a commonjs module module in compileroptions module in compileroptions cleaning up lint errors --- types/aframe/README.md | 28 +++ types/aframe/UNUSED_FILES.txt | 1 + types/aframe/aframe-tests.ts | 45 +++++ types/aframe/index.d.ts | 324 +++++++++++++++++++++++++++++++ types/aframe/tests/aframe.ts | 37 ++++ types/aframe/tests/component.ts | 45 +++++ types/aframe/tests/entity.ts | 66 +++++++ types/aframe/tests/intern.ts | 26 +++ types/aframe/tests/package.json | 19 ++ types/aframe/tests/tests.html | 8 + types/aframe/tests/tsconfig.json | 22 +++ types/aframe/tsconfig.json | 26 +++ types/aframe/tslint.json | 5 + 13 files changed, 652 insertions(+) create mode 100644 types/aframe/README.md create mode 100644 types/aframe/UNUSED_FILES.txt create mode 100644 types/aframe/aframe-tests.ts create mode 100644 types/aframe/index.d.ts create mode 100644 types/aframe/tests/aframe.ts create mode 100644 types/aframe/tests/component.ts create mode 100644 types/aframe/tests/entity.ts create mode 100755 types/aframe/tests/intern.ts create mode 100755 types/aframe/tests/package.json create mode 100644 types/aframe/tests/tests.html create mode 100644 types/aframe/tests/tsconfig.json create mode 100755 types/aframe/tsconfig.json create mode 100644 types/aframe/tslint.json diff --git a/types/aframe/README.md b/types/aframe/README.md new file mode 100644 index 0000000000..0bceeb7487 --- /dev/null +++ b/types/aframe/README.md @@ -0,0 +1,28 @@ +# aframe typings + +### build + +From the `tests` directory run: + +* `npm i` +* `npm run build` + +This will build the both `aframe-tests.ts` and the `tests` directory using the provided typings. + +Note: If you do not want to install node modules then a basic test can be ran by compiling `aframe-tests.ts` +by typing `tsc`. + +### test + +* build using the instructions above +* open `tests/tests.html` in a browser + +The testing framework uses [intern](https://theintern.github.io/) to run tests. The tests ensure that typings are +actually written against real aframe constructs by exercising the code and validating assertions. Intern also supports +local execution using Selenium by running `npm run test`. + + +## Contributing + +These typings cover much of the core of A-Frame. Help is welcomed to provide typings for A-Frame bundled components and +additional intern tests <3 diff --git a/types/aframe/UNUSED_FILES.txt b/types/aframe/UNUSED_FILES.txt new file mode 100644 index 0000000000..3598c3003f --- /dev/null +++ b/types/aframe/UNUSED_FILES.txt @@ -0,0 +1 @@ +tests \ No newline at end of file diff --git a/types/aframe/aframe-tests.ts b/types/aframe/aframe-tests.ts new file mode 100644 index 0000000000..190489b346 --- /dev/null +++ b/types/aframe/aframe-tests.ts @@ -0,0 +1,45 @@ +// Entity +const entity = document.createElement('a-entity'); +entity.emit('rotate'); +entity.emit('collide', { target: entity }); +entity.emit('sink', null, false); + +const position = entity.getAttribute('position'); +position.x; +position.y; +position.z; +entity.setAttribute('material', 'color', 'red'); + +entity.components['geometry'].data; + +type MyEntity = AFrame.Entity<{ + camera: THREE.Camera; + material: THREE.Material; + sound: { pause(): void }; +}>; +const camera = document.querySelector('a-entity[camera]').components.camera; +const material = document.querySelector('a-entity[material]').components.material; +document.querySelector('a-entity[sound]').components.sound.pause(); + +entity.getDOMAttribute('geometry').primitive; + +entity.setAttribute('light', { + type: 'spot', + distance: 30, + intensity: 2.0 +}); + +entity.addEventListener('child-detached', (event) => { + event.detail; +}); + +// Components +const Component = AFRAME.registerComponent('test', {}); + +// Scene + +const scene = document.querySelector('a-scene'); +scene.hasLoaded; + +// System +const system = scene.systems['systemName']; diff --git a/types/aframe/index.d.ts b/types/aframe/index.d.ts new file mode 100644 index 0000000000..b1a763e7dd --- /dev/null +++ b/types/aframe/index.d.ts @@ -0,0 +1,324 @@ +// Type definitions for AFRAME 0.5 +// Project: https://aframe.io/ +// Definitions by: Paul Shannon +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// +/// + +// Globals +declare var AFRAME: AFrame.AFrameGlobal; +declare var hasNativeWebVRImplementation: boolean; + +interface NodeSelector { + querySelector(selectors: 'a-scene'): AFrame.Scene; + querySelector>(selectors: string): T; + querySelectorAll(selectors: string): NodeListOf | Element>; +} + +interface Document { + createElement(tagName: string): AFrame.Entity; +} + +// Interfaces +declare namespace AFrame { + interface ObjectMap { + [ key: string ]: T; + } + + interface AFrameGlobal { + AEntity: Entity; + ANode: ANode; + AScene: Scene; + components: { [ key: string ]: ComponentDescriptor }; + geometries: { [ key: string ]: GeometryDescriptor }; + primitives: { [ key: string ]: Entity }; + registerComponent(name: string, component: ComponentDefinition): ComponentConstructor; + registerElement(name: string, element: ANode): void; + registerGeometry(name: string, geometery: THREE.Geometry): Geometry; + registerPrimitive(name: string, primitive: PrimitiveDefinition): void; + registerShader(name: string, shader: any): void; + registerSystem(name: string, definition: SystemDefinition): void; + schema: SchemaUtils; + shaders: { [ key: string ]: ShaderDescriptor }; + systems: { [key: string]: System }; + THREE: any; // TODO THREE + TWEEN: any; // TODO TWEEN + utils: Utils; + version: string; + } + + interface Animation { + attribute: string; + begin: string | number; + delay: number; + direction: 'alternate' | 'alternateReverse' | 'normal' | 'reverse'; + dur: number; + easing(): void; + end: string; + fill: 'backwards' | 'both' | 'forwards' | 'none'; + from: any; // TODO type + repeat: number | 'indefinite'; + to: number; + } + + interface ANode extends HTMLElement { + // Only public APIs added. Many methods intentionally left out. + // createdCallback + // attachedCallback + // attributeChangedCallback + closestScene(): Scene; + closest(selector: string): ANode; + // detachedCallback + hasLoaded: boolean; + load(cb?: () => void, childFilter?: (el: Element) => boolean): void; + // updateMixins + registerMixin(id: string): void; + setAttribute(type: string, newValue: any): void; + unregisterMixin(id: string): void; + removeMixinListener(id: string): void; + attachMixinListener(mixin: HTMLElement): void; + emit(name: string, detail?: any, bubbles?: boolean): void; + emitter(name: string, detail?: any, bubbles?: boolean): () => void; + } + + interface Behavior { + tick(): void; + } + + interface Component { + attrName?: string; + data?: any; + dependencies?: string[]; + el: Entity; + id: string; + multiple?: boolean; + name: string; + schema: Schema; + + init(): void; + pause(): void; + play(): void; + remove(): void; + tick?(time: number, timeDelta: number): void; + update(oldData: any): void; + updateSchema?(): void; + + extendSchema(update: Schema): void; + flushToDOM(): void; + } + + interface ComponentConstructor { + new (el: Entity, name: string, id: string): Component; + } + + interface ComponentDefinition { + dependencies?: string[]; + el?: Entity; + id?: string; + multiple?: boolean; + schema?: Schema; + + init?(): void; + pause?(): void; + play?(): void; + remove?(): void; + tick?(time: number, timeDelta: number): void; + update?(oldData: any): void; + updateSchema?(): void; + + [ key: string ]: any; + } + + interface ComponentDescriptor { + Component: Component; + dependencies: string[] | null; + multiple: boolean | null; + + // internal APIs2 + // parse + // parseAttrValueForCache + // schema + // stringify + // type + [ key: string ]: any; + } + + interface Coordinate { + x: number; + y: number; + z: number; + } + + interface Entity> extends ANode { + components: C; + isPlaying: boolean; + object3D: THREE.Object3D; + object3DMap: ObjectMap; + sceneEl?: Scene; + + addState(name: string): void; + flushToDOM(recursive?: boolean): void; + /** + * @deprecated since 0.4.0 + */ + getComputedAttribute(attr: string): T; + getDOMAttribute(attr: string): T; + getObject3D(type: string): THREE.Object3D; + getOrCreateObject3D(type: string, construct: any): THREE.Object3D; + is(stateName: string): boolean; + pause(): void; + play(): void; + setObject3D(type: string, obj: THREE.Object3D): void; + removeAttribute(attr: string, property?: string): void; + removeObject3D(type: string): void; + removeState(stateName: string): void; + + // getAttribute specific usages + getAttribute(type: string): any; + getAttribute(attr: string): T; + getAttribute(type: 'position' | 'rotation' | 'scale'): Coordinate; + + // setAttribute specific usages + setAttribute(attr: string, value: any): void; + setAttribute(attr: string, property: string, componentAttrValue?: any): void; + setAttribute(type: 'position' | 'rotation' | 'scale', value: Coordinate): void; + + // addEventListener specific usages + addEventListener(type: K, listener: (event: Event & EntityEventMap[K]) => void, useCapture?: boolean): void; + addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + } + + type DetailEvent = Event & { detail: D }; + + interface EntityEventMap { + 'child-attached': DetailEvent<{ el: Element | Entity }>; + 'child-detached': DetailEvent<{ el: Element | Entity }>; + 'componentchanged': DetailEvent<{ name: string }>; + 'componentremoved': DetailEvent<{ + name: string, + id: string, + newData: any, + oldData: any + }>; + 'loaded': EventListener; + 'pause': EventListener; + 'play': EventListener; + 'stateadded': DetailEvent<{ state: string }>; + 'stateremoved': DetailEvent<{ state: string }>; + 'schemachanged': DetailEvent<{ componentName: string }>; + } + + interface Geometry { + name: string; + geometry: THREE.Geometry; + schema: Schema; + update(data: object): void; + [ key: string ]: any; + } + + interface GeometryDescriptor { + Geometry: Geometry; + schema: Schema; + } + + interface MultiPropertySchema { + [ key: string ]: SinglePropertySchema; + } + + interface PrimitiveDefinition { + defaultComponents?: any; // TODO cleanup type + deprecated?: boolean; + mappings?: any; // TODO cleanup type + transforms?: any; // TODO cleanup type + } + + type PropertyTypes = 'array' | 'boolean' | 'color' | 'int' | 'number' | 'selector' | + 'selectorAll' | 'src' | 'string' | 'vec2' | 'vec3' | 'vec4'; + + type SceneEvents = 'enter-vr' | 'exit-vr' | 'loaded' | 'renderstart'; + + interface Scene extends Entity { + behaviors: Behavior[]; + camera: THREE.Camera; + canvas: HTMLCanvasElement; + effect: THREE.VREffect; + isMobile: boolean; + object3D: THREE.Scene; + renderer: THREE.WebGLRenderer; + renderStarted: boolean; + systems: ObjectMap; + time: number; + + enterVR(): Promise | void; + exitVR(): Promise | void; + reload(): void; + + addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + addEventListener(type: SceneEvents, listener: EventListener, useCapture?: boolean): void; + } + + type Schema = SinglePropertySchema | MultiPropertySchema; + + interface SchemaUtils { + isSingleProperty(schema: Schema): boolean; + process(schema: Schema): boolean; + } + + interface Shader { + name: string; + schema: Schema; + } + + interface ShaderDescriptor { + Shader: Shader; + schema: Schema; + } + + interface SinglePropertySchema { + type?: PropertyTypes; + 'default'?: T; + parse?(value: string): T; + stringify?(value: T): string; + [ key: string ]: any; + } + + interface System { + data: any; + schema: Schema; + init(): void; + pause(): void; + play(): void; + tick?(): void; + } + + interface SystemDefinition { + schema?: Schema; + init?(): void; + pause?(): void; + play?(): void; + tick?(): void; + [ key: string ]: any; + } + + interface Utils { + coordinates: { + isCoordinate(value: string): boolean; + parse(value: string): Coordinate; + stringify(coord: Coordinate): string; + }; + entity: { + getComponentProperty(entity: Entity, componentName: string, delimiter?: string): any; + setComponentProperty(entity: Entity, componentName: string, value: any, delimiter?: string): void; + }; + styleParser: { + parse(value: string): object; + stringify(data: object): string; + }; + deepEqual(a: any, b: any): boolean; + diff(a: object, b: object): object; + extend(target: object, ... source: object[]): object; + extendDeep(target: object, ... source: object[]): object; + } +} diff --git a/types/aframe/tests/aframe.ts b/types/aframe/tests/aframe.ts new file mode 100644 index 0000000000..37d839e4df --- /dev/null +++ b/types/aframe/tests/aframe.ts @@ -0,0 +1,37 @@ +import 'aframe'; +import { describe, it } from 'intern!bdd'; +import * as expect from 'intern/chai!expect'; + +/** + * A-Frame exposes its public interface through the window.AFRAME browser global. + */ +describe('aframe global', () => { + describe('AFRAME', () => { + it('has the expected shape', () => { + expect(AFRAME).to.exist; + + expect(AFRAME.components).to.exist; + expect(AFRAME.geometries).to.exist; + expect(AFRAME.primitives).to.exist; + expect(AFRAME.schema).to.exist; + expect(AFRAME.shaders).to.exist; + expect(AFRAME.systems).to.exist; + expect(AFRAME.THREE).to.exist; + expect(AFRAME.TWEEN).to.exist; + expect(AFRAME.utils).to.exist; + expect(AFRAME.version).to.exist; + + expect(AFRAME.AEntity).to.be.a('function'); + expect(AFRAME.ANode).to.be.a('function'); + expect(AFRAME.AScene).to.be.a('function'); + expect(AFRAME.registerComponent).to.be.a('function'); + expect(AFRAME.registerElement).to.be.a('function'); + expect(AFRAME.registerGeometry).to.be.a('function'); + expect(AFRAME.registerPrimitive).to.be.a('function'); + }); + }); + + it('hasNativeWebVRImplementation', () => { + expect(window).to.have.property('hasNativeWebVRImplementation'); + }); +}); diff --git a/types/aframe/tests/component.ts b/types/aframe/tests/component.ts new file mode 100644 index 0000000000..0c7390e0c7 --- /dev/null +++ b/types/aframe/tests/component.ts @@ -0,0 +1,45 @@ +import 'aframe'; +import { describe, beforeEach, afterEach, it } from 'intern!bdd'; +import * as expect from 'intern/chai!expect'; + +describe('components', () => { + let Component: AFrame.ComponentConstructor; + + afterEach(() => { + if (Component) { + delete AFRAME.components[Component.prototype.name]; + } + }); + + describe('basic component', () => { + beforeEach(() => { + Component = AFRAME.registerComponent('test', {}); + }); + + it('has the expected shape', () => { + expect(Component).to.exist; + const entity: AFrame.Entity = document.createElement('a-entity'); + const component = new Component(entity, 'test', 'test'); + + expect(component.attrName).to.exist; + expect(component.el).to.exist; + expect(component.id).to.exist; + expect(component.name).to.exist; + expect(component.schema).to.exist; + + expect(component.data).to.not.exist; + expect(component.dependencies).to.not.exist; + expect(component.multiple).to.not.exist; + expect(component.tick).to.not.exist; + + expect(component.init).to.be.a('function'); + expect(component.update).to.be.a('function'); + expect(component.remove).to.be.a('function'); + expect(component.play).to.be.a('function'); + expect(component.pause).to.be.a('function'); + expect(component.remove).to.be.a('function'); + expect(component.flushToDOM).to.be.a('function'); + expect(component.extendSchema).to.be.a('function'); + }); + }); +}); diff --git a/types/aframe/tests/entity.ts b/types/aframe/tests/entity.ts new file mode 100644 index 0000000000..68cf591633 --- /dev/null +++ b/types/aframe/tests/entity.ts @@ -0,0 +1,66 @@ +import 'aframe'; +import { describe, beforeEach, afterEach, it } from 'intern!bdd'; +import * as expect from 'intern/chai!expect'; + +function assertStaticShape(entity: AFrame.Entity) { + expect(entity).to.exist; + + expect(entity.components).to.exist; + expect(entity.object3D).to.exist; + expect(entity.object3DMap).to.exist; + + expect(entity.addState).to.be.a('function'); + expect(entity.emit).to.be.a('function'); + expect(entity.flushToDOM).to.be.a('function'); + expect(entity.getAttribute).to.be.a('function'); + expect(entity.getComputedAttribute).to.be.a('function'); + expect(entity.getObject3D).to.be.a('function'); + expect(entity.getOrCreateObject3D).to.be.a('function'); + expect(entity.is).to.be.a('function'); + expect(entity.pause).to.be.a('function'); + expect(entity.play).to.be.a('function'); + expect(entity.setAttribute).to.be.a('function'); + expect(entity.setObject3D).to.be.a('function'); + expect(entity.removeAttribute).to.be.a('function'); + expect(entity.removeObject3D).to.be.a('function'); + expect(entity.removeState).to.be.a('function'); +} + +describe('entity', () => { + let entity: AFrame.Entity; + + beforeEach(() => { + entity = document.createElement('a-entity'); + }); + + describe('entity is not attached to a scene', () => { + it('has the expected shape', () => { + assertStaticShape(entity); + expect(entity.sceneEl).to.not.exist; + }); + }); + + describe('entity is part of a scene', () => { + let scene: AFrame.Scene; + + beforeEach(() => { + return new Promise(function (resolve) { + scene = document.createElement('a-scene'); + scene.addEventListener('renderstart', function () { + resolve(); + }); + document.body.appendChild(scene); + scene.appendChild(entity); + }); + }); + + afterEach(() => { + document.body.innerHTML = ''; + }); + + it('has the expected shape', () => { + assertStaticShape(entity); + expect(entity.sceneEl).to.exist; + }); + }); +}); diff --git a/types/aframe/tests/intern.ts b/types/aframe/tests/intern.ts new file mode 100755 index 0000000000..f81395f8ec --- /dev/null +++ b/types/aframe/tests/intern.ts @@ -0,0 +1,26 @@ +export const loaders = { + 'host-browser': 'node_modules/@dojo/loader/loader.js' +}; + +export const environments = [ + { browserName: 'chrome' } +]; + +// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader +// can be used here +export const loaderOptions = { + // Packages that should be registered with the loader in each testing environment + packages: [ + { name: 'tests', location: '.' }, + { name: 'aframe', location: `./node_modules/aframe/dist`, main: 'aframe-master.js' } + ] +}; + +export const suites = [ + 'tests/aframe', + 'tests/component', + 'tests/entity' +]; + +// A regular expression matching URLs to files that should not be included in code coverage analysis +export const excludeInstrumentation = /(?:node_modules|tests)[\/\\]/; diff --git a/types/aframe/tests/package.json b/types/aframe/tests/package.json new file mode 100755 index 0000000000..8d50073828 --- /dev/null +++ b/types/aframe/tests/package.json @@ -0,0 +1,19 @@ +{ + "scripts": { + "build": "tsc && tsc -p ../tsconfig.json", + "dev": "npm run build && npm run test", + "test": "intern-runner --config=./intern" + }, + "dependencies": { + "@types/three": "^0.84.8", + "@types/tweenjs": "^0.6.27" + }, + "devDependencies": { + "@dojo/loader": "^2.0.0-beta1.1", + "aframe": "^0.5.0", + "intern": "^3.3.1", + "ts-node": "^3.0.4", + "tslint": "^3.15.1", + "typescript": "^2.3.4" + } +} diff --git a/types/aframe/tests/tests.html b/types/aframe/tests/tests.html new file mode 100644 index 0000000000..113631453e --- /dev/null +++ b/types/aframe/tests/tests.html @@ -0,0 +1,8 @@ + + + + + + Unit Tests + + diff --git a/types/aframe/tests/tsconfig.json b/types/aframe/tests/tsconfig.json new file mode 100644 index 0000000000..92f9994342 --- /dev/null +++ b/types/aframe/tests/tsconfig.json @@ -0,0 +1,22 @@ +{ + "version": "2.3.2", + "extends": "../tsconfig.json", + "compilerOptions": { + "module": "umd", + "moduleResolution": "node", + "removeComments": false, + "sourceMap": true, + "types": [ "intern" ], + "noEmit": false, + "paths": { + "aframe": [ ".." ] + } + }, + "files": [ + "aframe.ts", + "component.ts", + "entity.ts", + "intern.ts", + "../index.d.ts" + ] +} diff --git a/types/aframe/tsconfig.json b/types/aframe/tsconfig.json new file mode 100755 index 0000000000..82e7e6792b --- /dev/null +++ b/types/aframe/tsconfig.json @@ -0,0 +1,26 @@ +{ + "version": "2.3.2", + "compilerOptions": { + "baseUrl": "..", + "lib": [ + "es5", + "dom", + "es2015.iterable", + "es2015.promise" + ], + "module": "commonjs", + "noImplicitAny": true, + "noImplicitThis": true, + "removeComments": false, + "sourceMap": true, + "strictNullChecks": true, + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "typeRoots": [ "../" ], + "types": [ ] + }, + "files": [ + "index.d.ts", + "aframe-tests.ts" + ] +} diff --git a/types/aframe/tslint.json b/types/aframe/tslint.json new file mode 100644 index 0000000000..724f3870ca --- /dev/null +++ b/types/aframe/tslint.json @@ -0,0 +1,5 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + } +} From 485696c0db2a2e694501eb0764afb568411b6fac Mon Sep 17 00:00:00 2001 From: Paul Shannon Date: Thu, 15 Jun 2017 21:13:34 -0700 Subject: [PATCH 2/2] making requested changes --- types/aframe/README.md | 28 -------------- types/aframe/UNUSED_FILES.txt | 1 - types/aframe/aframe-tests.ts | 5 +++ types/aframe/index.d.ts | 10 +++-- types/aframe/tests/aframe.ts | 37 ------------------ types/aframe/tests/component.ts | 45 ---------------------- types/aframe/tests/entity.ts | 66 -------------------------------- types/aframe/tests/intern.ts | 26 ------------- types/aframe/tests/package.json | 19 --------- types/aframe/tests/tests.html | 8 ---- types/aframe/tests/tsconfig.json | 22 ----------- types/aframe/tsconfig.json | 1 - types/aframe/tslint.json | 4 +- 13 files changed, 13 insertions(+), 259 deletions(-) delete mode 100644 types/aframe/README.md delete mode 100644 types/aframe/UNUSED_FILES.txt delete mode 100644 types/aframe/tests/aframe.ts delete mode 100644 types/aframe/tests/component.ts delete mode 100644 types/aframe/tests/entity.ts delete mode 100755 types/aframe/tests/intern.ts delete mode 100755 types/aframe/tests/package.json delete mode 100644 types/aframe/tests/tests.html delete mode 100644 types/aframe/tests/tsconfig.json diff --git a/types/aframe/README.md b/types/aframe/README.md deleted file mode 100644 index 0bceeb7487..0000000000 --- a/types/aframe/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# aframe typings - -### build - -From the `tests` directory run: - -* `npm i` -* `npm run build` - -This will build the both `aframe-tests.ts` and the `tests` directory using the provided typings. - -Note: If you do not want to install node modules then a basic test can be ran by compiling `aframe-tests.ts` -by typing `tsc`. - -### test - -* build using the instructions above -* open `tests/tests.html` in a browser - -The testing framework uses [intern](https://theintern.github.io/) to run tests. The tests ensure that typings are -actually written against real aframe constructs by exercising the code and validating assertions. Intern also supports -local execution using Selenium by running `npm run test`. - - -## Contributing - -These typings cover much of the core of A-Frame. Help is welcomed to provide typings for A-Frame bundled components and -additional intern tests <3 diff --git a/types/aframe/UNUSED_FILES.txt b/types/aframe/UNUSED_FILES.txt deleted file mode 100644 index 3598c3003f..0000000000 --- a/types/aframe/UNUSED_FILES.txt +++ /dev/null @@ -1 +0,0 @@ -tests \ No newline at end of file diff --git a/types/aframe/aframe-tests.ts b/types/aframe/aframe-tests.ts index 190489b346..439d314f4a 100644 --- a/types/aframe/aframe-tests.ts +++ b/types/aframe/aframe-tests.ts @@ -1,3 +1,8 @@ +// Global + +const threeCamera = new AFRAME.THREE.Camera(); +AFRAME.TWEEN.Easing; + // Entity const entity = document.createElement('a-entity'); entity.emit('rotate'); diff --git a/types/aframe/index.d.ts b/types/aframe/index.d.ts index b1a763e7dd..f1f5cd7a20 100644 --- a/types/aframe/index.d.ts +++ b/types/aframe/index.d.ts @@ -4,8 +4,12 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 +/** + * Extended tests available at https://github.com/devpaul/aframe-typings.git + */ + /// -/// +/// // Globals declare var AFRAME: AFrame.AFrameGlobal; @@ -43,8 +47,8 @@ declare namespace AFrame { schema: SchemaUtils; shaders: { [ key: string ]: ShaderDescriptor }; systems: { [key: string]: System }; - THREE: any; // TODO THREE - TWEEN: any; // TODO TWEEN + THREE: typeof THREE; + TWEEN: typeof TWEEN; utils: Utils; version: string; } diff --git a/types/aframe/tests/aframe.ts b/types/aframe/tests/aframe.ts deleted file mode 100644 index 37d839e4df..0000000000 --- a/types/aframe/tests/aframe.ts +++ /dev/null @@ -1,37 +0,0 @@ -import 'aframe'; -import { describe, it } from 'intern!bdd'; -import * as expect from 'intern/chai!expect'; - -/** - * A-Frame exposes its public interface through the window.AFRAME browser global. - */ -describe('aframe global', () => { - describe('AFRAME', () => { - it('has the expected shape', () => { - expect(AFRAME).to.exist; - - expect(AFRAME.components).to.exist; - expect(AFRAME.geometries).to.exist; - expect(AFRAME.primitives).to.exist; - expect(AFRAME.schema).to.exist; - expect(AFRAME.shaders).to.exist; - expect(AFRAME.systems).to.exist; - expect(AFRAME.THREE).to.exist; - expect(AFRAME.TWEEN).to.exist; - expect(AFRAME.utils).to.exist; - expect(AFRAME.version).to.exist; - - expect(AFRAME.AEntity).to.be.a('function'); - expect(AFRAME.ANode).to.be.a('function'); - expect(AFRAME.AScene).to.be.a('function'); - expect(AFRAME.registerComponent).to.be.a('function'); - expect(AFRAME.registerElement).to.be.a('function'); - expect(AFRAME.registerGeometry).to.be.a('function'); - expect(AFRAME.registerPrimitive).to.be.a('function'); - }); - }); - - it('hasNativeWebVRImplementation', () => { - expect(window).to.have.property('hasNativeWebVRImplementation'); - }); -}); diff --git a/types/aframe/tests/component.ts b/types/aframe/tests/component.ts deleted file mode 100644 index 0c7390e0c7..0000000000 --- a/types/aframe/tests/component.ts +++ /dev/null @@ -1,45 +0,0 @@ -import 'aframe'; -import { describe, beforeEach, afterEach, it } from 'intern!bdd'; -import * as expect from 'intern/chai!expect'; - -describe('components', () => { - let Component: AFrame.ComponentConstructor; - - afterEach(() => { - if (Component) { - delete AFRAME.components[Component.prototype.name]; - } - }); - - describe('basic component', () => { - beforeEach(() => { - Component = AFRAME.registerComponent('test', {}); - }); - - it('has the expected shape', () => { - expect(Component).to.exist; - const entity: AFrame.Entity = document.createElement('a-entity'); - const component = new Component(entity, 'test', 'test'); - - expect(component.attrName).to.exist; - expect(component.el).to.exist; - expect(component.id).to.exist; - expect(component.name).to.exist; - expect(component.schema).to.exist; - - expect(component.data).to.not.exist; - expect(component.dependencies).to.not.exist; - expect(component.multiple).to.not.exist; - expect(component.tick).to.not.exist; - - expect(component.init).to.be.a('function'); - expect(component.update).to.be.a('function'); - expect(component.remove).to.be.a('function'); - expect(component.play).to.be.a('function'); - expect(component.pause).to.be.a('function'); - expect(component.remove).to.be.a('function'); - expect(component.flushToDOM).to.be.a('function'); - expect(component.extendSchema).to.be.a('function'); - }); - }); -}); diff --git a/types/aframe/tests/entity.ts b/types/aframe/tests/entity.ts deleted file mode 100644 index 68cf591633..0000000000 --- a/types/aframe/tests/entity.ts +++ /dev/null @@ -1,66 +0,0 @@ -import 'aframe'; -import { describe, beforeEach, afterEach, it } from 'intern!bdd'; -import * as expect from 'intern/chai!expect'; - -function assertStaticShape(entity: AFrame.Entity) { - expect(entity).to.exist; - - expect(entity.components).to.exist; - expect(entity.object3D).to.exist; - expect(entity.object3DMap).to.exist; - - expect(entity.addState).to.be.a('function'); - expect(entity.emit).to.be.a('function'); - expect(entity.flushToDOM).to.be.a('function'); - expect(entity.getAttribute).to.be.a('function'); - expect(entity.getComputedAttribute).to.be.a('function'); - expect(entity.getObject3D).to.be.a('function'); - expect(entity.getOrCreateObject3D).to.be.a('function'); - expect(entity.is).to.be.a('function'); - expect(entity.pause).to.be.a('function'); - expect(entity.play).to.be.a('function'); - expect(entity.setAttribute).to.be.a('function'); - expect(entity.setObject3D).to.be.a('function'); - expect(entity.removeAttribute).to.be.a('function'); - expect(entity.removeObject3D).to.be.a('function'); - expect(entity.removeState).to.be.a('function'); -} - -describe('entity', () => { - let entity: AFrame.Entity; - - beforeEach(() => { - entity = document.createElement('a-entity'); - }); - - describe('entity is not attached to a scene', () => { - it('has the expected shape', () => { - assertStaticShape(entity); - expect(entity.sceneEl).to.not.exist; - }); - }); - - describe('entity is part of a scene', () => { - let scene: AFrame.Scene; - - beforeEach(() => { - return new Promise(function (resolve) { - scene = document.createElement('a-scene'); - scene.addEventListener('renderstart', function () { - resolve(); - }); - document.body.appendChild(scene); - scene.appendChild(entity); - }); - }); - - afterEach(() => { - document.body.innerHTML = ''; - }); - - it('has the expected shape', () => { - assertStaticShape(entity); - expect(entity.sceneEl).to.exist; - }); - }); -}); diff --git a/types/aframe/tests/intern.ts b/types/aframe/tests/intern.ts deleted file mode 100755 index f81395f8ec..0000000000 --- a/types/aframe/tests/intern.ts +++ /dev/null @@ -1,26 +0,0 @@ -export const loaders = { - 'host-browser': 'node_modules/@dojo/loader/loader.js' -}; - -export const environments = [ - { browserName: 'chrome' } -]; - -// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader -// can be used here -export const loaderOptions = { - // Packages that should be registered with the loader in each testing environment - packages: [ - { name: 'tests', location: '.' }, - { name: 'aframe', location: `./node_modules/aframe/dist`, main: 'aframe-master.js' } - ] -}; - -export const suites = [ - 'tests/aframe', - 'tests/component', - 'tests/entity' -]; - -// A regular expression matching URLs to files that should not be included in code coverage analysis -export const excludeInstrumentation = /(?:node_modules|tests)[\/\\]/; diff --git a/types/aframe/tests/package.json b/types/aframe/tests/package.json deleted file mode 100755 index 8d50073828..0000000000 --- a/types/aframe/tests/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "scripts": { - "build": "tsc && tsc -p ../tsconfig.json", - "dev": "npm run build && npm run test", - "test": "intern-runner --config=./intern" - }, - "dependencies": { - "@types/three": "^0.84.8", - "@types/tweenjs": "^0.6.27" - }, - "devDependencies": { - "@dojo/loader": "^2.0.0-beta1.1", - "aframe": "^0.5.0", - "intern": "^3.3.1", - "ts-node": "^3.0.4", - "tslint": "^3.15.1", - "typescript": "^2.3.4" - } -} diff --git a/types/aframe/tests/tests.html b/types/aframe/tests/tests.html deleted file mode 100644 index 113631453e..0000000000 --- a/types/aframe/tests/tests.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - Unit Tests - - diff --git a/types/aframe/tests/tsconfig.json b/types/aframe/tests/tsconfig.json deleted file mode 100644 index 92f9994342..0000000000 --- a/types/aframe/tests/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "2.3.2", - "extends": "../tsconfig.json", - "compilerOptions": { - "module": "umd", - "moduleResolution": "node", - "removeComments": false, - "sourceMap": true, - "types": [ "intern" ], - "noEmit": false, - "paths": { - "aframe": [ ".." ] - } - }, - "files": [ - "aframe.ts", - "component.ts", - "entity.ts", - "intern.ts", - "../index.d.ts" - ] -} diff --git a/types/aframe/tsconfig.json b/types/aframe/tsconfig.json index 82e7e6792b..9488fe8297 100755 --- a/types/aframe/tsconfig.json +++ b/types/aframe/tsconfig.json @@ -1,5 +1,4 @@ { - "version": "2.3.2", "compilerOptions": { "baseUrl": "..", "lib": [ diff --git a/types/aframe/tslint.json b/types/aframe/tslint.json index 724f3870ca..d88586e5bd 100644 --- a/types/aframe/tslint.json +++ b/types/aframe/tslint.json @@ -1,5 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - } + "extends": "dtslint/dt.json" }