【发布时间】:2020-12-02 18:21:23
【问题描述】:
我一直在对一些代码进行单元测试,但似乎不知从何而来,我收到有关未知文件扩展名的错误(之前,我收到有关无法识别某些类型的错误)。
这是我的 package.json:
{
"name": "cgt-core-engine-mv",
"description": "API container for other CGT plugins",
"version": "1.01.03",
"author": "CG-Tespy",
"repository": {
"type": "git",
"url": "https://github.com/CG-Tespy/CGT_CoreEngine_MV"
},
"scripts": {
"build": "tsc & (rollup -c)",
"test": "mocha -r ts-node/register Test/**/*.ts"
},
"dependencies": {},
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.0",
"@types/sinon": "^9.0.4",
"chai": "^4.2.0",
"mocha": "^8.0.1",
"rollup": "^2.00.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-pluginutils": "^2.8.2",
"sinon": "^9.0.2",
"ts-node": "^8.10.2",
"typescript": "^3.9.6"
},
"type": "module"
}
这是我的 tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "CommonJS",
"esModuleInterop": true,
"sourceMap": false,
"downlevelIteration": true,
},
"include": ["_MainSource/**/*", "Tests/**/*", "@typeDefs/**/*"],
}
我真的不知道这是从哪里来的。我有一个单独的项目,我能够很好地对事物进行单元测试,并且没有给我任何错误。它的 package.json:
{
"name": "unittesting",
"version": "1.0.0",
"description": "For practicing unit-testing",
"main": "main.js",
"scripts": {
"test": "mocha -r ts-node/register test/**/*.ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/mocha": "^8.0.0",
"chai": "^4.2.0",
"mocha": "^8.0.1",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
},
"type": "module"
}
它的 tsconfig:
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"esModuleInterop": true,
},
"include": ["src/**/*", "tests/**/*"],
}
什么可能导致此问题?我已经尝试了here 的建议,但没有奏效(即使在查看了链接的 Github 问题之后)。
【问题讨论】:
-
如果您将
type: module放在package.json 中,您会遇到同样的问题吗? -
@rags2riches 这样做之后,我收到一个错误,提示我无法在模块外使用 import 语句。
-
@Tepsy 同上。这基本上是一个永无止境的循环,我不明白为什么。我还在调查。
-
@ViliamJobko 不,它没有
标签: typescript unit-testing visual-studio-code