Strapi Cron doesn't work after migrating to version strapi-3.0.0 - api

Cron usually worked in the strapi-3.0.0-beta.20 version
but It doesn't work after migrating to version strapi-3.0.0
Strapi-3.0.0-beta.20
./config/environments/{env}/server.json
{
"host": "0.0.0.0",
"port": 1337,
"proxy": {
"enabled": false
},
"cron": {
"enabled": true
},
"admin": {
"autoOpen": false
}
}
Strapi-3.0.0
./config/server.js
module.exports = ({ env }) => ({
host: '0.0.0.0',
port: env.int('PORT', '1337'),
production: env('NODE_ENV') === 'production' ? true : false,
proxy: {
enabled: false
},
cron: {
enabled: true
},
admin: {
autoOpen: false
}
})
This is strapi code that uses the server.js
strapi/packages/strapi/lib/middlewares/cron/index.js
if (strapi.config.get('server.cron.enabled', false) === true) {
_.forEach(_.keys(strapi.config.get('functions.cron', {})), task => {
cron.scheduleJob(task, strapi.config.functions.cron[task]);
});

This is the content registered in the github issue.
Describe the bug
Incorrect information in documentation for new configuration loader
Expected behavior
There is a possibility of misunderstanding in the document regarding the cron setting.
This is a setting to activate cron (3.0.0.beta.20)
./config/environments/{env}/server.json
{
"host": "0.0.0.0",
"port": 1337,
"cron": {
"enabled": true
}
}
The documentation on how to migrate guides like this.
Migrating
Server
Your server configuration can move from ./config/environments/{env}/server.json to
./config/server.js like shown here.
Server
Available options -> cron
However, to enable cron in version 3.0.0 must do it in the middleware.js
./config/middleware.js
timeout: 100,
load: {
before: ['responseTime', 'logger', 'cors', 'responses', 'gzip'],
order: [
"Define the middlewares' load order by putting their name in this array is the right order"
],
after: ['parser', 'router']
},
settings: {
...
cron: { enabled: true }
...
}
Code snippets
After checking the code (strapi/middlewares/index.js), I learned that it should be set in middleware.
System
- Node.js version: v12.14.0
- NPM version: 6.13.6
- Strapi version: 3.0.0
- Database: mongodb
- Operating system: window, linux

Related

Error evaluating function `ceil`: argument must be a number

On OSX, after I installed all of dependencies by yarn install, The webpack bundle's output keeps showing the error Error evaluating function ceil: argument must be a number.
I have no idea why this happen but it works on my linux machine with the same package.json
Some info:
webpack: "5.56.0"
less: "^4.1.2"
less-loader: "^10.0.1"
Here is my less-loader config:
{loader: "less-loader"}
It looks like the there is a change of the default options of less based on what I've found in here
https://lesscss.org/usage/#less-options-math
The solution is adding the option for less-loader in webpack config as following:
{
loader: "less-loader",
options: {
lessOptions: {
math: 'always' // <=== add this
}
}
}
Also you should change => strictMath: false
Example (my file config-overrides.js):
const addLessLoader = require("customize-cra-less-loader");
module.exports = override(
addLessLoader({
cssLoaderOptions: {
sourceMap: true,
modules: {
localIdentName: "[hash:base64:8]",
},
},
lessLoaderOptions: {
lessOptions: {
math: "always",
modifyVars: { "#primary-color": "#2a4365" },
javascriptEnabled: true,
strictMath: false,
},
},
})
);

Is There a Problem with my Nightwatch.conf.js file?

I have been attempting to setup an automated testing framework for my job, and nodejs testing has seemed to be the best option for future scalability. Plus, I am attempting to stretch myself into new areas of QA.
I have setup my Nightwatch framework with npm install commands and manually installed the most up-to-date chrome drivers, and selenium standalone executables. I have attempted to ensure that my nightwatch.conf.js file is completely setup to run my first test with google chrome, but I get this error:
⚠ Error connecting to localhost on port 4444.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (249ms)
✖ GoogleTest
An error occurred while retrieving a new session
Error: An error occurred while retrieving a new session
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Error: An error occurred while retrieving a new session
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
SKIPPED:
- Basic Google search
Which seems to be pretty generic. As per normal Nightwatch setup, I created a root folder called 'Automation' where I stuck my bin folder for the drivers and selenium framework. Inside of the 'Automation' folder I also have my nightwatch.conf.js file that I've setup (Let me know if its more helpful if I paste its code in here). In order to run my test, I use the npx nightwatch command, but I continue to get this error.
From what I can tell it may be due to me trying to run the tests locally, but I can't think of a way that I would configure the selenium service to accept local ports other than how it's been setup.
I don't know if this is a well formatted description of the problem, so I apologize in advance if this is super vague. If there's anything else I can do to help clear it up let me know.
Thank you!
Update Conf.js File
// Autogenerated by Nightwatch
// Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/
const Services = {}; loadServices();
module.exports = {
// An array of folders (excluding subfolders) where your tests are located;
// if this is not specified, the test source must be passed as the second argument to the test runner.
src_folders: ["tests"],
// See https://nightwatchjs.org/guide/working-with-page-objects/
page_objects_path: '',
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
custom_commands_path: '',
// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions
custom_assertions_path: '',
// See https://nightwatchjs.org/guide/#external-globals
globals_path : '',
webdriver: {},
test_settings: {
default: {
disable_error_log: false,
launch_url: 'https://nightwatchjs.org',
screenshots: {
enabled: false,
path: 'screens',
on_failure: true
},
desiredCapabilities: {
browserName : 'chrome'
},
webdriver: {
start_process: true,
server_path: (Services.chromedriver ? Services.chromedriver.path : '.Automation/bin/chromedriver.exe')
}
},
safari: {
desiredCapabilities : {
browserName : 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4444,
start_process: true,
server_path: '/usr/bin/safaridriver'
}
},
firefox: {
desiredCapabilities : {
browserName : 'firefox',
alwaysMatch: {
// Enable this if you encounter unexpected SSL certificate errors in Firefox
// acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
],
}
}
},
webdriver: {
start_process: true,
port: 4444,
server_path: (Services.geckodriver ? Services.geckodriver.path : './Automation/bin/geckodriver.exe'),
cli_args: [
// very verbose geckodriver logs
// '-vv'
]
}
},
chrome: {
desiredCapabilities : {
browserName : 'chrome',
chromeOptions : {
// This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
w3c: true,
//More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
args: ['disable-gpu', 'no-sandbox', 'headless']
}
},
webdriver: {
start_process: true,
port: 9515,
server_path: (Services.chromedriver ? Services.chromedriver.path : './Automation/bin/chromedriver.exe'),
cli_args: [
// --verbose
]
}
},
//////////////////////////////////////////////////////////////////////////////////
// Configuration for when using the browserstack.com cloud service |
// |
// Please set the username and access key by setting the environment variables: |
// - BROWSERSTACK_USER |
// - BROWSERSTACK_KEY |
// .env files are supported |
//////////////////////////////////////////////////////////////////////////////////
browserstack: {
selenium: {
host: 'hub-cloud.browserstack.com',
port: 443
},
// More info on configuring capabilities can be found on:
// https://www.browserstack.com/automate/capabilities?tag=selenium-4
desiredCapabilities: {
'bstack:options' : {
local: 'false',
userName: '${BROWSERSTACK_USER}',
accessKey: '${BROWSERSTACK_KEY}',
}
},
disable_error_log: true,
webdriver: {
keep_alive: true,
start_process: false
}
},
'browserstack.chrome': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions : {
// This tells Chromedriver to run using the legacy JSONWire protocol
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
w3c: true,
args: ['disable-gpu', 'no-sandbox', 'headless']
}
}
},
'browserstack.firefox': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'firefox'
}
},
'browserstack.ie': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'IE',
browserVersion: '11.0',
'bstack:options' : {
os: 'Windows',
osVersion: '10',
local: 'false',
seleniumVersion: '3.5.2',
resolution: '1366x768'
}
}
},
//////////////////////////////////////////////////////////////////////////////////
// Configuration for when using the Selenium service, either locally or remote, |
// like Selenium Grid |
//////////////////////////////////////////////////////////////////////////////////
selenium: {
// Selenium Server is running locally and is managed by Nightwatch
selenium: {
start_process: true,
port: 4444,
server_path: (Services.seleniumServer ? Services.seleniumServer.path : './Automation/bin/selenium-server-standalone-3.141.59.jar'),
cli_args: {
'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : './Automation/bin/geckodriver.exe'),
'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : './Automation/bin/chromedriver.exe')
}
}
},
'selenium.chrome': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions : {
w3c: true,
args: ['disable-gpu', 'no-sandbox', 'headless']
}
}
},
'selenium.firefox': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
]
}
}
}
}
};
function loadServices() {
try {
Services.seleniumServer = require('selenium-server');
} catch (err) {}
try {
Services.chromedriver = require('chromedriver');
} catch (err) {}
try {
Services.geckodriver = require('geckodriver');
} catch (err) {}
}
What I will suggest is to create a create a new file for Nightwatch.conf.js and then start adding rest of the configuration from there. Below is an example which works for me:
module.exports = {
src_folders: ["tests"],
skip_testcases_on_fail: false,
page_objects_path: "pageObjects",
custom_commands_path: "./commands",
screenshots: {
enabled: true,
path: "./screenshots",
on_failure: true,
on_error: true
},
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
prefs: {
download: {
default_directory: require('path').resolve(__dirname + '/download')
}
}
},
},
webdriver: {
start_process: true,
port: 4444,
server_path: require('chromedriver').path,
}
},
test_workers: {
enabled: true,
workers: 'auto'
},
safari: {
desiredCapabilities: {
browserName: 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4445,
start_process: true,
server_path: '/usr/bin/safaridriver'
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox'
},
webdriver: {
start_process: true,
port: 4446,
server_path: require('geckodriver').path
}
}
}
}
The Nightwatch JS, chromedriver, geckodriver are installed using the npm commands. Since I am using a mac I just needed to enable the safari webdriver.
npm install nightwatch --save-dev
npm install geckodriver --save-dev
npm install chromedriver --save-dev
safaridriver --enable
This is the full repo if you want to have a look: https://github.com/alapanme/NightwatchJS
Also if you need the detailed steps how I setup Nightwatch on my machine you can refer: https://testersdock.com/nightwatch-js-installation/

Critical dependency: the request of a dependency is an expression, vue.js

My testing-app is compiling fine, except that I get this warning:
" Critical dependency: the request of a dependency is an expression"
(base) marco#pc01:~/webMatters/vueMatters/PeerJS-VueJS-Test$ npm run serve
> testproject#0.1.0 serve /home/marco/webMatters/vueMatters/PeerJS-VueJS-Test
> vue-cli-service serve
INFO Starting development server...
98% after emitting CopyPlugin
WARNING Compiled with 1 warnings
7:22:25 PM
warning in ./node_modules/peerjs/dist/peerjs.min.js
Critical dependency: the request of a dependency is an expression
App running at:
- Local: http://localhost:8080
- Network: http://ggc.world/
Note that the development build is not optimized.
To create a production build, run npm run build.
I read around that it might depend of webpack, but didn't find how to put it right.
This is webpack.config.js :
{
"mode": "development",
"output": {
"path": __dirname+'/static',
"filename": "[name].[chunkhash:8].js"
},
"module": {
"rules": [
{
"test": /\.vue$/,
"exclude": /node_modules/,
"use": "vue-loader"
},
{
"test": /\.pem$/,
"use": "file-loader"
}
]
},
node: {
__dirname: false,
__filename: false
},
resolve: {
extension: ['*', '.pem'],
},
devServer: {
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
https: true,
compress: true,
public: 'ggc.world:8080'
}
}
Any ideas about how to solve it?
The following code works for me. Edit vue.config.js and add webpack config:
configureWebpack: {
module: {
exprContextCritical: false
}
}
const webpack = require('webpack');
module.exports = {
// ... your webpack configuration ...
plugins: [
new webpack.ContextReplacementPlugin(
/\/package-name\//,
(data) => {
delete data.dependencies[0].critical;
return data;
},
),
]
}
try this one
For people coming here using CRA and having trouble with PeerJS, install react-app-rewired and use the following override config and it should work.
/* config-overrides.js */
const webpack = require('./node_modules/webpack')
module.exports = function override (config, env) {
if (!config.plugins) {
config.plugins = []
}
config.plugins.push(
new webpack.ContextReplacementPlugin(
/\/peerjs\//,
(data) => {
delete data.dependencies[0].critical
return data
}
)
)
return config
}
It seems it is an error between the library bundler (parcel) and CRA bundler (webpack), and I couldn't find any official fix on the way.

cannot read property to String of undefined [sequelize db:migrate node.js postgres]

I run
$ sequelize db:migrate,
but I get this result, with an ERROR
Loaded Configuration file "db\config\config.json".
Using environment "development".
==20190927081141-add-email-to-contacts: migrating =======
ERROR: Cannot read property 'toString' of undefined
This is my current config.json file, but I don't have any toString property in it.
//config.json
{
"development": {
"port":5432,
"username": "postgres",
"password": null,
"database": "address-bloc-dev",
"host": "127.0.0.1",
"dialect": "postgres",
"logging":false
},
"test": {
"username": "postgres",
"password": null,
"database": "address-bloc-test",
"host": "127.0.0.1",
"dialect": "postgres",
"logging": false
}
}
Here is also the add email to contacts.js file
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('Contacts', 'email',
{
email: {
type: Sequelize.STRING,
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('Contacts', 'email');
}
};
What am I doing wrong? I'm struggling in figuring it out.
Thank you
Federico
Had a similar issue with
changeColumn(), ensure that that you completely define the new data type of the column that you intend to change.
Sequelize Docs
This method changes the meta data of an attribute. It is possible to change the default value, allowance of null or the data type. Please make sure, that you are completely describing the new data type.
This error is not coming from the config.json file, but rather the 20190927081141-add-email-to-contacts. The error is from there.
EDIT:
What you are doing wrong is how you are setting the type of the email field.
You should do:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('Contacts', 'email',
{
type: Sequelize.STRING,
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('Contacts', 'email');
}
};
I have this error and the solution was to modify just a word.
the place of the error
id:{
ype: DataTypes.UUID,
defaultValue: DataTypes.UUIDV1,
primaryKey: true,
allowNull: false,
}
the solution was
id:{
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV1,
primaryKey: true,
allowNull: false,
}
just added the missing letter
follow steps below:
install sequelize-cli: npm install -g sequelize-cli
install sequelize: npm install --save sequelize
install mysql2: npm install --save mysql2
initialize sequelize: sequelize init
delete the migration and seeder directory automatically generated
create a model (e.g user model):
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('users', {
name: {
type: Datatype.STRING,
allowNull: false,
},
userRole: {
type: Datatype.INTEGER,
allowNull: false,
},
});
return User;
}
Add db.sequelize.sync({ force: true, logging: console.log }); to your server.js after db has been defined.
run your server

Protractor- chrome headless in CentOS 7

We are trying to execute Protractor tests in CentOS 7 vm in headless mode using chromedriver.
Versions:
Protractor- 5.4.0
Node - v6.14.3
cucumber-js - 4.2.1
Google Chrome version - Google Chrome 68.0.3440.84
Webdriver-manager running and showing following information
[bpmuser#bg-bpm-qa-jbpm6 ~]$ ps -eaf | grep java
root 3692 3685 5 17:19 pts/0 00:00:01 java -
Djava.security.egd=file:///dev/./urandom -Dwebdriver.chrome.driver=/usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.41 -Dwebdriver.gecko.driver=/usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.21.0 -jar /usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.14.0.jar -port 4444
protractor.conf.js:
var Cucumber = require("./node_modules/cucumber");
var { defineSupportCode } = require("./node_modules/cucumber");
var reporter = require('./node_modules/cucumber-html-reporter');
var report = require("./node_modules/cucumber-html-report");
var cucumberReportOptions = {
source: './reports/results.json',
dest: './reports/results',
name: "report_detailed.html",
title: "CDocs Automation Report",
};
var cucumberReporteroptions = {
theme: 'Bootstrap',
jsonFile: './reports/results.json',
output: './reports/results/report.html',
screenshotsDirectory: './reports/screenshots/',
storeScreenshots: true,
reportSuiteAsScenarios: true,
launchReport: false,
metadata: {
"App Version":"Angular 2.0",
"Test Environment": "QA",
"Browser": "Chrome",
"Platform": process.platform,
//"Parallel": "Scenarios",
"Scenarios" : "TestCases",
"Executed": "Local"
}
};
exports.config = {
//directConnect: true,
useAllAngular2AppRoots: true,
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: "custom",
// path relative to the current config file
frameworkPath: require.resolve('./node_modules/protractor-cucumber- framework'),
//restartBrowserBetweenSuites: true,
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ 'headless' ]
},
acceptSslCerts: true,
},
// Spec patterns are relative to this directory.
specs: ['./features/ChangeView.feature',
],
//baseURL: 'http://localhost:8080/',
onPrepare: function () {
browser.baseUrl = "http://localhost:8080/";
},
onComplete: () => {
reporter.generate(cucumberReporteroptions); //invoke cucumber-html-reporter
report
.create(cucumberReportOptions)
.then(function() {
//invoke cucumber-html-report
// creating two reports(optional) here, cucumber-html-report gives
directory already exists as cucumber-html-reporter already creates the html dir!
// suggestion- use either one of the reports based on your needs
console.log("cucumber_report.html created successfully!");
})
},
cucumberOpts: {
format: ['json:reports/results.json', 'pretty'],
require: ['./features/step_definitions/content_step_definitions.js'],
tags: true,
profile: false,
'no-source': true
}
};
However, running Protractor still does not work:
[bpmuser#bg-bpm-qa-jbpm6 bin]$ pwd
/usr/lib/node_modules/protractor/bin
[bpmuser#bg-bpm-qa-jbpm6 bin]$ ./protractor /home/bpmuser/docs/CDocsAutomation/protractor.conf.js
[18:10:33] I/launcher - Running 1 instances of WebDriver
[18:10:33] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
Its not progressing after this step. Not sure where i am doing wrong.
Try using this in your config
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--window-size=800,600" ]
}
}
hope this helps