I am trying to organize a new typescript project that has unit tests, also written in TS, running in the Mocha test runner.
My project with the following directory convention:
/project/src/ for server-side code (java)
/project/test/ server's tests
/project/resources/ client-side code (typescript)
/project/test-resources/ typescript tests.
right now I have a typescript module Schema in a typescript file located at resources/many/levels/schema.ts
and I have its test, written for the mocha test runner, in a typescript file: test-resources/many/levels/schemaTest.ts
The problem is that the typescript compiler can't find the schema module using the following import syntaxes:
TC2307 Can't find module schema
schemaTest.ts (version 1):
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
/// <reference path="../../../resources/many/levels/schema.ts" />
import s = require('schema');
schemaTest.ts (version 2):
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
/// <reference path="../../../resources/many/levels/schema.ts" />
import {Schema, SchemaFactory} from 'schema';
finally, the following version compiles but leads to a runtime error since the module is not at ../../../resources/many/level but instead is located in the dist directory
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
/// <reference path="../../../resources/many/levels/schema.ts" />
import {Schema, SchemaFactory} from '../../../resources/many/levels/schema';
schema.ts:
module Schema {
export interface Schema {
getName() : string;
getColumnByIndex(index : number) : Column;
getColumnById(id : string) : Column;
getNumberOfColumns(): number;
}
export class SchemaFactory{
...
build() : Schema {...}
}
}
I am compiling both my test and src files to a single dist directory (not ideal) and hope to run tests from there.
I am compiling with the flag --module commonjs.
if it matters, I am using IntelliJ 15 / WebStorm (and using its plugings for mocha, node, and tsc)
Is my Schema module set up incorrectly? Should it be an internal/external module? Should my tests be in the same namespace?
Thanks in advance!