💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] 除了单元测试,某些项目可能还会用到端对端测试(由于用的少,这里就简单列一下常用的第三方框架,感兴趣的可以自行了解) 1. `CasperJS` 2. `Protractor` 3. `Nightwatch.js` 4. `TestCafe` 5. `CodeceptJS` 6. Sinon [Using Mocks for Testing in JavaScript With Jest (stackabuse.com)](https://stackabuse.com/using-mocks-for-testing-in-javascript-with-jes/#settingupjestinanodejsapplication) # HTML-parser on Node.js You can also take a look at x-ray:[https://github.com/lapwinglabs/x-ray](https://github.com/lapwinglabs/x-ray) [playwright · GitHub Topics](https://github.com/topics/playwright) If you want to build [DOM](http://en.wikipedia.org/wiki/Document_Object_Model)you can use[jsdom](https://github.com/tmpvar/jsdom). There's also [cheerio](https://github.com/MatthewMueller/cheerio), it has the [jQuery](http://jquery.com/) interface and it's a lot faster than older versions of jsdom, although these days they are similar in performance. You might wanna have a look at [htmlparser2](https://github.com/fb55/htmlparser2), which is a streaming parser, and according to its benchmark, it seems to be faster than others, and no DOM by default. It can also produce a DOM, as it is also bundled with a handler that creates a DOM. This is the parser that is used by cheerio. [parse5](https://github.com/inikulin/parse5)also looks like a good solution. It's fairly active (11 days since the last commit as of this update), WHATWG-compliant, and is used in [jsdom](https://github.com/tmpvar/jsdom),[Angular](https://github.com/angular/angular), and [Polymer](https://github.com/Polymer/polymer). And if you want to parse HTML for[web scraping](http://en.wikipedia.org/wiki/Web_scraping), you can use [YQL](http://developer.yahoo.com/yql/). There is a [node module](https://github.com/derek/node-yql) for it. YQL I think would be the best solution if your HTML is from a[static](http://en.wikipedia.org/wiki/Static_web_page)website, since you are relying on a service, not your own code and processing power. Though note that it won't work if the page is disallowed by the robot.txt of the website, YQL won't work with it. If the website you're trying to scrape is [dynamic](http://en.wikipedia.org/wiki/Dynamic_web_page) then you should be using a [headless browser](https://en.wikipedia.org/wiki/Headless_browser) like [phantomjs](http://phantomjs.org/). Also have a look at [casperjs](http://casperjs.org/), if you're considering phantomjs. And you can control casperjs from node with [SpookyJS](https://github.com/WaterfallEngineering/SpookyJS). Beside phantomjs there's [zombiejs](http://zombie.labnotes.org/). Unlike phantomjs that cannot be embedded in nodejs, zombiejs is just a node module. There's a [nettuts+ toturial](http://net.tutsplus.com/tutorials/javascript-ajax/web-scraping-with-node-js/)for the latter solutions.