アプリがホストされているすべての環境でテストを展開して実行できるように、すべてのテストを webpack でパックしています。タイプスクリプトファイルを処理します。tsc が js にトランスパイルしたテスト ファイルを実行すると、同じ動作が得られます。これがスタックトレースです。どんな助けでも大歓迎です。
λ npm run cm:test:build
npm info it worked if it ends with ok
npm info using npm@3.10.6
npm info using node@v6.5.0
npm info lifecycle cs-card@1.0.0~precm:test:build: cs-card@1.0.0
> cs-card@1.0.0 precm:test:build C:\Users\wmunt\Dropbox\cs-framework\projects\card
> tsc
npm info lifecycle cs-card@1.0.0~cm:test:build: cs-card@1.0.0
> cs-card@1.0.0 cm:test:build C:\Users\wmunt\Dropbox\cs-framework\projects\card
> webpack --config test/webpack.config.js
ts-loader: Using typescript@1.8.10 and C:\Users\wmunt\Dropbox\cs-framework\projects\card\tsconfig.json
Hash: a9dae0564433ba4614d5
Version: webpack 1.13.2
Time: 3577ms
Asset Size Chunks Chunk Names
all.specs.js 6.11 kB 0 [emitted] main
+ 6 hidden modules
npm info lifecycle cs-card@1.0.0~postcm:test:build: cs-card@1.0.0
npm info ok
C:\Users\wmunt\Dropbox\cs-framework\projects\card (master) (cs-card@1.0.0){hg}
λ mocha test/all.specs.js
C:\Users\wmunt\Dropbox\cs-framework\projects\card\node_modules\cs-core\src\user.ts:3
import { Iuuid } from "./contracts/uuid";
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\wmunt\Dropbox\cs-framework\projects\card\node_modules\cs-core\index.js:23:17)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:176:19)
at __webpack_require__ (C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:20:30)
at Object.<anonymous> (C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:95:18)
at __webpack_require__ (C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:20:30)
at Object.<anonymous> (C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:49:21)
at __webpack_require__ (C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:20:30)
at C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:40:18
at Object.<anonymous> (C:\Users\wmunt\Dropbox\cs-framework\projects\card\test\all.specs.js:43:10)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at C:\Users\wmunt\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:219:27
at Array.forEach (native)
at Mocha.loadFiles (C:\Users\wmunt\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:216:14)
at Mocha.run (C:\Users\wmunt\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:468:10)
at Object.<anonymous> (C:\Users\wmunt\AppData\Roaming\npm\node_modules\mocha\bin\_mocha:403:18)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
使用したwebpackファイル
"use strict";
var path = require("path");
var fs = require("fs");
var webpack_1 = require("webpack");
var nodeModules = {};
fs.readdirSync("node_modules")
.filter(function (x) {
return [".bin"].indexOf(x) === -1;
})
.forEach(function (mod) {
nodeModules[mod] = "commonjs " + mod;
});
var wepackConfig = {
entry: path.resolve(__dirname, "../src/components/card/server/models/card.model.spec.ts"),
target: "node",
output: {
path: path.resolve(__dirname),
filename: "all.specs.js",
},
externals: nodeModules,
resolve: {
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],
},
module: {
loaders: [
{ test: /\.ts$/, loaders: ["ts-loader"] }
]
},
plugins: [
new webpack_1.DefinePlugin({
Promise: require("es6-promise").Promise
})
]
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = wepackConfig;
//# sourceMappingURL=webpack.config.js.map
と私の tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": true,
"sourceMap": true,
"rootDir": "./",
"declaration": false
},
"exclude": [
"node_modules",
".vscode",
"report",
"dist",
"output"]
}