Currently I am using Jest with puppeteer and I want combine that with MongoDB, is it possible to do that?
Here is my package.json look like:
{
"name": "testing",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"jest": {
"preset": "jest-puppeteer",
"testMatch": [
"**/tests/**/*.test.js"
],
"testTimeout": 80000,
"verbose": true
}
}
and my jest-puppeteer.config.js looks like this
module.exports = {
launch: {
defaultViewport: {
width: 1420,
height: 1080,
},
devtools: false,
headless: process.env.HEADLESS !== 'false',
slowMo: process.env.SLOWMO ? process.env.SLOWMO : 0,
},
};
Now I want to add mongoDB connection to the project with some predefined config something like this.
module.exports = {
mongodbMemoryServerOptions: {
binary: {
version: '4.0.3',
skipMD5: true
},
autoStart: false,
instance: {}
}
};
How do I combine puppeteer and mongoDB?
Related
I have used AWS SAM to initialize a typescript lambda project which I am editing in VSCode on Windows 10. I have also setup debug points in the typescript code and this is my launch.json
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"invokeTarget": {
"target": "template",
"logicalId": "HelloWorldFunction",
"templatePath": "${workspaceFolder}/lambda-app/template.yaml"
},
"lambda": {
"runtime": "nodejs14.x"
},
"sam": {
"containerBuild": false,
"skipNewImageCheck": false
},
"api": {
"httpMethod": "get"
},
"name": "templatestyle"
},
{
"type": "aws-sam",
"request": "direct-invoke",
"invokeTarget": {
"target": "code",
"lambdaHandler": "app.lambdaHandler",
"projectRoot": "${workspaceFolder}/lambda-app/hello-world"
},
"lambda": {
"runtime": "nodejs14.x",
"payload": {
"json": {
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
}
},
"sam": {
"containerBuild": false,
"skipNewImageCheck": false
},
"api": {
"httpMethod": "get"
},
"name": "basic"
}
]
}
This is my tsconfig.json
{
"compilerOptions": {
"target": "es2020",
"strict": true,
"preserveConstEnums": true,
"noEmit": true,
"sourceMap": true,
"module":"es2015",
"moduleResolution":"node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
},
"include": ["*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
This is the code in app.ts
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
/**
*
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
* #param {Object} event - API Gateway Lambda Proxy Input Format
*
* Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
* #returns {Object} object - API Gateway Lambda Proxy Output Format
*
*/
export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
let response: APIGatewayProxyResult;
try {
response = {
statusCode: 200,
body: JSON.stringify({
message: 'hello world',
}),
};
} catch (err) {
console.log(err);
response = {
statusCode: 500,
body: JSON.stringify({
message: 'some error happened',
}),
};
}
return response;
};
When I select either of the debug configurations above, the break point only attaches in a file that is not part of what I created. It stops without a breakpoint on the first line below, which is seems to be in the path \var\runtime\index.js
Where did this file come from? Docker perhaps?. Also, why is it stopping here in this file and not in the breakpoint I put on my app.ts?
This is the result I get in the debug console, and the breakpoints I have set are not hit. How do I fix this?
By default the debugger will break on the first line of code. There is a switch to disable this. I don't see the command you are using for local invoke. I was able to get it to break on my source code by using the following:
sam local invoke <function logical id> --event events/event.json -d <port>
Function logical id is the name of your function in template.yml and port is the debug port to use. I used 9999. The command I used was
sam local invoke HelloWorldFunction --event events/event.json -d 9999
Unable to change email configuration. I specify the settings according to the instructions.
Restarted the server.
Removed cache and node_modules
In any case, the default plugin configuration is used.
node v14.18.2
strapi 4.1.5
{
"name": "strapi-test",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"#strapi/plugin-i18n": "4.1.5",
"#strapi/plugin-users-permissions": "4.1.5",
"#strapi/provider-email-nodemailer": "^4.1.5",
"#strapi/strapi": "4.1.5",
"sqlite3": "5.0.2"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "87e9d8e3-8c82-4c8e-8de4-990c2b729be4"
},
"engines": {
"node": ">=12.x.x <=16.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
SOLUTION https://github.com/strapi/strapi/issues/12919#issuecomment-1075954840
in case anyone looking for the answer for this.
like derick says, in strapi v4 the provider and providerOptions need to be wrapped inside config.
like this
module.exports = ({ env }) => ({
// ...
email: {
config: {
provider: 'nodemailer',
providerOptions: {
host: env('SMTP_HOST', 'smtp.gmail.com'),
port: env('SMTP_PORT', 465),
auth: {
user: env('SMTP_USERNAME', 'email#gmail.com'),
pass: env('SMTP_PASSWORD', 'password'),
},
},
settings: {
defaultFrom: 'email#gmail.com',
defaultReplyTo: 'email#gmail.com',
},
},
},
// ...
});
I generated a local plugin and created an article model using:
"pluginOptions": {
"i18n": {
"localized": true
}
},
inside his article.settings.json file, in order to make some specific fields translatables using the Internationalization(I18N) plugin
Problem is, while running the command:
strapi develop --watch-admin
I end up having the following errors:
error Something went wrong in the model "Article" with the attribute "localizations"
error TypeError: Cannot read property "uid" of undefined
Removing the "pluginOptions" instead, gives my local plugin running without any translatable field or articles__translations pivot that should be generated into my mysql database
"pluginOptions" is the very same parameter that gets generated into the model settings creating a collection type using the Content-Types Builder, but I can't have it to work while using it for a local plugin.
Here is my article.settings.json:
plugins/blog/models/article.settings.json
{
"kind": "collectionType",
"collectionName": "articles",
"info": {
"name": "article"
},
"options": {
"draftAndPublish": false,
"timestamps": true,
"populateCreatorFields": true,
"increments": true,
"comment": ""
},
"pluginOptions": {
"i18n": {
"localized": true
}
},
"attributes": {
"title": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "string",
"required": true,
"maxLength": 255,
"minLength": 3
},
"slug": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "uid",
"targetField": "title",
"required": true
},
"featured": {
"pluginOptions": {
"i18n": {
"localized": false
}
},
"type": "boolean",
"default": false
},
"published_date": {
"pluginOptions": {
"i18n": {
"localized": false
}
},
"type": "datetime"
},
}
}
You can use the content-type-builder plugin as a workaround. You would not create the content type under the content-types folder but create it programmatically.
As an example of a very simple tag content type:
{
"singularName": "tag",
"pluralName": "tags",
"displayName": "tag",
"description": "",
"draftAndPublish": false,
"pluginOptions": {
"i18n": {
"localized": true
}
},
"attributes": {
"label": {
"type": "string",
"pluginOptions": {
"i18n": {
"localized": true
}
},
"unique": true
}
}
}
Note, this schema of the json is a bit different from the ones in plugin/server/content-types.
Then you can create the content type programmatically like this:
import { Strapi } from "#strapi/strapi";
import tag from "../content-types/tag.json";
import page from "../content-types/page.json";
export default ({ strapi }: { strapi: Strapi }) => ({
async createContentComponent() {
if (!tag) return null;
try {
const components: any = [];
const contentType = await strapi
.plugin("content-type-builder")
.services["content-types"].createContentType({
contentType: tag,
components,
});
return contentType;
} catch (e) {
console.log("error", e);
return null;
}
},
});
This is exactly how the admin creates content types using the content builder UI.
And it works using the pluginOptions.i18n.localized: true.
One approach would be to do this, e.g., on the bootstrap phase of the plugin. Here you could also check whether or not the contents are created or not.
As a bonus, you can also create components that otherwise would not work.
Hope that helps.
Links:
Create components programmatically in a plugin: https://github.com/strapi/strapi-plugin-seo/blob/main/server/services/seo.js
Create content types:
https://github.com/strapi/strapi/blob/88caa92f878a068926255dd482180202f53fcdcc/packages/core/content-type-builder/server/controllers/content-types.js#L48
EDIT:
You could also keep the original schema and use this fn to transform it - at least for now as long as the other approach is not working:
https://github.com/strapi/strapi/blob/1eab2fb08c7a4d3d40a5a7ff3b2f137ce0afcf8a/packages/core/content-type-builder/server/services/content-types.js#L37
I am working on variant management using shell. I got 'getService' of undefined error in FLP. After adding below libraries, It worked.
Index.html
<script>
window["sap-ushell-config"] = {
defaultRenderer : "fiori2",
renderers: {
fiori2: {
componentData: {
config: {
search: "hidden"
}
}
}
},
applications: {
"OrderTracking-display": {
additionalInformation: "SAPUI5.Component=orders",
applicationType: "URL",
url: ".",
title: "Order Tracking"
}
}
};
</script>
<script src="/sap/public/bc/ui5_ui5/resources/sap/ushell_abap/bootstrap/abap.js" id="sap-ushell-bootstrap"></script>
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ushell, sap.collaboration, sap.m, sap.ui.commons,
sap.ui.layout, sap.ui.ux3"
data-sap-ui-theme="sap_belize"
data-sap-ui-bindingSyntax="complex"
data-sap-ui-compatVersion="edge"
data-sap-ui-resourceroots='{"orders": "."}'
data-sap-ui-frameOptions="trusted">
manifest.json
"sap.ui5": {
"rootView": {
"viewName": "orders.view.App",
"type": "XML",
"async": true,
"id": "app"
},
"dependencies": {
"minUI5Version": "1.42.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.f": {},
"sap.ushell": {},
"sap.collaboration": {
"lazy": true
}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "orders.i18n.i18n"
}
},
"": {
"dataSource": "mainService",
"preload": true
}
},
"services": {
"ShellUIService": {
"factoryName": "sap.ushell.ui5service.ShellUIService",
"lazy": false,
"settings": {
"setHierarchy": "auto",
"setTitle": "auto"
}
}
},
But I couldn't find ui5service.ShellUIService under sap.ushell. Also popups & date pickers is not working. How to make both sap.ushell.ui5service &
sap.ushell.services libraries work.
Below are the errors I get
Error -1
Error -2
There is no 'ui5service' under 'ushell'
sap.ushell
The index.html file is used to run an app from the WebIDE in test mode during development. A local launchpad called a Sandbox is created to run the app but not all services from launchpad (cloud or abap) are available.
The libraries that the app needs must be defined in the javascript files where they are needed.
I am curious how one would interact with Windows Authentication using React.js.
We have a little internal portal we are trying to set up, we already have predefined users groups and users that are in them. We are looking for a way to get those Authenticated credentials to the view using React.js. There are a couple of good links on how to get started with Reactjs.net but I don't see any tutorials on passing credentials to Reactjs.
Any suggested reading? Tutorials or maybe you know yourself and can provide direction?
enter link description here
I've found this really cool tutorial!
It says:
Here’s a minimal setup for React and Webpack based on what we did in this article. Now that you understand the steps, you can copy-paste this to your heart’s content.
package.json
Note: agentkeepalive is only needed for fixing a Windows authentication error with Hot Module Replacement.
{
"name": "ReactWebPackMVC5",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"dev": "webpack-dev-server –open –hot"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"agentkeepalive": "^3.5.1",
"babel-loader": "^8.0.2",
"react": "^16.5.0",
"react-dom": "^16.5.0",
"webpack": "^4.18.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
}
}
webpack.config.js
Again, agentkeepalive is only needed for fixing a Windows authentication error with Hot Module Replacement. The same is true for the agent and onProxyRes properties.
const path = require("path"); const agent = require("agentkeepalive")
module.exports = { mode: "development", entry: "./Scripts/react/app.js", //or app.jsx output: { path: path.resolve(__dirname, "./Scripts/react/dist"), filename: "bundle.js", publicPath: "Scripts/react/dist" }, resolve: { extensions: ["*", ".js", ".jsx"] }, module: { rules: [ { test: /\.(js|jsx)/, exclude: /node_modules/, use: { loader: "babel-loader", options: { “presets”: [“#babel/preset-env”, “#babel/preset-react”] } } } ] }, devServer: { proxy: { "*": { target: "http://localhost:59829", changeOrigin: true, agent: new agent({ maxSockets: 100, keepAlive: true, maxFreeSockets: 10, keepAliveMsecs: 100000, timeout: 6000000, keepAliveTimeout: 90000 // free socket keepalive for 90 seconds }), onProxyRes: (proxyRes) => { var key = "www-authenticate"; proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(","); }, }, port: 8080, host: "0.0.0.0", hot: true, }, } };