I have a project that contains modules for both the server and client of my application, which are each built using 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.
我有一个项目,其中包含应用程序的服务器和客户机的模块,每个模块都使用webpack构建。我使用Jasmine来测试我的客户(使用角度),我想使用Jasmine来测试服务器,这也是在typescript中编写的。
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. Can anyone suggest a way that I can use Jasmine, or an alternative, for testing within my project?
不幸的是,我能在网上找到的唯一的指南是使用jasmine-node(在过去的几年中它是不受影响的),而不是jasmine-npm。谁能给我一个方法,我可以使用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.
我试过写茉莉花。json文件,或者使用init cli命令编辑jasmine生成的文件,但是这似乎不适用于打字文件。
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
1 个解决方案
#1
2
Its definately possible to use jasmine for your server side tests. Follow these steps and you'll be fine:
使用jasmine进行服务器端测试是完全可能的。遵循这些步骤,你就会好起来:
1) In your package.json add the following dev dependencies:
1)在你的包。json添加了以下开发依赖项:
"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)设置你的茉莉花。它将包含您想要运行测试的所有文件,等等。
{
"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)添加单元。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 js。
#1
2
Its definately possible to use jasmine for your server side tests. Follow these steps and you'll be fine:
使用jasmine进行服务器端测试是完全可能的。遵循这些步骤,你就会好起来:
1) In your package.json add the following dev dependencies:
1)在你的包。json添加了以下开发依赖项:
"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)设置你的茉莉花。它将包含您想要运行测试的所有文件,等等。
{
"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)添加单元。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 js。