简体   繁体   English

如何将jasmine与服务器端打字稿项目一起使用?

[英]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.

相关问题 我可以使用服务器端Javascript在Razor中对视图进行编码吗? - Can I use server-side Javascript to code views in Razor? 如何使用jQuery克隆窗口服务器端? - How can I clone a window server-side using jQuery? 如何使用 HTTPOnly 访问服务器端的凭据? - How can I access the credentials on the server-side with HTTPOnly? 每当变量在服务器端更改其值时,如何使用socket.io将数据发送到客户端? - How can I use socket.io to emit data to client-side whenever a variable change its values in server-side? 让Jasmine在服务器端运行 - Getting Jasmine to run on the server-side 如何在Angular 2中使用服务器端渲染? - How to use server-side rendering in Angular 2? 我可以在服务器端使用某些客户端Javascript API吗? - Can I use certain client-side Javascript APIs server-side? 503 服务不可用响应。 如何使用 Heroku 使用服务器端代码中继 API? - 503 Service Unavailable response. How can I use Heroku to relay API's using server-side code? 我可以在 ES6 中使用服务器端节点 js 并且仍然不使用 bable - Can I use server-side node js with ES6 and still without using bable 如何将服务器端处理添加到NodeJS React项目 - How to add server-side processing to a NodeJS React project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM