project: testing (#15)

This commit is contained in:
Mike 2024-02-16 16:07:49 -05:00 committed by GitHub
parent 6f8a4ec879
commit d899a773bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 9544 additions and 0 deletions

12
testing/.eslintrc.js Normal file
View file

@ -0,0 +1,12 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: ["eslint:recommended", "prettier"],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
};

132
testing/.gitignore vendored Normal file
View file

@ -0,0 +1,132 @@
# ---> Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

4
testing/.prettierrc Normal file
View file

@ -0,0 +1,4 @@
{
"tabWidth": 4,
"singleQuote": true
}

5
testing/README.md Normal file
View file

@ -0,0 +1,5 @@
# webpack-template
Vanilla template for webpack
sets up common utilities needed for vanilla JS/HTML/CSS development

3
testing/babel.config.js Normal file
View file

@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
};

9207
testing/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

29
testing/package.json Normal file
View file

@ -0,0 +1,29 @@
{
"name": "webpack-template",
"version": "1.0.0",
"description": "Vanilla template for webpack",
"main": "index.js",
"scripts": {
"test": "jest",
"start": "webpack serve --open --config webpack.dev.js",
"build": "webpack --config webpack.prod.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"babel-jest": "^29.7.0",
"css-loader": "^6.8.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"html-webpack-plugin": "^5.6.0",
"jest": "^29.7.0",
"style-loader": "^3.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.10.0"
}
}

3
testing/src/index.js Normal file
View file

@ -0,0 +1,3 @@
import { calculator } from './odinTests';
console.log(calculator(1, 2, '+'));

42
testing/src/odinTests.js Normal file
View file

@ -0,0 +1,42 @@
const capitalize = (thing) => thing.charAt(0).toUpperCase() + thing.slice(1);
const reverseString = (thing) => thing.split('').reverse().join('');
const calculator = (a, b, operation) => {
switch (operation) {
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
if (b === 0) {
return 'error';
}
return a / b;
}
};
const ceaserCipher = (thing) => {
let cipher = thing.split('').map((item) => {
let charCode = item.charCodeAt(0);
return String.fromCharCode(charCode + 3);
});
return cipher.join('');
};
const analyzeArray = (arr) => {
let min = Math.min(...arr);
let max = Math.max(...arr);
let length = arr.length;
let avg = arr.reduce((sum, num) => sum + num, 0) / length;
return {
average: avg,
min: min,
max: max,
length: length,
};
};
export { analyzeArray, ceaserCipher, calculator, capitalize, reverseString };

View file

@ -0,0 +1,30 @@
import {
analyzeArray,
ceaserCipher,
calculator,
reverseString,
capitalize,
} from './odinTests';
test('make sure mike = Mike', () => {
expect(capitalize('mike')).toBe('Mike');
});
test('make sure mike = ekim', () => {
expect(reverseString('mike')).toBe('ekim');
});
test('Make sure calculator works', () => {
expect(calculator(1, 2, '+')).toBe(3);
expect(calculator(1, 2, '-')).toBe(-1);
expect(calculator(1, 2, '*')).toBe(2);
expect(calculator(1, 0, '/')).toBe('error');
expect(calculator(1, 2, '/')).toBe(0.5);
expect(ceaserCipher('bob')).toBe('ere');
expect(analyzeArray([1, 2, 3, 4])).toEqual({
average: 2.5,
min: 1,
max: 4,
length: 4,
});
});

17
testing/src/style.css Normal file
View file

@ -0,0 +1,17 @@
input {
outline: none;
}
input:user-invalid {
outline: none;
border: 3px solid red;
}
input:valid {
outline: none;
border: 3px solid green;
}
span {
margin-left: 10px;
color: red;
}

5
testing/src/sum.js Normal file
View file

@ -0,0 +1,5 @@
function sum(a, b) {
return a + b;
}
module.exports = sum;

5
testing/src/sum.test.js Normal file
View file

@ -0,0 +1,5 @@
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});

34
testing/webpack.common.js Normal file
View file

@ -0,0 +1,34 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
index: './src/index.js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'Testing',
}),
],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
};

10
testing/webpack.dev.js Normal file
View file

@ -0,0 +1,10 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
module.exports = merge(common, {
mode: "development",
devtool: "inline-source-map",
devServer: {
static: "./dist",
},
});

6
testing/webpack.prod.js Normal file
View file

@ -0,0 +1,6 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
module.exports = merge(common, {
mode: "production",
});