Error: Jest: Got error running globalSetup ../#shelf/jest-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error - mongodb

I'm following the documentation on jestjs.io. When I try to run a test I get this error:
Error: Jest: Got error running globalSetup - /home/.../node_modules/#shelf/jest-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error!
This happened both when I've used typescript and also when I created a simple app using javascript instead:
package.json:
{
"name": "mongojest",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"#shelf/jest-mongodb": "^3.0.1"
},
"scripts": {
"test": "jest"
},
"dependencies": {
"jest": "^28.1.0"
}
}
jest.config.js:
module.exports = {
coverageProvider: "v8",
"preset": "#shelf/jest-mongodb"
};
I haven't made any changes other than the minimum installs to get it running.

I got around this issue by installing Ubuntu 20.04. I was using the newer Ubuntu 22.04 and it seem to have caused some issues.

I installed typescript in my project. That was enough to run. Follow my configuration files
//package.json
{
"name": "research-with-programmers-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --passWithNoTests --silent --noStackTrace --runInBand",
"test:verbose": "jest --passWithNoTests --runInBand",
"test:unit": "yarn test -- --watch -c jest-unit-config.ts",
"test:integration": "yarn test -- --watch -c jest-integration-config.ts",
"test:staged": "yarn test -- --findRelatedTest",
"test:ci": "yarn test -- --coverage"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#shelf/jest-mongodb": "^4.1.0",
"#types/bcrypt": "^5.0.0",
"#types/jest": "^28.1.8",
"#types/mongodb": "^4.0.7",
"#types/node": "^18.7.13",
"#types/validator": "^13.7.6",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"git-commit-msg-linter": "^4.1.3",
"husky": "^8.0.1",
"jest": "^29.0.1",
"lint-staged": "^13.0.3",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.8.2"
},
"dependencies": {
"bcrypt": "^5.0.1",
"mongodb": "^4.10.0",
"validator": "^13.7.0"
}
}
//jest-config.ts
export default {
roots: ['<rootDir>/src'],
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!<rootDir>/src/**/protocols/*.ts',
'!<rootDir>/src/**/*protocols.ts',
'!<rootDir>/src/**/models/*.ts',
'!<rootDir>/src/**/usecases/*.ts',
'!<rootDir>/src/**/index.ts'
],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
testEnvironment: 'node',
preset: '#shelf/jest-mongodb',
transform: {
'.+\\.ts$': 'ts-jest'
}
}
// jest-mongodb-config.ts
export default {
mongodbMemoryServerOptions: {
instance: {
dbName: 'jest'
},
binary: {
version: '4.0.3',
skipMD5: true
},
autoStart: false
}
}

Related

Importing jQuery with Parcel JS

I am trying to create a library using parceljs and after npm run watch, i am getting
Uncaught ReferenceError: require is not defined
package.json
{
"name": "social-tagger",
"version": "1.0.0",
"description": "",
"source": "src/index.ts",
"main": "dist/main.js",
"module": "dist/module.js",
"scripts": {
"watch": "parcel watch",
"build": "parcel build"
},
"author": "",
"license": "ISC",
"dependencies": {
"#yaireo/tagify": "^4.12.0",
"jquery": "^3.6.0"
},
"devDependencies": {
"#parcel/packager-ts": "^2.6.2",
"#parcel/transformer-typescript-types": "^2.6.2",
"#types/jquery": "^3.5.14",
"parcel": "^2.6.2",
"typescript": "^4.7.4"
}
}
src/social.ts
import * as jQuery from 'jquery';
How to properly import jQuery
Output From Inspect Element
Added Targets to package.json
package.json
{
"name": "social-tagger",
"version": "1.0.0",
"description": "",
"source": "src/index.ts",
"main": "dist/main.js",
"module": "dist/module.js",
"scripts": {
"watch": "parcel watch",
"build": "parcel build"
},
"author": "",
"license": "ISC",
"dependencies": {
"#yaireo/tagify": "^4.12.0",
"jquery": "^3.6.0"
},
"devDependencies": {
"#parcel/packager-ts": "^2.6.2",
"#parcel/transformer-typescript-types": "^2.6.2",
"#types/jquery": "^3.5.14",
"parcel": "^2.6.2",
"typescript": "^4.7.4"
},
"targets":{
"main": {
"includeNodeModules": true
}
}
}
Create a file named jquery.ts
jquery.ts
import jquery from "jquery";
export default ((window as any).jQuery = jquery);
Dont import jquery instead import from jquery.ts
social.ts
import './jquery';

Host React App with Parcel Build on gh pages?

Can someone please help me figure out how to host my app on gh pages. All I am getting when I deploy it is the ReadMe file.
My app is deployed using parcel build, and it works perfectly fine when ran locally.
This is my package.js:
{
"name": "myflix-client",
"version": "1.0.0",
"description": "",
"default": "src/index.html",
"dependencies": {
"#fortawesome/free-regular-svg-icons": "^5.15.4",
"#fortawesome/free-solid-svg-icons": "^5.15.4",
"#fortawesome/react-fontawesome": "^0.1.16",
"axios": "^0.24.0",
"font-awesome": "^4.7.0",
"js-tokens": "^4.0.0",
"loose-envify": "^1.4.0",
"moment": "^2.29.1",
"object-assign": "^4.1.1",
"parcel": "^2.0.0-rc.0",
"parcel-bundler": "^1.12.5",
"prop-types": "^15.8.0",
"react": "^17.0.2",
"react-bootstrap": "^2.1.2",
"react-dom": "^17.0.2",
"react-paginate": "^8.1.0",
"react-redux": "^7.2.6",
"react-router-dom": "^5.2.0",
"redux": "^4.1.2",
"redux-devtools-extension": "^2.13.9",
"scheduler": "^0.20.2",
"uuid": "^8.3.2"
},
"scripts": {
"start": "parcel src/index.html",
"build": "parcel-build src/index.html",
"test": "echo \"Error: no test specified\" && exit 1",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/johannesvw3/myFlix-client-react.git"
},
"author": "Deepthi Rao",
"license": "ISC",
"bugs": {
"url": "https://github.com/johannesvw3/myFlix-client-react"
},
"homepage": "https://github.com/johannesvw3/myFlix-client-react",
"devDependencies": {
"#parcel/transformer-image": "^2.0.0-rc.0",
"#parcel/transformer-sass": "^2.0.0-rc.0",
"gh-pages": "^3.2.3"
}
}
Thanks!

Babel : As of v7.0.0-beta.55, we've removed Babel's Stage presets

I'm trying to create a build for this project but I've faced this issue with babel :
Error: [BABEL] D:\open-source\React\react-notify\src\components\Notification\Action\index.js:
As of v7.0.0-beta.55, we've removed Babel's Stage presets.
Please consider reading our blog post on this decision at
https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets
for more details. TL;DR is that it's more beneficial in the
long run to explicitly add which proposals to use.
For a more automatic migration, we have updated babel-upgrade,
https://github.com/babel/babel-upgrade to do this for you with
"npx babel-upgrade".
If you want the same configuration as before:
{
"plugins": [
// Stage 2
["#babel/plugin-proposal-decorators", { "legacy": true }],
"#babel/plugin-proposal-function-sent",
"#babel/plugin-proposal-export-namespace-from",
"#babel/plugin-proposal-numeric-separator",
"#babel/plugin-proposal-throw-expressions",
// Stage 3
"#babel/plugin-syntax-dynamic-import",
"#babel/plugin-syntax-import-meta",
["#babel/plugin-proposal-class-properties", { "loose": false }],
"#babel/plugin-proposal-json-strings"
]
}
If you're using the same configuration across many separate projects,
keep in mind that you can also create your own custom presets with
whichever plugins and presets you're looking to use.
module.exports = function() {
return {
plugins: [
require("#babel/plugin-syntax-dynamic-import"),
[require("#babel/plugin-proposal-decorators"), { "legacy": true }],
[require("#babel/plugin-proposal-class-properties"), { "loose": false }],
],
presets: [
// ...
],
};
};
my package.json:
{
"name": "react-notify",
"version": "0.1.0",
"description": "Push notification component for React",
"main": "dist/index.js",
"module": "dist/index.js",
"babel": {
"presets": [
"#babel/react",
"#babel/env",
"#babel/stage-2"
]
},
"license": "MIT",
"dependencies": {
"#babel/runtime": "^7.11.2",
"#fortawesome/fontawesome-svg-core": "^1.2.30",
"#fortawesome/free-brands-svg-icons": "^5.14.0",
"#fortawesome/free-solid-svg-icons": "^5.14.0",
"#fortawesome/react-fontawesome": "^0.1.11",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"styled-components": "^5.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "SET NODE_ENV=production && rm -rf dist && mkdir dist && npx babel src/components/Notification --out-dir dist --copy-files",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"resolutions": {
"styled-components": "^5"
},
"devDependencies": {
"#babel/cli": "^7.11.6",
"#babel/core": "^7.11.6",
"#babel/preset-env": "^7.11.5",
"#babel/preset-react": "^7.10.4",
"#babel/preset-stage-2": "^7.8.3",
"#storybook/addon-actions": "^6.0.21",
"#storybook/addon-essentials": "^6.0.21",
"#storybook/addon-links": "^6.0.21",
"#storybook/node-logger": "^6.0.21",
"#storybook/preset-create-react-app": "^3.1.4",
"#storybook/react": "^6.0.21",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.4",
"enzyme-to-json": "^3.5.0",
"react-addons-test-utils": "^15.6.2",
"react-is": "^16.13.1",
"react-test-renderer": "^16.13.1"
}
}
I tried :
npx babel-upgrade
But still facing the same issue.
My Action/index.js:
import React, { useContext } from "react"
import PropTypes from "prop-types"
import { Button, Wrapper } from "./Styled"
import Context from "../context"
const Action = ({ name, onClick }) => {
const { type } = useContext(Context);
if (!(typeof onClick === "function")) {
throw new Error("Action event should be a function")
}
return (< Wrapper >
<Button type={type} onClick={onClick}>{name}</Button>
</Wrapper >)
}
Action.propTypes = {
name: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired
}
export default Action
Why I faced this issue?
Babel had stopped supporting Stage Presets in the configuration. Read this article.
How to solve the issue?
By running this command :
npx babel-upgrade
Then:
npm install
This will replace the legacy dependencies with :
"devDependencies": {
"#babel/cli": "^7.11.6",
"#babel/core": "^7.11.6",
"#babel/plugin-proposal-class-properties": "^7.0.0",
"#babel/plugin-proposal-decorators": "^7.0.0",
"#babel/plugin-proposal-export-namespace-from": "^7.0.0",
"#babel/plugin-proposal-function-sent": "^7.0.0",
"#babel/plugin-proposal-json-strings": "^7.0.0",
"#babel/plugin-proposal-numeric-separator": "^7.0.0",
"#babel/plugin-proposal-throw-expressions": "^7.0.0",
"#babel/plugin-syntax-dynamic-import": "^7.0.0",
"#babel/plugin-syntax-import-meta": "^7.0.0",
}
And replace the configuration with :
"babel": {
"presets": [
"#babel/react",
"#babel/env"
]
},

Electron App Not Starting after I build it

I have installed the electron-packager npm module globally and run npm run build to build my application.
When I do this, the app seems to build properly and it outputs an application (see picture). However, the date/time on the application is from over a month ago. Furthermore, when I open the application, it simply presents a blank screen.
Below, please find my package.json and accompanying pictures.
{
"name": "turtlecreeklane",
"version": "0.0.1",
"author": "Tanner Houghton <houta483#uchicago.edu>",
"description": "An electron-vue project",
"license": "ISC",
"main": "./dist/electron/main.js",
"scripts": {
"build": "electron-packager . TCL",
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "./start_backend.sh& node .electron-vue/dev-runner.js",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": ""
},
"build": {
"productName": "turtlecreeklane",
"appId": "com.example.yourapp",
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/Icon-48"
},
"win": {
"icon": "build/icons/icon.ico"
},
"linux": {
"icon": "build/icons"
}
},
"dependencies": {
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"ejs": "^3.0.2",
"electron-unhandled": "^3.0.2",
"express": "^4.17.1",
"multer": "^1.4.2",
"path": "^0.12.7",
"pillow": "0.0.9",
"vue": "^2.5.16",
"vue-axios": "^2.1.5",
"vuex": "^3.1.3"
},
"devDependencies": {
"ajv": "^6.5.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"cfonts": "^2.1.2",
"chalk": "^2.4.1",
"copy-webpack-plugin": "^4.5.1",
"cross-env": "^5.1.6",
"css-loader": "^0.28.11",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^2.0.4",
"electron-builder": "^20.19.2",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
"electron-packager": "^14.2.1",
"electron-prebuilt": "^1.4.13",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "0.4.0",
"multispinner": "^0.2.1",
"node-loader": "^0.6.0",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1",
"vue-html-loader": "^1.2.4",
"vue-loader": "^15.2.4",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.16",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4",
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.3"
}
}
Picture showing that the project seems to be built but the date if for over a month ago...
Picture showing that the app looks blank after it is opened
Thanks,
Tanner

facing error TS2339: Property 'then' does not exist on type 'StepDefinitions & Hooks'

facing error TS2339: Property 'then' does not exist on type 'StepDefinitions & Hooks'.
when I am trying to run tsc -w
tried all the solution which I know but nothing is working out.
Feature file:
Feature: Login creation for Amazon AWS
Scenario: Successful creation of Login
Given User navigate to Home Page
When User enter email and other details
Then Login is created sucessfully
Package.json
{
"name": "package.json",
"version": "1.0.0",
"description": "package",
"main": "index.js",
"dependencies": {
"#types/node": "^12.7.5"
},
"scripts": {
"test": "./node_modules/.bin/cucumber-js -p default"
},
"compilerOptions": {
"target": "es6"
},
"devDependencies": {
"#types/chai": "^4.2.2",
"#types/cucumber": "^4.0.7",
"chai": "^4.2.0",
"cucumber": "^5.1.0",
"cucumber-pretty": "^1.5.2",
"cucumber-tsflow": "^3.2.0",
"exceljs": "^2.0.1",
"protractor": "^5.4.2",
"protractor-cucumber-framework": "^6.1.3",
"ts-node": "^8.3.0",
"typescript": "^3.6.3",
"xlsx": "^0.15.1"
},
"author": "Bharani",
"license": "ISC"
}
Step Definition file:
import { Given, When, Then } from "cucumber"
Given("User navigate to Home Page", function(){
console.log("hafd");
});
When("User enter email and other details",function(){
console.log("dfhagsdf");
});
Then("Login is created sucessfully",function(){
console.log("dhfhd");
});
Package.json:
{
"name": "package.json",
"version": "1.0.0",
"description": "package",
"main": "index.js",
"dependencies": {
"#types/node": "^12.7.5"
},
"scripts": {
"test": "./node_modules/.bin/cucumber-js -p default"
},
"compilerOptions": {
"target": "es6"
},
"devDependencies": {
"#types/chai": "^4.2.2",
"#types/cucumber": "^4.0.7",
"chai": "^4.2.0",
"cucumber": "^5.1.0",
"cucumber-pretty": "^1.5.2",
"cucumber-tsflow": "^3.2.0",
"exceljs": "^2.0.1",
"protractor": "^5.4.2",
"protractor-cucumber-framework": "^6.1.3",
"ts-node": "^8.3.0",
"typescript": "^3.6.3",
"xlsx": "^0.15.1"
},
"author": "Bharani",
"license": "ISC"
}
Error in console:
'''[16:44:58] Starting compilation in watch mode...
POM_TS_CUCUMBER/Featurefile/stepdefinition/Steps.ts:3:32 - error
TS2339: Property 'then' does not exist on type 'StepDefinitions &
Hooks'.
3 defineSupportCode(({Given,When,then}) =>{
~~~~
[16:45:04] Found 1 error. Watching for file changes. '''
You have written Then in feature file which is not from the cucumber library. Try writing then statement again from cucumber library and try again.