Skip to content

Instantly share code, notes, and snippets.

@ricmiber96
Last active October 24, 2021 10:21
Show Gist options
  • Save ricmiber96/374d2a766b1c95376cb6e081f3c89c40 to your computer and use it in GitHub Desktop.
Save ricmiber96/374d2a766b1c95376cb6e081f3c89c40 to your computer and use it in GitHub Desktop.
BASH SCRIPT FOR TESTING JS FUNCTION WITH JEST
#!/bin/bash
VERSION="0.1"
NAME=$1
JQ=$(which jq)
WGET=$(which wget)
NPM=$(npm --version)
NPM=${NPM::1}
echo "Ejecutar con bash commandNAME folderNAME"
if [ -z "$JQ" ]; then
echo "jq not detected. Install with sudo apt-get install jq"
exit
fi
if [ -z "$WGET" ]; then
echo "wget not detected. Install with sudo apt-get install wget"
exit
fi
if [[ "$NPM" == "6" ]]; then
echo "npm7 is required. Install with npm install -g npm"
exit
fi
if [ $# -eq 0 ]; then
echo "mkweb $VERSION. Sintaxis:"
echo -e " $(basename $0) <nombre-carpeta>\n"
echo "Recuerda que necesitas tener instalado jq, wget y npm7+."
exit
fi
mkdir $NAME
cd $NAME
git init
# npm install --save-dev jest
cat >package.json << EOF
{
"name": "testing-js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "jest",
"test:watch": "jest --watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.15.4",
"@types/jest": "^27.0.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"jest": "^27.2.4"
}
}
EOF
npm i
cat >.gitignore << EOF
node_modules
.vscode
EOF
cat > .babelrc << EOF
{
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
EOF
cat > .eslintrc.js << EOF
module.exports = {
env: {
commonjs: true,
es6: true,
node: true,
jest: true,
},
extends: ["standard", "prettier"],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
parserOptions: {
ecmaVersion: 2018,
},
rules: {},
}
EOF
mkdir src
cd src
mkdir __tests__
cat > main.js <<EOF
export function mainFuction() {
return true;
}
EOF
cd __tests__
cat > main.test.js <<EOF
import { mainFuction } from "../main";
describe("Main function test", () => {
it("Function returns true", () => {
expect(dummy()).toEqual(true);
})
})
EOF
cat << EOF
¡Listo! Para empezar, escribe:
cd $NAME
git remote add origin <repo>
npm install
npm jest --watch
EOF
@ricmiber96
Copy link
Author

ricmiber96 commented Oct 24, 2021

Ejecutar con bash testing-script.sh nameFolderProject

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment