From d0ddf584ba39dd6cac19a05f650fa3e1d77fc29f Mon Sep 17 00:00:00 2001 From: tolumide-ng Date: Fri, 2 Aug 2019 11:40:21 +0100 Subject: [PATCH] feat(users): Add heroku:build command - Adds server - Adds procfile for npm - Adds jest.config.js - Adds mock file for jest mocking - Enforces pre:commit test through husky [Maintains #167664242] --- Procfile | 1 + __mocks__/fileMock.js | 1 + jest.config.js | 28 ++++++ package.json | 10 +- server.js | 15 +++ {public => src/assets}/images/logo.png | Bin src/pages/hompage.js | 5 +- tests/__snapshots__/App.spec.js.snap | 128 +++++++++++++++++++++++++ webpack.common.js | 2 +- 9 files changed, 183 insertions(+), 7 deletions(-) create mode 100644 Procfile create mode 100644 __mocks__/fileMock.js create mode 100644 jest.config.js create mode 100644 server.js rename {public => src/assets}/images/logo.png (100%) create mode 100644 tests/__snapshots__/App.spec.js.snap diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..bef5264 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: npm run start \ No newline at end of file diff --git a/__mocks__/fileMock.js b/__mocks__/fileMock.js new file mode 100644 index 0000000..f053ebf --- /dev/null +++ b/__mocks__/fileMock.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..93d7f23 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,28 @@ +module.exports = { + coverageDirectory: 'coverage', + testPathIgnorePatterns: ['/node_modules/'], + transformIgnorePatterns: ['/node_modules/'], + moduleNameMapper: { + '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': + '/__mocks__/fileMock.js', + '\\.(css|less)$': '/__mocks__/styleMock.js' + }, + collectCoverageFrom: [ + '**/*.{js,jsx}', + '!**/node_modules/**', + '!jest.config.js', + '!**/dist/**', + '!**/webpack-build-utils/**', + '!README.md', + 'Procfile', + 'Postcss.config.js', + '!package.json', + '!package-lock.json', + '!cypress.json', + '!/server.js', + '!webpack.common.js', + '!webpack.config.js', + '!**/coverage/**', + '!**/tests/**' + ] +}; diff --git a/package.json b/package.json index b511461..244d664 100644 --- a/package.json +++ b/package.json @@ -4,17 +4,18 @@ "description": "errorSwag frontend", "main": "index.js", "scripts": { - "test": "jest --coverage", "lint": "eslint '**/*.js'", "lint:fix": "prettier-eslint \"**/*.{js,json}\" --write", "prettier": "prettier **/*.{js,json} --write", "format": "pretty-quick", "develop": "webpack --env.mode development --watch", - "heroku-postbuild": "webpack --env.mode production", + "heroku-postbuild": "npm run build", + "start": "node server.js", "build": "webpack --env.mode production", - "start": "webpack-dev-server --hot --env.mode development --open", + "start:dev": "webpack-dev-server --hot --env.mode development --open", "cypress": "cypress open", - "test:watch": "npm run test -- --watch", + "test": "jest --coverage", + "test:watch": "jest --watch --coverage", "coverage": "cat ./coverage/lcov.info | coveralls" }, "husky": { @@ -79,6 +80,7 @@ "autoprefixer": "^9.6.1", "clean-webpack-plugin": "^3.0.0", "css-loader": "^3.1.0", + "express": "^4.17.1", "glob": "^7.1.4", "html-webpack-plugin": "^3.2.0", "mini-css-extract-plugin": "^0.8.0", diff --git a/server.js b/server.js new file mode 100644 index 0000000..02f9a34 --- /dev/null +++ b/server.js @@ -0,0 +1,15 @@ +const express = require('express'); +const path = require('path'); + +const port = process.env.PORT || 9000; +const app = express(); + +app.use(express.static(`${__dirname}/dist`)); + +app.get('*', (req, res) => { + res.sendFile(path.resolve(__dirname, './dist/index.html')); +}); + +app.listen(process.env.PORT || 3000, () => { + process.stdout.write(`Listening on port ${port}`); +}); diff --git a/public/images/logo.png b/src/assets/images/logo.png similarity index 100% rename from public/images/logo.png rename to src/assets/images/logo.png diff --git a/src/pages/hompage.js b/src/pages/hompage.js index 790cd0b..6b47006 100644 --- a/src/pages/hompage.js +++ b/src/pages/hompage.js @@ -1,5 +1,6 @@ -import React, { Component } from 'react'; +import React from 'react'; import { Link } from 'react-router-dom'; +import logo from '../assets/images/logo.png'; const Homepage = () => { return ( @@ -7,7 +8,7 @@ const Homepage = () => {

Welcome to ErrorSwag, what on your mind?

- errorswag logo + errorswag logo + + +`; + +exports[`Application test should work fine on App 1`] = ` + + + +`; + +exports[`Application test should work fine on Login Page 1`] = ` + + + + +
+ + + + + +
+
+`; + +exports[`Application test should work fine on Routes 1`] = ` + + + + +`; diff --git a/webpack.common.js b/webpack.common.js index 6ea29bd..0d7884c 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -28,7 +28,7 @@ module.exports = { } }, { - test: /\.(svg|png|gif|jpeg|jpg)$/, + test: /\.(svg|png|jpeg|jpg)$/, use: { loader: 'file-loader', options: {