Saturday, September 14, 2024

how to configure microservice CDK package.json

 {

"name": "brn-cdk-packages-v2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"latest": "npm show @brn/cdk-constructs-v2 version",
"link": "for pkg in $(ls ./packages); do echo \"linking $pkg ...\"; pushd ./packages/$pkg; npm link ; popd; done",
"unlink": "for pkg in $(ls ./packages); do npm un -g @brn/$pkg; done",
"lint": "eslint -c .eslintrc.js '*/**/*.{js,ts}'",
"lint:fix": "eslint -c .eslintrc.js '*/**/*.{js,ts}' --quiet --fix",
"lint:quiet": "eslint 'packages/**/*.ts' --quiet",
"lint:report": "eslint 'packages/**/*.ts' -f json -o './build/eslint/eslint-report.json' -f html -o './build/eslint/eslint-report.html'",
"prettier": "prettier --check 'packages/**/*.ts'",
"prettier:fix": "prettier --write 'packages/**/*.ts'",
"pre-release": "lerna version --conventional-commits --conventional-prerelease",
"force-release": "lerna publish --force-publish",
"test": "jest",
"clear:libs": "for lib in $(find ./packages -type d -name \"lib\" -not -path \"*node_modules*\"); do echo \"cleaning $lib ...\"; rm -rf $lib; done; echo",
"clean": "npm run clear:libs && lerna clean --yes && rm -rf node_modules/ && npm install && lerna bootstrap",
"build": "lerna clean && lerna bootstrap && npm run prettier:fix && npm run lint:quiet && npm run prettier && lerna run build",
"commit": "git-cz",
"publish:alpha": "lerna version --conventional-commits --conventional-prerelease --force-publish --yes",
"publish:release": "export RELEASE=release/${VERSION} && git checkout -b ${RELEASE} && git push --set-upstream origin ${RELEASE} && lerna version --yes --conventional-commits ${VERSION} && echo && echo \"Submit your PR for ${RELEASE}\"",
"publish": "[[ -z $VERSION ]] && echo \"MUST define VERSION\" || npm run publish:release",
"publish:major": "VERSION=$(npm run latest | tail -1 | awk '{ split($0,version,\".\"); major=version[1]+1; print major \".0.0\" }') npm run publish:release",
"publish:minor": "VERSION=$(npm run latest | tail -1 | awk '{ split($0,version,\".\"); minor=version[2]+1; print version[1] \".\" minor \".0\" }') npm run publish:release",
"publish:patch": "VERSION=$(npm run latest | tail -1 | awk '{ split($0,version,\".\"); patch=version[3]+1; print version[1] \".\" version[2] \".\" patch }') npm run publish:release",
"bootstrap": "lerna bootstrap",
"link-constructs": "npm i && cd packages/cdk-constructs && npm i && npm run build && npm link",
"release:alpha": "lerna version --conventional-commits --conventional-prerelease --force-publish --yes"
},
"author": "",
"license": "ISC",
"dependencies": {
"14": "^3.1.6",
"aws-cdk-lib": "^2.134.0",
"constructs": "^10.2.45"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.6",
"@types/jest": "^27.5.2",
"@types/node": "10.17.27",
"@types/prettier": "2.6.0",
"@types/ramda": "^0.27.44",
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"babel-jest": "^27.1.1",
"babel-loader": "^8.2.2",
"commitizen": "4.2.4",
"cz-lerna-changelog": "^2.0.3",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.2",
"jest": "^27.5.1",
"lerna": "3.22.1",
"lint-staged": "^11.1.2",
"prettier": "^2.4.0",
"ramda": "^0.27.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"typescript": "^4.4.2"
},
"engines" : {
"npm" : ">=8.0.0",
"node" : ">=18.0.0 <19.0.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-lerna-changelog"
}
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.ts": [
"eslint -c .eslintrc.js --fix"
]
}
}

Tuesday, January 10, 2023

How to mock specific method mockImplementation jest in nodejs?

 Here is some best solution , how we can mock specific method from utils file.


Step1: I have created a utils.js file and it contains two methods

like :

const getSchoolName = async ({schoolId }) => {


return 'Bikash School';
};
const getAllSchoolList = async ({schoolId }) => {


return {object};
};


Step 2 : create actual-utils-call.test.js  and import the utils.js file

import { getAllSchoolList, getSchoolName } from './util';



jest.mock('./utils', () => {
const originalUtils = jest.requireActual('./utils');
return {
...originalUtils,
getSchoolName: jest.fn(),
};
});


describe('Mock specific mockImplementation', () => {
it('getSchoolName method should mock from util file', async () => {
getSchoolName.mockImplementation(() => {
return 'different School Name';
});
});

// Here you call your actual method where getSchoolName method is invoke

});