Karma + JSPM + Typescript - not found '.ts.js'
Asked Answered
P

1

0

Mainly just trying to get Karma+JSPM to play nice on loading the .ts files but having absolutely no luck.

I see up a discussion repo with a stripped down example.

Basically JSPM within Karma is seemingly ignoring the defaultJSExtensions: true and package level "defaultExtension": "ts" configurations when running in Karma giving the following error when attempting to load files:

$ npm test

> [email protected] test C:\examples\karma-jspm-typescript-coverage
> karma start

18 08 2016 17:29:31.937:INFO [karma]: Karma v1.2.0 server started at http://localhost:1337/
18 08 2016 17:29:31.943:INFO [launcher]: Launching browser Chrome with unlimited concurrency
18 08 2016 17:29:31.974:INFO [launcher]: Starting browser Chrome
18 08 2016 17:29:33.075:INFO [Chrome 52.0.2743 (Windows 7 0.0.0)]: Connected on socket /#jTR10wm0CWNIfrdhAAAA with id 75197348
18 08 2016 17:29:33.317:WARN [web-server]: 404: /src/app/app.spec.ts.js
Chrome 52.0.2743 (Windows 7 0.0.0) ERROR
  Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:1337/src/app/app.spec.ts.js
        Error: XHR error (404 Not Found) loading http://localhost:1337/src/app/app.spec.ts.js
        Error loading http://localhost:1337/src/app/app.spec.ts.js

npm ERR! Test failed.  See above for more details.

Note the .ts.js extension. Tried everyting from karma-typescript-proprocessor to loading via a different JSPM config than what would be ran with live.

Trying to keep it so there's no need to manage the .js compiled files and only work with the .ts files. The development server and bundling/build are fully functional - this testing and coverage piece is my last hurdle.

Please let me know if there any kind of direction you can give me!

Perm answered 18/8, 2016 at 22:49 Comment(0)
P
1

package level "defaultExtension": "ts" does not apply because karma is running in the top-level directory, one level above src directory which contains config.js with

baseURL: '.'

If I duplicate app package config there with src prepended to it, like this:

  packages: {
    "src/app": {
      "main": "app",
      "defaultExtension": "ts",
      "meta": {
        "*.ts": {
          "loader": "ts"
        }
      }
    },
    "app": {
      "main": "app",
      "defaultExtension": "ts",
      "meta": {
        "*.ts": {
          "loader": "ts"
        }
      }
    }
  },

I'm able to get one step further. I'm now getting

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:9876/jspm_packages/github/frankwallis/[email protected]

which indicates to me that karma-jspm plugin is unable to serve source files at URLs where SystemJS expects them to be

Photophilous answered 19/8, 2016 at 18:14 Comment(1)
You are a genius! Added that and a proxy to the karma configuration. proxies : { "/src" : "/base/src", "/jspm_packages" : "/base/src/jspm_packages" }, Changes have been updated in the github project.Perm

© 2022 - 2024 — McMap. All rights reserved.