diff --git a/modulo5/testes-automatizados/.gitignore b/modulo5/testes-automatizados/.gitignore new file mode 100644 index 0000000..77f5760 --- /dev/null +++ b/modulo5/testes-automatizados/.gitignore @@ -0,0 +1,4 @@ +node_modules +build +package-lock.json +.env \ No newline at end of file diff --git a/modulo5/testes-automatizados/jest.config.js b/modulo5/testes-automatizados/jest.config.js new file mode 100644 index 0000000..969c9b1 --- /dev/null +++ b/modulo5/testes-automatizados/jest.config.js @@ -0,0 +1,8 @@ +module.exports = { + roots: ["/tests"], + transform: { + "^.+\\.tsx?$": "ts-jest", + }, + testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], + }; \ No newline at end of file diff --git a/modulo5/testes-automatizados/package.json b/modulo5/testes-automatizados/package.json new file mode 100644 index 0000000..43737dc --- /dev/null +++ b/modulo5/testes-automatizados/package.json @@ -0,0 +1,28 @@ +{ + "name": "testes-automatizados", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "tsc && node ./build/index.js", + "dev": "ts-node-dev ./src/index.ts", + "test": "jest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@types/express": "^4.17.13", + "@types/jest": "^27.4.1", + "@types/knex": "^0.16.1", + "@types/node": "^17.0.21", + "dotenv": "^16.0.0", + "express": "^4.17.3", + "jest": "^27.5.1", + "knex": "^1.0.4", + "mysql": "^2.18.1", + "ts-jest": "^27.1.3", + "ts-node-dev": "^1.1.8", + "typescript": "^4.6.2" + } +} diff --git a/modulo5/testes-automatizados/src/index.ts b/modulo5/testes-automatizados/src/index.ts new file mode 100644 index 0000000..0b325f4 --- /dev/null +++ b/modulo5/testes-automatizados/src/index.ts @@ -0,0 +1,31 @@ +import express from 'express' +import knex from 'knex' +import dotenv from 'dotenv' +import { AddressInfo } from "net" + +dotenv.config() + +const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + port: Number(process.env.DB_PORT || "3306"), + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_NAME, + } + +}) + +const app = express(); + +app.use(express.json()); + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost:${address.port}`); + } else { + console.error(`Failure upon starting server.`); + } +});; \ No newline at end of file diff --git a/modulo5/testes-automatizados/tests/index.test.js b/modulo5/testes-automatizados/tests/index.test.js new file mode 100644 index 0000000..e69de29 diff --git a/modulo5/testes-automatizados/tsconfig.json b/modulo5/testes-automatizados/tsconfig.json new file mode 100644 index 0000000..ceeb309 --- /dev/null +++ b/modulo5/testes-automatizados/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, + "outDir": "./build" /* Redirect output structure to the directory. */, + "rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, + "strict": true /* Enable all strict type-checking options. */, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } + } \ No newline at end of file