Is it possible to run Cucumber.js programmatically? - javascript

I'm constructing a e2e-testing framework which utilizes cucumber. The framework is meant to be used by our customers who build web-applications with our tooling.
I'd like to ensure that the framework is functioning correctly by testing it. Unfortunately it seems that the Cucumber.js API has no means to run the program without using a CLI.
I'd much prefer to avoid running tests based on the outcome of a CLI.
So, my question, is it possible to run cucumber.js programmatically?
I can't find any documentation on this. Thanks in advance for any answers.

There seems to be some functionality to do this. It's undocumented however. There is an issue [ https://github.com/cucumber/cucumber-js/issues/1004 ] with a request to update the API Usage documentation. However, the issue dates back to 2018 and hasn't received a whole lot of attention since.

use the child_process module to spawn cucumber.

Related

Running in-browser development server [like stackblitz/codesandbox]

The Question:
How to run a live in-browser dev server?
Context
Stackblitz and CodeSandbox are two platforms that provide online IDE to develop web applications. I have a similar use case, and would need to run an in browser dev server, but there's not much that I was able to find, apart from these few observations.
Few Observations
Stackblitz, in their announcement post describe that they use, "Progressive Web App API’s to run a live dev server in-browser."
To resolve node dependencies stackblitz uses their custom npm client turbo . On the github repo page, it is described as
Express.js routes used for hydrating client-side dependencies and type definitions on StackBlitz.
There is also some module bundler involved to support live development with hot-reloading.
I suspect stackblitz runs an express.js server in the service worker, but i can't seem to understand how. I'm out of ideas here, any help would be appreciated.
I'll be honest, I have no idea but I'd like to wildly speculate.
https://nodejs.org/api/vm.html
If you're going to just be focusing on front end code, then what I would think to do is to evaluate the code in your vm with the context of whatever modules are required. React will allow you to convert the JS into html. You can update the HTML directly in the dom.
I'm not sure how much help that is, but I will leave you with this
http://www.alexrothenberg.com/2012/02/29/building-a-browser-ide.html
https://60devs.com/executing-js-code-with-nodes-vm-module.html
If you're interested in having a contributor, then I'm down to team up on your project!

javascript object2object mapper

I'm searching for a javascript mapping library I can easily integrate in my angularjs project.
I use some json objects in my javascript code that are slightly different from the json structure given by my back-end.
I have found this interesting library (https://github.com/wankdanker/node-object-mapper) that lets you specify a mapping through another object, but unfortunately it seems to work only in a nodejs environment and not in the browser.
Does anyone know a similar library working in a browser too?
Last year, I have created a port of the C# AutoMapper implementation to TypeScript / JavaScript exactly for this scenario. I have put the code at GitHub (https://b.ldmn.nl/AutoMapperTS). You can also use the library directly using the automapper-ts NPM or Bower package.
The library is almost fully documented. Furthermore, quite a lot of Jasmine unit tests are already available (code coverage is about 95%). They should provide you with some explanation of what you need.
I hope this library suits your needs. Should you have any questions and/or remarks, please don't hesitate contacting me!

What is a proper way of end-to-end (e2e) testing in Vue.js

Of cause I can use selenium-standalone with xpath to test an app. But testing SPA could be challenging sometime.
But, for example angularjs's team provides protractor for this purpose.
The reason behind protractor as I can see is that protractor waits till angularjs will be loaded and few more features:
Protractor provides some new locator strategies and functions which
are very helpful to automate the AngularJS application. Examples
include things like: waitForAngular, By.binding, By.repeater,
By.textarea, By.model, WebElement.all, WebElement.evaluate, etc.
So, the question is: Is it any tool or best practice for e2e testing in Vuejs?
UPD: feel free to post links to tutorials, example and everything cool about e2e-testing in vue.js. Thanks.
The tool you are thinking about is Nightwatch.
With this, you can do E2E testing with Vue.js.
Even better, this is bundled by default when you are using vue-cli, ready to run.
The command line to create a project with Nightwatch activated by default is vue init webpack myProjectName.
Here are small tutorials about it.
EDIT: Lately I used Webdriver.io a lot, and I must say I prefer it to Nightwatch (better documentation, reactive community with a live gitter, issues that are treated in a timely fashion, etc.)
I recommend to use https://devexpress.github.io/testcafe.
Pros:
easy install
complete test harness
javascript ES2016 with (async/await)
flexible selector system
smart assertions with retry policy
reports
See the simple tutorial here
I recommend Cypress.
single NPM dependency
video recording right out of the box
GUI that shows every step of the test.
Our docs are great: https://on.cypress.io/intro
For Vue specifically see this tutorial: https://vuejsdevelopers.com/2018/01/29/vue-js-e2e-test-hacker-news/ and if you want to do unit testing of Vue components https://github.com/bahmutov/cypress-vue-unit-test
Happy testing.
Seems to be an old question, but at the end of 2019 the best way is webdriverio:
Pros:
Large ecosystem of plugins and integrations.
Mocha, cucumber, jasmine runners.
Sync mode of test runner.
Allure reporter and others out of the box.
Chromedriver service from the box.
Easy integrate with selenoid and get cluster of browsers in docker for parallel test execution.
Integration with devtools protocol and puppeteer, can use huge amount of functions.
Integration with cloud service providers.
Appium integration out of the box.
Cons:
Have to manually write waits.
Some functions require to use promises.

Node.js unit testing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Are there any good Node.js (server-side JavaScript) unit testing frameworks currently out there?
I'm looking for something a little deeper than the provided Assert module.
I ended up using Nodeunit and am really happy with it.
I was using Expresso originally, but the fact that it runs tests in parallel caused a few problems. (For example, using database fixtures doesn't work well in this situation.)
I was also looking for a decent test framework for node and found Mocha. It is the official successor to Expresso and seems very mature.
It allows to plug-in different assertion libraries, it offers reporters for code coverage and other things (you can plug-in your own). It can run synchronously or asynchronously and it has a concise API.
I will give it a try and report back...
EDIT:
After an incredible amount of time dedicated to other projects I finally came back to a JavaScript project and had time to play around with mocha. I can seriously recommend using it. The tests read very nicely, integration with Gulp.js is great and tests run very fast. I was able to setup automatic standalone as well as in-browser (Browserify) test runs and corresponding code coverage reports in about half a day (most of the time spent on understanding how to use Browserify from Gulp.js). To me, Mocha seems a very good choice for a testing framework.
UPDATE:
I am still very convinced about Mocha. Integration with Chai allows to plugin different assertion styles. You can checkout a working setup in this GitHub project. I am using it with karma now, integrating code coverage report, automatic watchers and good integration with IntelliJ IDEA.
Personally I've stuck with Expresso, but there are a bunch of different frameworks out there, accommodating most testing styles.
Joyent has an extensive list; give that a go.
I've personally only used the assert module, but I also find myself wanting more. I've looked through many Node.js modules and popular unit testing frameworks are Nodeunit and should (which is made by the same guy as Espresso (maybe an updated name?)
Vows also looks promising.
vows is a solid unit testing library for Node.js, but the syntax is tedious.
I've written a thin abstraction called vows-fluent which makes the API chainable.
And I've written another abstraction, [vows-is] which builds on vows-fluent and exposes a BDD style syntax.
An example would be
var is = require("vows-is");
is.suite("testing is fun").batch()
.context("is testing fun?")
.topic.is("yes")
.vow.it.should.equal("yes")
.suite().run({
reporter: is.reporter
});
More examples.
I think among various testing frameworks available, Mocha is the most latest, and very simple to implement. Here is a wonderful tutorial about how to use it:
How to build and test your Rest API with Node.js, Express and Mocha
If you are familiar with QUnit, you could use node-qunit which is a sort of a node wrapper around QUnit's existing framework.
test-studio is an npm package that provides a powerful, web based front end for unit testing. It supports things like executing individual or groups of tests and stepping node-inspector into individual tests. It currently supports mocha and more frameworks will be supported in future given demand.
Read more about it here.
Disclaimer: I am the author.
Originally made for Node.js, deadunit is a JavaScript unit testing library for Node.js and the browser. Some of its unique attributes:
Easy learning curve
Can output test results on the command line (colored or plain-text) or as HTML
It prints out the actual lines of code where your assertions are, so your output makes sense even if you don't spend a lot of time writing test commentary
It has a simple count assertion that makes dealing with expected exceptions and asynchronous asserts easy
it prints out exception and any attached data they have
it'll let you know if your code is hanging (something you don't want, but usually goes unnoticed)
Has an event driven API enables streaming test results across a network, or in any way you want.
Supports testing with node-fibers
I just uploaded a project I am using to unit test Node.js with Karma and Jasmine: Narma.
Your Node.js modules get loaded into a node-webkit browser, so you can execute Node.js modules and use libraries like jQuery in the same heap.

How do you know if a JavaScript library you are using will break your code after an upgrade?

So, you are using a bunch of javascript libraries in a website. Your javascript code calls the several APIs, but every once in a while after an upgrade, one of the API changes, and your code breaks, without you knowing it.
How do you prevent this from happening?
I'm mostly interested in javascript, but any answer regarding dynamically typed languages would be valuable.
I don't think there's much you can do. You always run a risk when updating any piece of software. The best advice is to:
Read and understand documentation about upgrading
Upgrade in your test environment
TEST
Roll out live when you are happy there are no regressions
You should consider building unit tests using tools such as JsUnit and Selenium. As long as your code passes the tests, you're good to go. If some tests fail, you would quickly identify what needs to be fixed.
As an example of a suite of Selenium tests, you can check the Google Maps API Tests, which you can download and run locally in your browser.
Well there are two options:
Don't upgrade
Retest everything after you upgrade.
There is no way to guarantee that an upgrade won't break something. Even if you have something that could check the underlying API and make sure it still all lines up, you can't be certain that the underlying functionality is the same.

Categories

Resources