简体   繁体   中英

Karma + TypeScript + jspm 404 on Spec

Trying to set up some testing in a typescript project. For some reason, though, I'm getting a 404 on the spec file (even though I can see the path is correct). Is there something I'm missing in my Karma configuration file?

module.exports = function(config) {
  config.set({
    basePath: ".",

    frameworks: ["jspm", "jasmine"],
    reporters: ["progress"],
    browsers: ["PhantomJS"],
    files: [

    ],

    proxies: {
      "/test/": "/base/test/",
      "/src/": "/base/src/"
    },

    jspm: {
      stripExtension: false,

      loadFiles: [
        "test/**/*.ts"
      ],
      serveFiles: [
        "src/**/*.ts"
      ]
    },

    preprocessors: {
      "**/*.ts": ["typescript"]
    },

    typescriptPreprocessor: {
      options: {
        noResolve: false,
        module: 'amd'
      },
      transformPath: function(path) {
        return path.replace(/\.ts$/, '.js');
      }
    }
  });
}

Or my config.js file?

System.config({
  transpiler: "typescript",
  paths: {
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },

  map: {
    "typescript": "npm:typescript@1.8.10",
    "github:jspm/nodelibs-os@0.1.0": {
      "os-browserify": "npm:os-browserify@0.1.2"
    },
    "npm:os-browserify@0.1.2": {
      "os": "github:jspm/nodelibs-os@0.1.0"
    },
    "npm:typescript@1.8.10": {
      "os": "github:jspm/nodelibs-os@0.1.0"
    }
  }
});

I had the same sort of issue except wasn't using the typescript-preprocessor as I wanted JSPM to handle that. See my question at Karma + JSPM + Typescript - not found '.ts.js' and the repo at https://github.com/Larchy/karma-jspm-typescript-coverage

Basically added a duplicate package to my jspm config to support karma serving at a higher level

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

and added proxies to karma config, as you already have:

proxies : {
    "/base/jspm_packages" : "/base/src/jspm_packages"
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM