node.js - How to resolve Typescript external dependencies with mocha and node -
i've got following files;
myclass.ts
/// <reference path="node_modules/phaser/typescript/phaser.d.ts" /> export class myclass { d: phaser.sprite; constructor() { this.d = new phaser.sprite(new phaser.game, 10, 10); } win() : boolean { return true; } } test.ts
/// <reference path="../typings/mocha/mocha.d.ts" /> import mymodule = require('../myclass'); describe('myclass', () => { var subject : mymodule.myclass; beforeeach(function () { subject = new mymodule.myclass(); }); describe('#win', () => { it('should pass', () => { var result : boolean = subject.win(); if (result !== true) { throw new error('expected true ' + result); } }); }); }); i've used tsd pull in mocha.d.ts , i'm using ts-node execute typescript in node execute mocha follows;
mocha --compilers ts:ts-node/register compilation successful, tests fail @ runtime because phaser not defined;
myclass #win 1) "before each" hook "should pass" 0 passing (47ms) 1 failing 1) myclass "before each" hook "should pass": referenceerror: phaser not defined @ new myclass (c:\users\stafford\documents\git\ts-node-test\myclass.ts:5:22) @ context.<anonymous> (c:\users\stafford\documents\git\ts-node-test\test\test.ts:8:19) @ callfn (c:\users\stafford\appdata\roaming\npm\node_modules\mocha\lib\runnable.js:286:21) @ hook.runnable.run (c:\users\stafford\appdata\roaming\npm\node_modules\mocha\lib\runnable.js:279:7) @ next (c:\users\stafford\appdata\roaming\npm\node_modules\mocha\lib\runner.js:297:10) @ immediate._onimmediate (c:\users\stafford\appdata\roaming\npm\node_modules\mocha\lib\runner.js:319:5) i thought have or similar;
import phaser = require('phaser'); but breaks compilation error phaser.d.ts;
phaser.d.ts not module.
how can such test execute via command-line?
import phaser = require('phaser');
you should create vendor.d.ts following
declare module 'phaser' { export = phaser; } this create type safe module phaser you. don't forget include phaser.d.ts : https://github.com/photonstorm/phaser/blob/v2.4.4/typescript/phaser.d.ts
more
https://basarat.gitbooks.io/typescript/content/docs/project/modules.html
Comments
Post a Comment