inject is not defined - CodeceptJs and CucumberJs - intellij-idea

It's my first time using CodeceptJs and I'm struggling to run my feature file as the IDE asks me to implement steps for my scenario but this is already done, so I feel it may be searching for them somewhere other than the specified under the codecept.conf.js file?
When I run npx codeceptjs gherkin:steps or snippets on the terminal I get this message saying Could not include object Step Definition from ./step_definitions/steps.js from module '/Users/myUser/IdeaProjects/codeceptjs_webdriver/step_definitions/steps.js' The "from" argument must be of type string. Received undefined .
I then move the step_definitions folder to inside features as read that this would be the default location for these and now get an inject is not defined error, which may be the actual cause for the issue I'm getting, but not sure what to do to fix it.
I've tried on IntelliJ Ultimate, Webstorm and VSCode but get the same on all of them.
basic.feature
Feature: Business rules
In order to achieve my goals
As a persona
I want to be able to interact with a system
Scenario: do something
Given I have a defined step
steps.js
const {Given} = require('cucumber');
const {I} = inject();
Given(/^I have a defined step$/, function () {
I.amOnPage('/');
});
codecept.conf.js
exports.config = {
output: './output',
helpers: {
WebDriver: {
url: 'https:www.google.com',
browser: 'chrome'
}
},
include: {
I: './steps_file.js'
},
mocha: {},
bootstrap: null,
teardown: null,
hooks: [],
gherkin: {
features: './features/*.feature',
steps: ['./step_definitions/steps.js']
},
plugins: {
screenshotOnFail: {
enabled: true
},
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
}
},
tests: './*_test.js',
name: 'codeceptjs_webdriver'
}
package.json
{
"name": "codeceptjs_webdriver",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"codeceptjs": "^3.0.0",
"cucumber": "^5.0.1"
},
"dependencies": {
"#codeceptjs/configure": "^0.6.0"
},
"description": ""
}
IntelliJ Ultimate 2020.2
And here my Github repo
Thank you very much.

It's working now and I've come back to update it here if useful to someone else.
Was able to keep the steps under step_definitions/steps folder (not the one inside the features folder). To fix the non implemented issue had to install the wdio dependency. In order for this to take effect properly through running npm install both node_modules and package-lock.json had to be deleted to be freshly regenerated.
updated package.json
{
"name": "codeceptjs_webdriver",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "npx codeceptjs run"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {},
"dependencies": {
"#wdio/selenium-standalone-service": "^6.6.2",
"codeceptjs": "^2.6.8",
"codeceptjs-assert": "0.0.4",
"webdriverio": "6.3.6"
},
"description": ""
}
updated codecept.conf.js
exports.config = {
output: './output',
helpers: {
WebDriver: {
url: 'https://www.google.com',
browser: 'chrome'
}
},
include: {
I: './steps_file.js'
},
mocha: {},
bootstrap: null,
teardown: null,
hooks: [],
gherkin: {
features: './features/*.feature',
steps: ['./step_definitions/steps.js']
},
plugins: {
wdio: {
enabled: true,
services: ['selenium-standalone']
// additional config for service can be passed here
},
screenshotOnFail: {
enabled: true
},
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
},
tests: './*_test.js',
name: 'codeceptjs_webdriver'
}

Related

How to setup plain text env vars in Expo build?

I'm working on an expo project and trying to link environment variables for build profiles. I was trying to achieve that using eas.json but I cannot get it to work.
I have two build profiles - development and production:
{
"cli": {
"version": ">= 3.3.1"
},
"build": {
"development": {
"distribution": "internal",
"env": {
"API_URL": "https://staging-api.example.com",
"STRIPE_ENV": "test"
},
"ios": {
"resourceClass": "m1-medium"
}
},
"production": {
"env": {
"API_URL": "https://api.example.com",
"STRIPE_ENV": "production"
},
"ios": {
"resourceClass": "m1-medium"
},
"autoIncrement": true
}
},
"submit": {
"production": {
...
}
}
}
Build command:
eas build --profile development --platform ios
Based on their documentation, I sohuld be able to use process.env.API_URL but it's undefined.
Am I missing something?
Putting those values in eas.json is only ensuring that those envs will be set during the build process on EAS. To pass them to the application code you need to pass those values to the extra field in app.config.js.
process.env.API_URL will be defined when evaluating app.config.js, but in your application code, you need to access those values via expo-constants package.

Can someone help me resolve this problem? Fatal error: Unable to find local grunt

I am learning hybris and I started using smartedit. The problem is that when I run ant clean all or ant updatesystem I get this error.
Running grunt default
grunt-cli: The grunt command line interface (v1.3.2)
Fatal error: Unable to find local grunt.
If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:
https://gruntjs.com/getting-started
What have I done till now:
I have grunt-cli installed globally, and grunt installed locally. Also, I run npm install.
Here is my packege.json file:
{
"name": "name",
"version": "1.0.0",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^1.4.1",
"grunt-contrib-jshint": "^3.0.0",
"grunt-contrib-watch": "^1.1.0"
},
"dependencies": {},
"description": "desc"
}
Here is my Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['jshint']);
};
I tried a bunch of ways to resolve this problem but nothing seemed to work. Can someone help me out?

ES6/ES7 support with serverless

I have few serverless project created without using ES6/ES7 support. In our new project, i wanted to integrate this with serverless but not able to get it going.
Here is my serverless.yml file
#sls offline start --skipCacheInvalidation
service: test
provider:
name: aws
runtime: nodejs8.10 # set node.js runtime
memorySize: 1024 # set the maximum memory of the Lambdas in Megabytes
timeout: 300 # the timeout is 10 seconds (default is 6 seconds)
stage: ${opt:stage, 'dev'} #${self:provider.stage} # setting the env stage to dev, this will be visible in the routes
region: us-east-1
logRetentionInDays: 14 # Set the default RetentionInDays for a CloudWatch LogGroup
deploymentBucket:
name: api-test
# custom:
# stage: ${opt:stage, self:provider.stage}
environment: ${file(env.yml):${self:provider.stage}}
plugins:
- serverless-webpack
- serverless-offline
# serverless optimization
package:
individually: true
# serverless-webpack configuration
# Enable auto-packing of external modules
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
functions:
createCampaign:
handler: src/Campaign.CreateCampaign
name : campaign-createcampaign-${self:provider.stage} #custom lambda name instead of auto generated
description: To create campaign
events:
- http:
path: campaign
method: post
cors: true
getAllCampaign:
handler: src/Campaign.GetCampaign
name : campaign-getall-${self:provider.stage} #custom lambda name instead of auto generated
description: To retrieve all campaign
events:
- http:
path: campaign
method: get
cors: true
My campaign.js is under /src folder in my code. I tried this using https://medium.com/#kilgarenone/write-es6-es7-in-serverless-framework-using-babel-7-and-webpack-4-5bd742168e1a
My webpack config is following.
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
//entry: slsw.lib.entries,
entry: {handler : './src/Campaign.js'},
target: 'node',
// Generate sourcemaps for proper error messages
devtool: 'source-map',
// Since 'aws-sdk' is not compatible with webpack,
// we exclude all node dependencies
externals: [nodeExternals()],
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
optimization: {
// We no not want to minimize our code.
minimize: false,
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
// Run babel on all .js files and skip those in node_modules
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: __dirname,
exclude: /node_modules/,
},
],
},
};
My package.json is
{
"name": "orim-api",
"version": "1.0.0",
"description": "",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.4.4",
"#babel/core": "^7.4.4",
"#babel/preset-env": "^7.4.4",
"babel-loader": "^8.0.5",
"babel-plugin-source-map-support": "^2.0.1",
"serverless-offline": "^4.9.4",
"serverless-webpack": "^5.3.0",
"webpack": "^4.30.0",
"webpack-node-externals": "^1.7.2"
},
"dependencies": {
"dotenv": "^7.0.0",
"mongoose": "^5.5.5",
"source-map-support": "^0.5.12"
}
}
My .babelrc file is
{
"plugins": ["source-map-support", "transform-runtime"],
"presets": [
["env", { "node": "8.10" }],
"stage-3"
]
}
When i execute sls offline start --SkipCacheInvalidateion, i get following warning
WARNING in ./src/Campaign.js 5:12-29
"export 'connectToDatabase' was not found in '../db'
And it seems like webpack and babel-loader isn't transpile my entire code
From the doc, this is something you can try:
// webpack.config.js
const _ = require('lodash');
const slsw = require('serverless-webpack');
module.exports = {
...
entry: _.assign({
handler : './src/Campaign.js'
}, slsw.lib.entries),
...
};

How can I change test suite name for Botium test using botium bindings. Currenlty it is coming default name

I am using botium bindings with mocha test runner and mochawesome reporter. I want to change default test suite name coming in mochaawesome report.
I have tried by modifying botium.spec file by below commna
-didnt work
I have tried to set up test suitename in envs in botium.json file. didnt work
1) botium.spec.js
const bb = require('botium-bindings')
bb.helper.mocha().setupMochaTestSuite('Demo Test suite')
2) botium.json
{
"botium": {
"Capabilities": {
"PROJECTNAME": "Test chatbot",
"CONTAINERMODE": "watson",
"WATSON_APIKEY" : "xxx",
"WATSON_WORKSPACE_ID": "xxx",
"WATSON_URL" : "https://gateway-lon.watsonplatform.net/assistant/api",
"WATSON_COPY_WORKSPACE" : true
},
"Sources": {},
"Envs": {
"BOTIUM_TESTSUITENAME" : "Demo Test suite"
}
}
}
3) package.json
{
"name": "Botium_Test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --reporter mochawesome --reporter-options \"code=false,reportTitle=Digital CityCool,inline=true,overwrite=false\" --exit spec",
"mocha": "mocha spec"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"botium-bindings": "^2.0.10",
"botium-connector-echo": "latest",
"botium-connector-watson": "0.0.5",
"mocha": "latest",
"mochawesome": "^3.1.1"
},
"botium": {
"convodirs": [
"spec\\convo"
],
"expandConvos": true,
"expandUtterancesToConvos": false
}
}
mocha report test suite name coming as 'Botium Test Suite for Botium_Test'
I want test suite name as defined in botium.json file
Your trial #1 was pretty close. Use this in the botium.spec.js:
const bb = require('botium-bindings')
bb.helper.mocha().setupMochaTestSuite({ name: 'Demo Test suite' })

npm run script causes Windows Script Host error

I a trying to use npm to minify javascript.
This is my package.json:
{
"name": "name1",
"version": "1.0.0",
"description": "",
"scripts": {
"minifyjs": "minifyJs",
"minifycss": "minifyCss",
"minifyhtml": "minifyHtml"
},
"author": "",
"license": "ISC",
"devDependencies": {
"clean-css": "^3.4.19",
"html-minifier": "^3.0.2",
"uglify-js": "^2.7.0"
}
}
and my minifyJs script is :
var uglifyJS = require('uglify-js');
var fs = require('fs');
var result = uglifyJS.minify(['src/main1.js', 'src/main2.js'], {
compress: {
drop_console: true,
unused: true
}
});
fs.writeFileSync('dist/minifyJs.js', result.code);
When I call npm run minifyjs I get the following error:
What am I doing wrong - btw this was working on another machine.....
Can anyone help?
The entries under scripts are commands that are run by NPM. They are not simply paths to JavaScript files.
You need to tell NPM to run your JavaScript tasks using node:
...
"scripts": {
"minifyjs": "node minifyJs",
"minifycss": "node minifyCss",
"minifyhtml": "node minifyHtml"
},
...