Problems with running test with --config - nightwatch.js

I'm currently trying to run a nightwatch test by passing in the conf.js file via the --config tag. The conf.js file is in the directory below where the nightwatch command will be run from. Looks like this
.
└── project root
├── tests
├── bin
└── selenium.jar
└── chromedriver
└── other
└── nightwatch.conf.js
├── custom-assertions
Relative part of the conf.js file looks like this
"src_folders" : [
"../tests"
],
"custom_commands_path" : "custom-commands",
"selenium": {
"start_process": true,
"server_path": "../bin/selenium.jar",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver" : "../bin/chromedriver"
}
},
The problem i'm having is if I try to run the test from project root with
nightwatch --config other/nightwatch.conf.js --verbose
I get the following error
Starting selenium server... There was an error while starting the
Selenium server:
Error: Unable to access jarfile ../bin/selenium.jar
However, if I run it from the other folder and don't specify the --config (because i'm running it from the folder where the conf lives) it works fine. So i'm thinking i'm doing something wrong but I don't know what. Anyone any ideas?
Other info -
The directory set up has to be the way outlined above
The tests have to be ran from the project root
The project root is in /home dir (I don't think it's a permissions
issues but it could be I guess)
Nightwatch is installed globally
Let me know if I can provide any other info.
Thanks
Ally
edit
changed 'run project from root' to 'run project from project root'

You need to adjust your config code to run based on the directory of the package.json or gulpfile.js. Try adjusting your code to the following
"src_folders" : [
"tests"
],
"custom_commands_path" : "custom-commands",
"selenium": {
"start_process": true,
"server_path": "bin/selenium.jar",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver" : "bin/chromedriver"
}
},

Related

How to debug application made by AWS SAM in VSCode?

Summary
I made Go application by AWS SAM. Now I try to debug this sample application in VSCode, but It fails so I want to know how to correctly debug it.
Tried
toggl-slack
├── Makefile
├── README.md
├── dlv
├── samconfig.toml
├── hello-world
│ ├── main.go
│ └── main_test.go
└── template.yaml
I put following command on console for debug.
cd toggl-slack
go get -u github.com/go-delve/delve/cmd/dlv
GOARCH=amd64 GOOS=linux go build -o ./dlv github.com/go-delve/delve/cmd/dlv
GOARCH=amd64 GOOS=linux go build -gcflags='-N -l' -o hello-world/hello-world ./hello-world
sam local start-api -d 5986 --debugger-path . --debug-args="-delveAPI=2"
curl http://127.0.0.1:3000/hello
As result, debug does not work and console shows error message.
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2019-12-28 21:23:17 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Invoking hello-world (go1.x)
Fetching lambci/lambda:go1.x Docker container image......
Mounting /Users/jpskgc/toggl-slack/hello-world as /var/task:ro,delegated inside runtime container
Could not create config directory: mkdir /home/sbx_user1051: permission denied.API server listening at: [::]:5986
2019-12-28T12:23:46Z info layer=debugger launching process with args: [/var/task/hello-world]
2019-12-28T12:23:47Z warning layer=debugger reading debug_info: could not find abstract origin (0x13ed31) of inlined call at 0xfab50
Codes
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to Lambda container",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath": "",
"port": 5986,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
}
]
}
Other code is same as default sample application for AWS SAM.
Full Source Code is here:
https://github.com/jpskgc/toggl-slack/tree/0db02109685ce89f17ed64fdaadd5261e5f61512
The reading debug_info: could not find abstract origin line tells us that the compile flags got scrambled and the debug info was not actually included. What we need is:
GOOS=linux GOARCH=amd64 go build -gcflags "all=-N -l" -o hello-world/hello-world ./hello-world
Second, VSCode should tell you this, but in launch.json, "request": "launch", is now "request": "attach", for mode remote giving:
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to SAM local",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "",
"port": 5986,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
}
]
}
With the above changes you should be able to attach to the debug server using VSCode (or GoLand/Vim/CLI).
Finally, the Could not create config directory: mkdir /home/sbx_user1051: permission denied. line is safe to ignore.
I am contributing this on behalf of my employer, Amazon. My contribution is licensed under the MIT license. See here for a more detailed explanation.

Go Debugging with VS Code does not work. No variables, Call Stack etc

I want to use VSCode with WSL for development.
I have problems debugging my Go applications and I don't know why. I dont see the things in the call stack, no variables and also the buttons to jumping from breakpoint to breakpoint are greyed out. My DEBUG Console log is clean, no erros (see details below) I try to follow these articles to set up my environment:
https://github.com/Microsoft/vscode-go/wiki/GOPATH-in-the-VS-Code-Go-extension
https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code
So what I do in detail:
First I tell VSCode to set my GOPATH dynamacly from the current Workspace and also seperate the GooTools Installation from my GOPATH via go.toolsGopath. My settings.json looks like this:
{
"go.inferGopath": true,
"go.toolsGopath": "/mnt/c/Users/cloudnaut/gospace/gotools",
}
So my GoTools are installed to /mnt/c/Users/cloudnaut/gospace/gotools. I have installed also the dlv debugger. Also My working directory for go is instead /mnt/c/Users/cloudnaut/gospace/go
It haves the common go project structure:
.
├── bin
├── pkg
└── src
└── github.com
└── cloudnaut
└── project1
└── main.go
Everything seems fine. Go:Install/Update Tools are installed in my separate path. And my GOPATH structure also works. I use GO:Current GOPATH it shows my the correct GOPATH i want and go install also creates the go binary from my main.go in /bin. Perfect ...
Now I want to start to debbuging. I just use a simple launch.json file directly point to my main.go
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"showLog": true,
"type": "go",
"request": "launch",
"mode": "auto",
"program": "/mnt/c/Users/cloudnaut/gospace/go/src/github.com/cloudnaut/project1/main.go",
"env": {},
"args": []
}
]
}
So and when I start now the debugging (breakpoints are set and shown under BREAKPOINTS) he creates in the folder a __debug_bin. But in my vscode debuger interface, I see no variables and stacktrace. The Problem is, I see also now errors or something. My Debug Console with the showLog: true option is nearly clean. It only contains the following lines:
API server listening at: 127.0.0.1:34477
2019-12-19T13:55:52+01:00 info layer=debugger launching process with args: [/mnt/c/Users/cloudnaut/gospace/go/src/github.com/cloudnaut/project1/__debug_bin]
Nothing else. The "step over/step info/Step out" buttons from the debugger are greyed out. I only can press pause, restart and stop.
See:
Picture VS Code Debugger Problem
I bring the solution for my own question:
The problem is that the Go dlv debugger dont works with WSL 1 because of some unsupported system calls. It only works with WSL 2, wich is included only in the Microsoft insider build.
See:
https://github.com/microsoft/vscode-go/issues/2505

Can't deploy go lang app to AWS Elastic Beanstalk

Here is how my files are organized before I zip the file.
├── app
│ ├── main.go
│ ├── Procfile
│ ├── Buildfile
│ ├── build.sh
Buildfile
make: ./build.sh
build.sh
#!/usr/bin/env bash
# Install dependencies.
go get ./...
# Build app
go build ./ -o bin/application
Procfile
web: bin/application
The error I get
[Instance: i-03f3c230e7b575431] Command failed on instance. Return code: 1 Output: (TRUNCATED)... inflating: /var/app/staging/app/main.go Unable to launch application as the source bundle does not contain a Buildfile, Procfile or an executable. Unable to launch application as the source bundle does not contain a Buildfile, Procfile or an executable. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/01_configure_application.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
More error logs
Application update failed at 2018-10-02T01:33:44Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/01_configure_application.sh failed.
Executing: /usr/bin/unzip -o -d /var/app/staging /opt/elasticbeanstalk/deploy/appsource/source_bundle
Archive: /opt/elasticbeanstalk/deploy/appsource/source_bundle
creating: /var/app/staging/app/
inflating: /var/app/staging/app/Buildfile
inflating: /var/app/staging/app/build.sh
inflating: /var/app/staging/app/Procfile
inflating: /var/app/staging/app/main.go
Unable to launch application as the source bundle does not contain a Buildfile, Procfile or an executable.
Unable to launch application as the source bundle does not contain a Buildfile, Procfile or an executable.
Incorrect application version ".01" (deployment 29). Expected version ".01" (deployment 18).
My main.go file has third-party packages. I'm using
port := os.Getenv("PORT")
if port == "" {
port = "5000"
log.Println("[-] No PORT environment variable detected. Setting to ", port)
}
like the docs say in the example app. It compiles and runes locally no problem.
As you can see in your error message:
Unable to launch application as the source bundle does not contain a Buildfile, Procfile or an executable.
Your Procfile, Buildfile and build.sh should be in the root of the project, like this:
├── app
│ ├── main.go
│ Procfile
│ Buildfile
│ build.sh

Include file from node_modules to nyc

I want to use nyc to generate code-coverage. I am building some of my projects into node_modules to use them in other projects. When writing tests I want to test the files inside node_modules and therefore I want to include files from node_modules.
Project-Example-Structure
1. foo (directory)
1.1 bar (directory)
1.1.1 node_modules (directory)
1.1.1.1 someFile.js // I want to include this!
1.1.2 foobar
1.1.2.1 foobar.js // this file works
1.1.3 .nycrc
.nycrc
{
"reporter": [
"html",
"text"
],
"all": true,
"cwd": "../",
"report-dir": "./bar/test-run/coverage",
"include": [
"./bar/**/foobar/*.js",
"./bar/**/node_modules/*.js",
]
}
Execute in terminal
nyc mocha
Explanation
nyc uses the .nycrc. cwd: change-working-directory. I want to be able to include files of parent-directory. Sadly include seems not to be able to use "../".
Inside the include-flag I am specifying which files should be included:
"./bar/foobar/foobar.js" does somehow not work.
But: "./bar/**/foobar/foobar.js" includes foorbar.js.
Expected behaiviour
someFile.js should be included. foorbar.js should be included.
Observed behaiviour
someFile.js is not included. foorbar.js is included.
Environment
MacOS Sierra
nyc 11.8.0
You have to modify your config files with
{
"include": [
"node_modules/**/<fileName>.js"
],
"excludeNodeModules": false
}

How to debug server side TypeScript code in WebStorm

Comparing this to Visual Studio Code all you need to do is allow source maps and VSCode will debug TypeScript however I can't achieve the same on WebStorm.
I can easily debug server side JavaScript in WebStorm but not TypeScript
For anyone else wrestling with debugging TypeScript in WebStorm/IDEA, I had similar frustrations as OP (possibly for different reason). My issue was simply that I didn't set the working directory to the dist folder in the node run configuration. I am running tests in Jest and assumed the working dir should be the root of my project. Set it to dist and debugging started working!
Further info...
Source .ts files in src
Typescript version: 2.0.3
File tsconfig.json:
{
"compilerOptions": {
"jsx": "react",
"module": "commonjs",
"noImplicitAny": false,
"outDir": "dist",
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,
"target": "es6",
"moduleResolution": "node"
},
"exclude": [
"node_modules",
"dist"
]
}
Jest config (in package.json):
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/ts-jest/dist/preprocessor.js",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
Run configuration...
Working directory: <project_root>/dist
Javascript file: ../node_modules/jest-cli/bin/jest.js
Application params: --runInBand
Hope it helps!
was trying to find a way to let Webstorm/Intellij to watch the TS file change and restart server in debug mode. Looks like ts-node-dev which IHMO is faster than nodemon in terms of live-reload because it shares Typescript compilation process between restarts.
npm i ts-node-dev --save-dev
Then in your Run/Debug Configuration, add a node.js config with below params:
JavaScript file ---> node_modules/ts-node-dev/lib/bin.js
Applicationi parameters ---> --respawn -- src/script/local.server.ts
Now save the config and run with Debug, you should be able to set break point as well as live reload server on any TS code change.
I wrapped up a small library for this if you happen to develop with aws lambda
https://github.com/vcfvct/ts-lambda-local-dev
Just want to add what worked for me with Webstorm 2021.1.1
I found the easiest way is to go to your package.json and right click the green triangle next to the npm script you want to run. Then select debug.
I am able to apply the breakpoints to my typescript code and it works perfectly. Coming from .Net where it was always pretty straight forward to debug, I am glad to see webstorm making it just as simple.
This is my npm script that I choose to debug.
"dev": "env-cmd -f ./config/dev.env concurrently -k -n COMPILER,NODEMON -c gray,blue \"tsc -w\" \"nodemon -w dist dist/index.js\"",
I'm using a specific version of node called ts-node.
First add in your package.json file:
"devDependencies": {
"ts-node": "8.1.0",
"typescript": "3.2.4"
},
Run npm install and the node_module/.bin/ directory will include the ts-node or ts-node.cmd required for Windows.
Obviously these versions will move. You may see inside the package.json of ts-node project which version of typescript they are using to be the closest as possible.
Then you can add breakpoints. The only downside I see is that you must define the Javascript file (which is a ts file) into the configuration, instead of just right-click + run.
If you have the xyz is not a function error, check that your tsconfig.json file doesn't have "noEmit": false,
For running WebStorm(2017.2.3) debugger around typescript sources I did:
Setup Node.js configuration:
Working directory: root/of/the/project (where located my package.json)
JavaScript file: dist/index.js
I am compiling my TypeScript with gulp-typescript, but more important the source-map files. So for compiling was used task like below:
const gulp = require('gulp');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const merge = require('merge2');
const tsProject = ts.createProject('tsconfig.json', {
declaration: true,
typescript: require('typescript'),
});
gulp.task('default', () => {
const result = gulp.src('./app/**/*.ts')
.pipe(sourcemaps.init())
.pipe(sourcemaps.identityMap()) // optional
.pipe(tsProject());
return merge([
result.js
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '../app' }))
.pipe(gulp.dest('dist')),
result.dts
.pipe(gulp.dest('dist')),
]);
});
All source TS files located in './app' folder, all compiled files located in ./dist folder. Most important source-files option sourceRoot, wrong value not bring you to ts file.
By sourcemaps.write('.', { includeContent: false, sourceRoot: '../app' } I am writing my .map files beside .js files and make reference to app folder. I no need content in .map files because it's already there (app folder).
Thanks to #Ekaterina I was able to run Node debug with Typescript.

Resources