使用 import {} 时未找到 Reshaper(2017.2.2) TypeScript(2.6.1) Jasmine(2.7.0) 的规范
No specs found Reshaper(2017.2.2) TypeScript(2.6.1) Jasmine(2.7.0) when using import {}
设置:
- Visual Studio 2017
- 整形器(2017.2.2)
- TypeScript(2.6.1)
- 茉莉花(2.7.0)
问题:
- 浏览器显示带有消息 "No specs found"
的 Web 测试启动器
- 控制台错误可见:Uncaught ReferenceError: exports is not defined at referenceFile:2
- Uncaught ReferenceError: exports is not defined at Tests.js:2
其他信息:
在开发工具中点击referenceFile:2可以看到该文件的JS源代码,内容如下:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var User = (function () {
function User(name, surname) {
this._name = name;
this._surname = surname;
}
Object.defineProperty(User.prototype, "Name", {
get: function () {
return this._name;
},
enumerable: true,
configurable: true
});
Object.defineProperty(User.prototype, "Surname", {
get: function () {
return this._surname;
},
enumerable: true,
configurable: true
});
return User;
}());
exports.User = User;
//# sourceMappingURL=User.js.map
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es5"],
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
package.json
{
"name": "nodejs-console-app",
"version": "0.0.0",
"description": "NodejsConsoleApp",
"main": "app.js",
"author": {
"name": "ms"
},
"devDependencies": {
"@types/node": "^6.0.87",
"jasmine": "^2.8.0"
},
"dependencies": {
"@types/jasmine": "^2.8.2"
}
}
知道如何解决这个问题吗?
更新:
该问题是由tsconfig.json中指定的commonJs模块类型引起的。
这是许多模板建议的默认值,也是我使用最多的一个。
不幸的是,CommonJS 不能立即在浏览器中执行,它需要 packed/browserified 才能在浏览器中执行。
对于源代码,我使用 Gulp>browserify 并且一切正常。
我的期望是让 resharper 为我完成肮脏的工作,但事实并非如此。
我如何使用 resharper 来 运行 那些没有错误的测试,在我的情况下,我什至不需要打开浏览器,所以它可以 运行 在 node.
TypeScript 模块编译很重要,我使用的是 CommonJS,但浏览器不支持它,R# 也没有对此做任何事情。
在tsconfig.json > compilerOptions > module中,您可以指定以下选项之一:commonjs, amd, system, umd, es6.
使用 R#,您可以而且应该使用 es6
设置:
- Visual Studio 2017
- 整形器(2017.2.2)
- TypeScript(2.6.1)
- 茉莉花(2.7.0)
问题:
- 浏览器显示带有消息 "No specs found" 的 Web 测试启动器
- 控制台错误可见:Uncaught ReferenceError: exports is not defined at referenceFile:2
- Uncaught ReferenceError: exports is not defined at Tests.js:2
其他信息:
在开发工具中点击referenceFile:2可以看到该文件的JS源代码,内容如下:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var User = (function () {
function User(name, surname) {
this._name = name;
this._surname = surname;
}
Object.defineProperty(User.prototype, "Name", {
get: function () {
return this._name;
},
enumerable: true,
configurable: true
});
Object.defineProperty(User.prototype, "Surname", {
get: function () {
return this._surname;
},
enumerable: true,
configurable: true
});
return User;
}());
exports.User = User;
//# sourceMappingURL=User.js.map
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es5"],
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
package.json
{
"name": "nodejs-console-app",
"version": "0.0.0",
"description": "NodejsConsoleApp",
"main": "app.js",
"author": {
"name": "ms"
},
"devDependencies": {
"@types/node": "^6.0.87",
"jasmine": "^2.8.0"
},
"dependencies": {
"@types/jasmine": "^2.8.2"
}
}
知道如何解决这个问题吗?
更新: 该问题是由tsconfig.json中指定的commonJs模块类型引起的。 这是许多模板建议的默认值,也是我使用最多的一个。 不幸的是,CommonJS 不能立即在浏览器中执行,它需要 packed/browserified 才能在浏览器中执行。 对于源代码,我使用 Gulp>browserify 并且一切正常。
我的期望是让 resharper 为我完成肮脏的工作,但事实并非如此。 我如何使用 resharper 来 运行 那些没有错误的测试,在我的情况下,我什至不需要打开浏览器,所以它可以 运行 在 node.
TypeScript 模块编译很重要,我使用的是 CommonJS,但浏览器不支持它,R# 也没有对此做任何事情。
在tsconfig.json > compilerOptions > module中,您可以指定以下选项之一:commonjs, amd, system, umd, es6.
使用 R#,您可以而且应该使用 es6