[英]How can I use jasmine with a server-side typescript project?
I have a project that contains modules for both the server and client of my application, which are each built using webpack. 我有一个项目,包含我的应用程序的服务器和客户端的模块,每个模块都使用webpack构建。 I'm using Karma with Jasmine to test my client (which uses Angular) and I would like to use Jasmine to test the server, which is written in typescript, too.
我正在使用Karma和Jasmine来测试我的客户端(使用Angular),我想使用Jasmine来测试服务器,这也是用打字稿编写的。
Unfortunately, the only guides that I could find online used jasmine-node (which to be untouched for the past few years) instead of jasmine-npm. 不幸的是,我在网上找到的唯一指南是使用jasmine-node(过去几年没有触及)而不是jasmine-npm。 Can anyone suggest a way that I can use Jasmine, or an alternative, for testing within my project?
任何人都可以提出一种方法,我可以使用Jasmine或替代方案在我的项目中进行测试吗?
I've tried writing a jasmine.json
file, or editing the one generated by jasmine with the init
cli command, however this doesn't seem to work with typescript files. 我已经尝试编写
jasmine.json
文件,或使用init
cli命令编辑jasmine生成的文件,但是这似乎不适用于typescript文件。
At the moment, my project's structure is like so: 目前,我的项目结构是这样的:
├── client
│ ├── karma.conf.js
│ ├── protractor.conf.js
│ ├── src
│ ├── tsconfig.json
│ └── webpack.config.js
├── server
│ ├── src
│ ├── tsconfig.json
│ └── webpack.config.js
└── node_modules
Its definately possible to use jasmine for your server side tests. 它肯定可以使用茉莉花进行服务器端测试。 Follow these steps and you'll be fine:
按照以下步骤,你会没事的:
1) In your package.json add the following dev dependencies: 1)在package.json中添加以下dev依赖项:
"jasmine": "latest",
"jasmine-core": "latest",
2) Setup your jasmine.json
so that it will include all files you want to run tests on, etc. 2)设置你的
jasmine.json
,使它包含你想要运行测试的所有文件,等等。
{
"spec_dir": "dist/dev/server/spec",
"spec_files": [
"unit/server/**/*[sS]pec.js"
],
"helpers": []
}
3) Add unit.ts
that will bootstrap your testing process: 3)添加将引导您的测试过程的
unit.ts
:
const Jasmine = require("jasmine");
let j = new Jasmine();
j.loadConfigFile("./jasmine.json");
j.configureDefaultReporter({
showColors: true
});
j.execute();
Now all you have to do is compile and run your resulting unit.js
in nodejs. 现在,您所要做的就是在nodejs中编译并运行生成的
unit.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.