'Anyone has experience using NightWatch with TypeScript?
I am using NightWatch for my e2e testing and want to move towards ES6 way of writing tests. I was able to do it with Babel and it worked fine but I want to use typescript. I could not find much documentation of NightWatch with TypeScript. Found some github repositories:
- https://github.com/rkavalap/NightWatchTest
- https://github.com/DonPage/Nightwatch-Typescript-example
- https://github.com/remojansen/TypeScriptTestingExamples
But these do not contain any detailed documentation around typescript.
Any help would be appreciated!
Solution 1:[1]
I haven't tried this, but on other TS projects, I use ts-node as the interpreter.
ts-node ./node_modules/.bin/nightwatch test.ts
You can do this with @vue/cli-plugin-e2e-nightwatch
as well.
Solution 2:[2]
Try this GitHub Nightwatch TypeScript example project. It uses the @types/nightwatch npm package for the Nightwatch type definition imports including support for the page object model and works with Nightwatch 2.0. The readme file in there has links to compiled documentation for further reading beyond the source code.
Solution 3:[3]
There is no real difference using nightwatch with typescript. You can use setup somewhat similar to this:
nightwatch.ts:
var nightwatch = require('nightwatch');
import * as child_process from 'child_process';
var nightwatchOptions = {
config: './path/to/nightwatch.json',
env: 'default'
};
var httpServerProc = child_process.spawn(
'node',
[
'node_modules/http-server/bin/http-server',
'path/to/your/client_to_test',
'-p 8082'
],
{
stdio: 'inherit'
}
);
nightwatch.runner(nightwatchOptions, function(success)
{
httpServerProc.kill('SIGINT');
});
Note - here I start http-server
, you can use any other or maybe start it outside of the nightwatch testing procedure.
nightwatch.json
- is your config settings for nightwatch.
Then all you need is to transpile nightwatch.ts
as part of your solution and run resulting nightwatch.js
under nodejs as usual.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kierans |
Solution 2 | EdgeCase |
Solution 3 | Amid |