TestsNodejs - mocha 和 babel 中的编译器弃用
TestsNodejs - compilers deprecation in mocha and babel
我正在构建 api 通过集成测试在节点上休息(Babel、chai、mocha)
我改了
--compilers js:babel-core/register
对于
--require babel-core/register
按照文档的建议:
https://github.com/mochajs/mocha/wiki/compilers-deprecation
但是当我在 mocha.opts 文件中进行此更改时,出现错误:
C:\Users\Ranulfo\Desktop\noderest>npm run test-integration
> noderest@1.0.0 test-integration C:\Users\Ranulfo\Desktop\noderest
> mocha --opts test/integration/mocha.opts test/integration/*.js
C:\Users\Ranulfo\Desktop\noderest\test\integration\helpers.js:1
(function (exports, require, module, __filename, __dirname) { import supertest f
rom 'supertest';
^^^^^^
SyntaxError: Unexpected token import
更多代码详情:
mocha.opts(test/integration/mocha):
--require test/integration/helpers.js
--reporter spec
--require babel-core/register
--slow 5000
helpers.js (test/integration/helpers.js)
import supertest from 'supertest';
import chai from 'chai';
import app from '../../app';
global.app = app;
global.request = supertest(app);
global.expect = chai.expect;
package.json
{
"name": "noderest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "babel-node ./index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"test-integration": "mocha --opts test/integration/mocha.opts test/integration/*.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-node6": "^11.0.0",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"mocha": "^5.2.0",
"supertest": "^3.1.0"
},
"dependencies": {
"express": "^4.16.3",
"sequelize": "^4.37.10",
"sqlite3": "^4.0.0"
}
}
.babelrc
{
"presets": ["env"]
}
随着版本 7 "Babel" 的更新,增加了一些配置步骤。
要调整 "bug",请执行以下步骤:
安装指定依赖:
npm install --save-dev @babel / 注册
将 "mocha.opts" 文件更改为以下行的编译器:
--compilers js: @babel / 注册
完成此操作后,您的工作流程应该标准化。 (即
注意:请注意本教程中不存在的以下依赖项。
npm install --save-dev @babel/cli
npm install --save-dev @babel/core
npm install --save-dev @babel/node
npm install --save-dev @babel/preset-env
npm install --save-dev @babel/register
辅助内容:
设置: https://babeljs.io/setup#installation
迁移: https://babeljs.io/docs/en/v7-migration
Mocha 问题 - 编译器弃用 https://github.com/mochajs/mocha/wiki/compilers-deprecation
对于那些因为使用编译器的折旧通知错误而来到这里并且没有其他 babel 问题的人。
安装依赖即可@babel/register.
并将测试脚本从 mocha --compilers js:babel-core/register 更改为 mocha --require @babel/register
这应该可以解决您关于来自 mocha 的错误通知的错误。
我正在构建 api 通过集成测试在节点上休息(Babel、chai、mocha)
我改了
--compilers js:babel-core/register
对于
--require babel-core/register
按照文档的建议: https://github.com/mochajs/mocha/wiki/compilers-deprecation
但是当我在 mocha.opts 文件中进行此更改时,出现错误:
C:\Users\Ranulfo\Desktop\noderest>npm run test-integration
> noderest@1.0.0 test-integration C:\Users\Ranulfo\Desktop\noderest
> mocha --opts test/integration/mocha.opts test/integration/*.js
C:\Users\Ranulfo\Desktop\noderest\test\integration\helpers.js:1
(function (exports, require, module, __filename, __dirname) { import supertest f
rom 'supertest';
^^^^^^
SyntaxError: Unexpected token import
更多代码详情:
mocha.opts(test/integration/mocha):
--require test/integration/helpers.js
--reporter spec
--require babel-core/register
--slow 5000
helpers.js (test/integration/helpers.js)
import supertest from 'supertest';
import chai from 'chai';
import app from '../../app';
global.app = app;
global.request = supertest(app);
global.expect = chai.expect;
package.json
{
"name": "noderest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "babel-node ./index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"test-integration": "mocha --opts test/integration/mocha.opts test/integration/*.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-node6": "^11.0.0",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"mocha": "^5.2.0",
"supertest": "^3.1.0"
},
"dependencies": {
"express": "^4.16.3",
"sequelize": "^4.37.10",
"sqlite3": "^4.0.0"
}
}
.babelrc
{
"presets": ["env"]
}
随着版本 7 "Babel" 的更新,增加了一些配置步骤。
要调整 "bug",请执行以下步骤:
安装指定依赖: npm install --save-dev @babel / 注册 将 "mocha.opts" 文件更改为以下行的编译器: --compilers js: @babel / 注册 完成此操作后,您的工作流程应该标准化。 (即
注意:请注意本教程中不存在的以下依赖项。
npm install --save-dev @babel/cli
npm install --save-dev @babel/core
npm install --save-dev @babel/node
npm install --save-dev @babel/preset-env
npm install --save-dev @babel/register
辅助内容:
设置: https://babeljs.io/setup#installation
迁移: https://babeljs.io/docs/en/v7-migration
Mocha 问题 - 编译器弃用 https://github.com/mochajs/mocha/wiki/compilers-deprecation
对于那些因为使用编译器的折旧通知错误而来到这里并且没有其他 babel 问题的人。
安装依赖即可@babel/register.
并将测试脚本从 mocha --compilers js:babel-core/register 更改为 mocha --require @babel/register
这应该可以解决您关于来自 mocha 的错误通知的错误。