0

I am having trouble getting an import working in a jasmine unit test that is written in typescript. Chutzpah is throwing an error on the import statement - which in js gets translated to a define

import {fakeclass} from '../src/data-analysis/fakeclass';

The error I see is:

Error: ReferenceError: Can't find variable: define

Otherwise the test gets discovered and runs fine.

I assume it has to with systemjs not being loaded by chutzpah - is there a recommended way to set this up?

here is my chutzpah.json file

{
  "Framework": "jasmine",
  "TestHarnessReferenceMode": "Normal",
  "TypeScriptModuleKind": "CommonJS",

  "Compile": {
  "Mode": "External",
  "Extensions": [ ".ts" ],
  "ExtensionsWithNoOutput": [ ".d.ts" ]

},
"References": [
{
  "Includes": [ "src/*.ts" ],
  "Excludes": [ "src/*.d.ts" ]
},
{
  "Path": "./jspm_packages/system.src.js",
  "IsTestFrameworkFile": true
},
{
  "Path": "./jspm_packages/system-polyfills.src.js",
  "IsTestFrameworkFile": true
},
{
  "Path": "./config.js",
  "IsTestFrameworkFile": true
}
],
"Tests": [
{
  "Includes": [ "*/test/*.ts" ],
  "Excludes": [ "*/test/*.d.ts" ]
}
]}
Cœur
  • 37,241
  • 25
  • 195
  • 267
MIantosca
  • 833
  • 1
  • 10
  • 33
  • You would definitely need to reference systemJS and any other libraries you need in the references section. I am planning on setting up a good sample using systemJS soon but have not had a chance though to get to it yet. – Matthew Manela May 29 '16 at 22:03
  • Thanks Mathew - took a shot at adding the systemJS files to the config file (see above) - still seeing same error – MIantosca May 30 '16 at 14:08
  • Can you give me a git repro with the attempt you did so I can test with it? – Matthew Manela Jun 01 '16 at 00:23
  • Here is a repo - https://github.com/miantosca/chutzpah-test – MIantosca Jun 02 '16 at 18:45

1 Answers1

0

I took a look at the sample you gave me and got it working by following the pattern in the Chutzpah Angular2 sample.

config.js

System.config({
  defaultJSExtensions: true,
  transpiler: "babel",
  babelOptions: {
    "optional": [
      "es7.decorators",
      "runtime"
    ]
  },
  paths: {
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },
  map: {

  }
});

chutzpah.json

{
  "Framework": "jasmine",
  "TestHarnessReferenceMode": "AMD",
  "TestHarnessLocationMode": "SettingsFileAdjacent",
  "Compile": {
    "Mode": "External",
    "Extensions": [ ".ts" ],
    "ExtensionsWithNoOutput": [ ".d.ts" ]

  },
  "References": [
    {
      "Path": "./jspm_packages/system.src.js",
      "IsTestFrameworkFile": true
    },
    {
      "Path": "./jspm_packages/system-polyfills.src.js",
      "IsTestFrameworkFile": true
    },
    {
      "Path": "./config.js",
      "IsTestFrameworkFile": true
    }

  ],
  "Tests": [
    {
      "Includes": [ "*/test/*.ts" ],
      "Excludes": [ "*/test/*.d.ts" ]
    }
  ],
   "Server": {
       "Enabled": true
    }
}
Matthew Manela
  • 16,572
  • 3
  • 64
  • 66