mmanela / chutzpah

Chutzpah is an open source JavaScript test runner which enables you to run unit tests using QUnit, Jasmine, Mocha and TypeScript.
http://mmanela.github.io/chutzpah/
Apache License 2.0
550 stars 142 forks source link

AMD, Chutzpah, typescript. Chutzpah test explorer not detecting jasmine tests with import statement in it. #778

Closed NareshNow closed 4 years ago

NareshNow commented 4 years ago

We are trying to figure out a approach for UI testing and felt chutzpah will be a nice option. I wrote jasmine tests using typescript and requirejs. Chutzpah is able to detect the sample tests which doesn't import any external modules. But when i try it with importing external modules to be tested, chutzpah doesn't seems to detect the tests in test explorer. This is my repo link: https://github.com/NareshNow/UItesting.git

This is my chutzpah json file:

{
  "Framework": "jasmine",
  "TestHarnessReferenceMode": "AMD",
  "TestHarnessLocationMode": "SettingsFileAdjacent",
  "AMDBaseUrl": "../Compiledmodules/Tests",
  "AMDAppDirectory": "../Compiledmodules",
  "TestFileTimeout": 600000,
  "EnableCodeCoverage": false,
  "References": [

    {
      "Path": "../Scripts/require.js",
      "IsTestFrameworkFile": true
    },
    {
      "Path": "../Scripts/AMDconfig.js",
      "IsTestFrameworkFile": true
    }
  ],
  "Compile": {
    "Mode": "External",
    "Extensions": [ ".ts" ],
    "ExtensionsWithNoOutput": [ ".d.ts" ],
    "SourceDirectory": "../Typescripts",
    "OutDirectory": "../Compiledmodules"
  },
  "Tests": [
    {
      "Path": "../Typescripts",
      "Includes": [ "*.ts" ]
    },
    {
      "Path": "../Compiledmodules",
      "Includes": ["*.js"]
    }
  ]
}

I have tried the suggestions from a lot of earlier questions on the similar issue for the last 5 days, and nothing seemed to work. It feels to me like something simple is missing. You can find the tests , chutzpah.json in the TypescripKit folder in the repo. Any help would be so greatly appreciated. Thank you!

NareshNow commented 4 years ago

Hey, any help ? still couldn't resolve the issue.

mmanela commented 4 years ago

If you run Chutzpah from the command line with the /trace command it will output a file there lists every thing Chutzpah tried to do. This will include paths it is looking for files in. This can often help show what setting might be wrong based on where it is looking incorrectly.

NareshNow commented 4 years ago

Thanks for the response. I ran it from command line and checked the trace log generated. It looks like chutzpah receives the compiled .js modules as well as the framework files but ends up saying "total 0 tests". Don't know what is missing chutzpahissue

NareshNow commented 4 years ago

Hey, I finally got it working. Didn't get time to post here. Here's what was the issue. I was targeting ES2015 in my tsconfig.json. ES2015 doesn't convert the typescript classes to a function, instead it uses class keyword itself. So, the way i accessed it in my jasmine tests was suitable for ES5 and also I was declaring variables before the describe block starts in my jasmine tests. This made chutzpah not recognize them as tests. So, Once I changed the target to ES5 and declared the variables inside the describe , chutzpah was able to detect the tests.

NareshNow commented 4 years ago

Is there any guide to set up chutzpah to work with different projects. I have a test project which tests the ts files in a main application project. So, how should the configuration settings change?