0

I got mocha working with typescript when executing "npm test". However Chutzpah refuse to recognize any tests.

My chutzpah.json contains:

{
"Framework": "mocha",
   "EnableTracing": true,
   "TraceFilePath": "./trace.log",
   "Compile": {
      "Extensions": [ ".ts" ],
      "ExtensionsWithNoOutput": [ ".d.ts" ],
      "Executable": "compile.bat",
      "UseSourceMaps": true
   },
   "References": [
      {
         "Includes": [ "*/src/*.ts" ],
         "Excludes": [ "*/src/*.d.ts" ]
      }
   ],
   "Tests": [
      {
         "Includes": [ "*/test/*.ts" ],
         "Excludes": [ "*/test/*.d.ts" ]
      }
   ]
}

The structure of the project: enter image description here

Project settings: enter image description here

The code.ts file:

class StringBaseThh {
   vowels: string;
   constructor(public content: string) {
      this.vowels = "aeiou";
      console.log("Called woolf");
   }

}

class StringPlusThh extends StringBaseThh {
   vowels: string;
   constructor(public content: string) {
      super(content);
   }

   countVowels() {
      var count = 0;
      for (var i = 0; i < this.content.length; i++) {
         if (this.vowels.indexOf(this.content[i]) > -1) {
            count++;
         }
      }
      return count;
   }
}
export { StringBaseThh, StringPlusThh };

The code.test.ts file:

/// <reference path="../../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../../node_modules/@types/chai/index.d.ts" />
/// <reference path="../src/code.ts" />
import 'mocha';
import { StringBaseThh } from '../src/code';
import * as assert from 'chai';
describe("my test", () => {
   it("hello", () => {
      let cb = new StringBaseThh("hello");
      assert.expect(cb.vowels).to.equal("aeiou");
   });
});

The package.json file:

{
  "name": "chutzpahtestingmocha",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha -r ts-node/register TypeScript/**/*.test.ts"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/chai": "^4.1.3",
    "@types/mocha": "^5.2.0",
    "chai": "^4.1.2",
    "mocha": "^5.1.1",
    "ts-node": "^6.0.3",
    "typescript": "^2.8.3"
  }
}

Output in error stream: devenv.exe Information: 0 : Time:14:03:55.0059414; Thread:13; Message:Chutzpah run finished with 0 passed, 0 failed and 0 errors

And finally the compile.bat file:

@echo off %appdata%\npm\tsc.cmd src/code.ts TypeScript/test/code.test.ts --sourcemap --declaration

0 Answers0