From 94312a6902f5b9cda05498000c565228449765cf Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sun, 9 Feb 2020 17:16:10 +0100 Subject: [PATCH] project organisation, fix build & test runs --- .editorconfig | 10 ----- .prettierrc | 3 +- .../babel.config.js => babel.config.js | 2 +- package.json | 42 +++++------------- src/main/index.js | 2 +- src/renderer/{src => }/Layout.jsx | 0 src/renderer/{src => }/Layout.module.css | 0 .../AccountsList}/New.jsx | 0 .../AccountsList}/New.module.css | 0 .../AccountsList}/Saved.jsx | 2 +- .../AccountsList}/Saved.module.css | 0 .../AccountsList}/index.jsx | 6 +-- .../AccountsList}/index.module.css | 2 +- .../{src => }/components/Animations.js | 0 src/renderer/{src => }/components/Balance.jsx | 2 +- .../{src => }/components/Balance.module.css | 0 .../{src => }/components/Box.module.css | 0 src/renderer/{src => }/components/Divider.jsx | 0 .../{src => }/components/Divider.module.css | 0 .../{src => }/components/Home/Accounts.jsx | 2 +- .../components/Home/Accounts.module.css | 0 .../{src => }/components/Home/Ticker.jsx | 2 +- .../components/Home/Ticker.module.css | 0 .../{src => }/components/Home/Total.jsx | 2 +- .../{src => }/components/Home/Welcome.jsx | 0 .../components/Home/Welcome.module.css | 0 src/renderer/{src => }/components/Label.jsx | 0 .../{src => }/components/Label.module.css | 0 src/renderer/{src => }/components/Spinner.jsx | 0 .../{src => }/components/Spinner.module.css | 0 .../{src => }/components/Titlebar.jsx | 2 +- .../{src => }/components/Titlebar.module.css | 0 src/renderer/{src => }/global.css | 0 src/renderer/{src => }/images/cog.svg | 0 src/renderer/{src => }/images/icon.icns | Bin src/renderer/{src => }/images/icon.ico | Bin src/renderer/{src => }/images/icon1024.png | Bin src/renderer/{src => }/images/rocket.svg | 0 src/renderer/jest/App.test.jsx | 15 ------- src/renderer/jest/setup-test-env.js | 1 - src/renderer/next.config.js | 16 +++---- src/renderer/{src => }/pages/_app.jsx | 4 +- src/renderer/{src => }/pages/index.jsx | 0 src/renderer/{src => }/pages/index.module.css | 0 src/renderer/{src => }/pages/preferences.jsx | 4 +- .../{src => }/pages/preferences.module.css | 0 src/renderer/{src => }/store/AppProvider.jsx | 20 ++++----- .../{src => }/store/createContext.jsx | 0 tests/Layout.test.jsx | 10 +++++ .../jest => tests}/__fixtures__/context.js | 0 .../jest => tests}/__mocks__/file-mock.js | 0 .../jest => tests}/__mocks__/svgr-mock.js | 0 .../components/AccountsList.test.jsx | 4 +- tests/components/Spinner.test.jsx | 10 +++++ tests/jest.config.js | 32 +++++++++++++ .../jest => tests/pages}/index.test.jsx | 6 +-- .../jest => tests/pages}/preferences.test.jsx | 4 +- 57 files changed, 101 insertions(+), 104 deletions(-) delete mode 100644 .editorconfig rename src/renderer/babel.config.js => babel.config.js (79%) rename src/renderer/{src => }/Layout.jsx (100%) rename src/renderer/{src => }/Layout.module.css (100%) rename src/renderer/{src/components/Preferences/Accounts => components/AccountsList}/New.jsx (100%) rename src/renderer/{src/components/Preferences/Accounts => components/AccountsList}/New.module.css (100%) rename src/renderer/{src/components/Preferences/Accounts => components/AccountsList}/Saved.jsx (96%) rename src/renderer/{src/components/Preferences/Accounts => components/AccountsList}/Saved.module.css (100%) rename src/renderer/{src/components/Preferences/Accounts => components/AccountsList}/index.jsx (92%) rename src/renderer/{src/components/Preferences/Accounts => components/AccountsList}/index.module.css (93%) rename src/renderer/{src => }/components/Animations.js (100%) rename src/renderer/{src => }/components/Balance.jsx (95%) rename src/renderer/{src => }/components/Balance.module.css (100%) rename src/renderer/{src => }/components/Box.module.css (100%) rename src/renderer/{src => }/components/Divider.jsx (100%) rename src/renderer/{src => }/components/Divider.module.css (100%) rename src/renderer/{src => }/components/Home/Accounts.jsx (93%) rename src/renderer/{src => }/components/Home/Accounts.module.css (100%) rename src/renderer/{src => }/components/Home/Ticker.jsx (97%) rename src/renderer/{src => }/components/Home/Ticker.module.css (100%) rename src/renderer/{src => }/components/Home/Total.jsx (94%) rename src/renderer/{src => }/components/Home/Welcome.jsx (100%) rename src/renderer/{src => }/components/Home/Welcome.module.css (100%) rename src/renderer/{src => }/components/Label.jsx (100%) rename src/renderer/{src => }/components/Label.module.css (100%) rename src/renderer/{src => }/components/Spinner.jsx (100%) rename src/renderer/{src => }/components/Spinner.module.css (100%) rename src/renderer/{src => }/components/Titlebar.jsx (84%) rename src/renderer/{src => }/components/Titlebar.module.css (100%) rename src/renderer/{src => }/global.css (100%) rename src/renderer/{src => }/images/cog.svg (100%) rename src/renderer/{src => }/images/icon.icns (100%) rename src/renderer/{src => }/images/icon.ico (100%) rename src/renderer/{src => }/images/icon1024.png (100%) rename src/renderer/{src => }/images/rocket.svg (100%) delete mode 100644 src/renderer/jest/App.test.jsx delete mode 100644 src/renderer/jest/setup-test-env.js rename src/renderer/{src => }/pages/_app.jsx (85%) rename src/renderer/{src => }/pages/index.jsx (100%) rename src/renderer/{src => }/pages/index.module.css (100%) rename src/renderer/{src => }/pages/preferences.jsx (83%) rename src/renderer/{src => }/pages/preferences.module.css (100%) rename src/renderer/{src => }/store/AppProvider.jsx (86%) rename src/renderer/{src => }/store/createContext.jsx (100%) create mode 100644 tests/Layout.test.jsx rename {src/renderer/jest => tests}/__fixtures__/context.js (100%) rename {src/renderer/jest => tests}/__mocks__/file-mock.js (100%) rename {src/renderer/jest => tests}/__mocks__/svgr-mock.js (100%) rename src/renderer/src/components/Preferences/Accounts/index.test.jsx => tests/components/AccountsList.test.jsx (91%) create mode 100644 tests/components/Spinner.test.jsx create mode 100644 tests/jest.config.js rename {src/renderer/jest => tests/pages}/index.test.jsx (80%) rename {src/renderer/jest => tests/pages}/preferences.test.jsx (73%) diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 37fee84..0000000 --- a/.editorconfig +++ /dev/null @@ -1,10 +0,0 @@ -# EditorConfig is awesome: http://EditorConfig.org -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -insert_final_newline = true -charset = utf-8 -trim_trailing_whitespace = true diff --git a/.prettierrc b/.prettierrc index 49955e2..338a8b9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,6 @@ { "semi": false, "singleQuote": true, - "trailingComma": "none" + "trailingComma": "none", + "tabWidth": 2 } diff --git a/src/renderer/babel.config.js b/babel.config.js similarity index 79% rename from src/renderer/babel.config.js rename to babel.config.js index 3d88cfe..94848e7 100644 --- a/src/renderer/babel.config.js +++ b/babel.config.js @@ -1,4 +1,4 @@ -const { devDependencies } = require('../../package.json') +const { devDependencies } = require('./package.json') module.exports = { presets: [ diff --git a/package.json b/package.json index fa7e407..621b7ad 100644 --- a/package.json +++ b/package.json @@ -6,17 +6,19 @@ "main": "./src/main/index.js", "scripts": { "start": "electron .", - "test": "npm run lint && jest", - "test:watch": "jest --watch", + "test": "npm run lint && npm run jest", + "test:watch": "npm run jest -- --watch", + "jest": "NODE_ENV=test jest -c tests/jest.config.js", "lint": "eslint --ignore-path .gitignore ./src/**/*.{js,jsx} && stylelint --ignore-path .gitignore ./src/**/*.{css,scss}", - "build:react": "next build src/renderer && next export src/renderer", + "copy": "rsync src/renderer/images/icon* build/", + "build:react": "next build src/renderer && next export src/renderer && npm run copy", "build:electron": "electron-builder build -ml -p never", "build:electron:win": "electron-builder build -w -p never", "dist": "./scripts/release-prepare.sh", "release": "release-it --non-interactive", "changelog": "auto-changelog -p", - "format": "prettier --write 'src/**/*.{js,jsx}' && npm run format:css", - "format:css": "prettier-stylelint --write --quiet 'src/**/*.{css,scss}'" + "format": "prettier --write --ignore-path .gitignore 'src/**/*.{js,jsx}' && npm run format:css", + "format:css": "prettier-stylelint --write --ignore-path .gitignore --quiet 'src/**/*.{css,scss}'" }, "repository": "https://github.com/kremalicious/blowfish.git", "homepage": "https://github.com/kremalicious/blowfish", @@ -28,6 +30,9 @@ "license": "MIT", "dependencies": { "@coingecko/cryptoformat": "^0.3.3", + "electron-is-dev": "^1.1.0", + "electron-next": "^3.1.5", + "electron-store": "^5.1.0", "ethereum-address": "^0.0.4", "ethereum-blockies": "github:MyEtherWallet/blockies", "ms": "^2.1.2", @@ -47,9 +52,6 @@ "electron": "^8.0.0", "electron-builder": "^22.3.2", "electron-devtools-installer": "^2.2.4", - "electron-is-dev": "^1.1.0", - "electron-next": "^3.1.5", - "electron-store": "^5.1.0", "eslint": "^6.8.0", "eslint-config-prettier": "^6.10.0", "eslint-plugin-react": "^7.18.3", @@ -117,29 +119,5 @@ "npm": { "publish": false } - }, - "jest": { - "rootDir": "src/renderer", - "transform": { - "^.+\\.jsx?$": "babel-jest" - }, - "moduleNameMapper": { - ".+\\.(css|styl|less|sass|scss)$": "identity-obj-proxy", - ".+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/jest/__mocks__/file-mock.js", - "\\.svg": "/jest/__mocks__/svgr-mock.js" - }, - "testURL": "http://localhost", - "setupFilesAfterEnv": [ - "/jest/setup-test-env.js" - ], - "coverageDirectory": "../../coverage/", - "collectCoverage": true, - "collectCoverageFrom": [ - "/**/*.{js,jsx}", - "!/jest/**/*.{js,jsx}", - "!**/node_modules/**" - ], - "runner": "@jest-runner/electron", - "testEnvironment": "@jest-runner/electron/environment" } } diff --git a/src/main/index.js b/src/main/index.js index c1a54e6..03b21b2 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -36,9 +36,9 @@ const createWindow = async () => { autoHideMenuBar: true, webPreferences: { nodeIntegration: true, + preload: path.join(__dirname, 'preload.js'), scrollBounce: true, enableBlinkFeatures: 'OverlayScrollbars' - // preload: path.join(__dirname, 'preload.js') } }) diff --git a/src/renderer/src/Layout.jsx b/src/renderer/Layout.jsx similarity index 100% rename from src/renderer/src/Layout.jsx rename to src/renderer/Layout.jsx diff --git a/src/renderer/src/Layout.module.css b/src/renderer/Layout.module.css similarity index 100% rename from src/renderer/src/Layout.module.css rename to src/renderer/Layout.module.css diff --git a/src/renderer/src/components/Preferences/Accounts/New.jsx b/src/renderer/components/AccountsList/New.jsx similarity index 100% rename from src/renderer/src/components/Preferences/Accounts/New.jsx rename to src/renderer/components/AccountsList/New.jsx diff --git a/src/renderer/src/components/Preferences/Accounts/New.module.css b/src/renderer/components/AccountsList/New.module.css similarity index 100% rename from src/renderer/src/components/Preferences/Accounts/New.module.css rename to src/renderer/components/AccountsList/New.module.css diff --git a/src/renderer/src/components/Preferences/Accounts/Saved.jsx b/src/renderer/components/AccountsList/Saved.jsx similarity index 96% rename from src/renderer/src/components/Preferences/Accounts/Saved.jsx rename to src/renderer/components/AccountsList/Saved.jsx index 9162f46..fe91e71 100644 --- a/src/renderer/src/components/Preferences/Accounts/Saved.jsx +++ b/src/renderer/components/AccountsList/Saved.jsx @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { toDataUrl } from 'ethereum-blockies' import posed, { PoseGroup } from 'react-pose' -import { fadeIn } from '../../Animations' +import { fadeIn } from '../Animations' import styles from './Saved.module.css' export default function Saved({ accounts, handleDelete }) { diff --git a/src/renderer/src/components/Preferences/Accounts/Saved.module.css b/src/renderer/components/AccountsList/Saved.module.css similarity index 100% rename from src/renderer/src/components/Preferences/Accounts/Saved.module.css rename to src/renderer/components/AccountsList/Saved.module.css diff --git a/src/renderer/src/components/Preferences/Accounts/index.jsx b/src/renderer/components/AccountsList/index.jsx similarity index 92% rename from src/renderer/src/components/Preferences/Accounts/index.jsx rename to src/renderer/components/AccountsList/index.jsx index c259230..76b3c6c 100644 --- a/src/renderer/src/components/Preferences/Accounts/index.jsx +++ b/src/renderer/components/AccountsList/index.jsx @@ -1,15 +1,15 @@ import React, { PureComponent } from 'react' import ethereum_address from 'ethereum-address' import Store from 'electron-store' -import { AppContext } from '../../../store/createContext' +import { AppContext } from '../../store/createContext' import Saved from './Saved' import New from './New' import styles from './index.module.css' -export default class Accounts extends PureComponent { +export default class AccountsList extends PureComponent { static contextType = AppContext - store = new Store() + store = process.env.NODE_ENV === 'test' ? new Store() : global.store state = { accounts: [], input: '', error: '' } diff --git a/src/renderer/src/components/Preferences/Accounts/index.module.css b/src/renderer/components/AccountsList/index.module.css similarity index 93% rename from src/renderer/src/components/Preferences/Accounts/index.module.css rename to src/renderer/components/AccountsList/index.module.css index eb1403e..62c801e 100644 --- a/src/renderer/src/components/Preferences/Accounts/index.module.css +++ b/src/renderer/components/AccountsList/index.module.css @@ -1,5 +1,5 @@ .preference { - composes: box from '../../../components/Box.module.css'; + composes: box from '../Box.module.css'; -webkit-app-region: none; -webkit-user-select: text; } diff --git a/src/renderer/src/components/Animations.js b/src/renderer/components/Animations.js similarity index 100% rename from src/renderer/src/components/Animations.js rename to src/renderer/components/Animations.js diff --git a/src/renderer/src/components/Balance.jsx b/src/renderer/components/Balance.jsx similarity index 95% rename from src/renderer/src/components/Balance.jsx rename to src/renderer/components/Balance.jsx index 3b00715..0335a40 100644 --- a/src/renderer/src/components/Balance.jsx +++ b/src/renderer/components/Balance.jsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react' import PropTypes from 'prop-types' import posed, { PoseGroup } from 'react-pose' import { AppContext } from '../store/createContext' -import { cryptoFormatter } from '../../../utils' +import { cryptoFormatter } from '../../utils' import { fadeIn } from './Animations' import Label from './Label' import styles from './Balance.module.css' diff --git a/src/renderer/src/components/Balance.module.css b/src/renderer/components/Balance.module.css similarity index 100% rename from src/renderer/src/components/Balance.module.css rename to src/renderer/components/Balance.module.css diff --git a/src/renderer/src/components/Box.module.css b/src/renderer/components/Box.module.css similarity index 100% rename from src/renderer/src/components/Box.module.css rename to src/renderer/components/Box.module.css diff --git a/src/renderer/src/components/Divider.jsx b/src/renderer/components/Divider.jsx similarity index 100% rename from src/renderer/src/components/Divider.jsx rename to src/renderer/components/Divider.jsx diff --git a/src/renderer/src/components/Divider.module.css b/src/renderer/components/Divider.module.css similarity index 100% rename from src/renderer/src/components/Divider.module.css rename to src/renderer/components/Divider.module.css diff --git a/src/renderer/src/components/Home/Accounts.jsx b/src/renderer/components/Home/Accounts.jsx similarity index 93% rename from src/renderer/src/components/Home/Accounts.jsx rename to src/renderer/components/Home/Accounts.jsx index 805907e..82eac45 100644 --- a/src/renderer/src/components/Home/Accounts.jsx +++ b/src/renderer/components/Home/Accounts.jsx @@ -1,5 +1,5 @@ import React, { useContext } from 'react' -import { openUrl } from '../../../../utils' +import { openUrl } from '../../../utils' import Balance from '../Balance' import { AppContext } from '../../store/createContext' import styles from './Accounts.module.css' diff --git a/src/renderer/src/components/Home/Accounts.module.css b/src/renderer/components/Home/Accounts.module.css similarity index 100% rename from src/renderer/src/components/Home/Accounts.module.css rename to src/renderer/components/Home/Accounts.module.css diff --git a/src/renderer/src/components/Home/Ticker.jsx b/src/renderer/components/Home/Ticker.jsx similarity index 97% rename from src/renderer/src/components/Home/Ticker.jsx rename to src/renderer/components/Home/Ticker.jsx index 96a8f2e..9b7d6e8 100644 --- a/src/renderer/src/components/Home/Ticker.jsx +++ b/src/renderer/components/Home/Ticker.jsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react' import PropTypes from 'prop-types' import posed, { PoseGroup } from 'react-pose' import { AppContext } from '../../store/createContext' -import { cryptoFormatter } from '../../../../utils' +import { cryptoFormatter } from '../../../utils' import stylesIndex from '../../pages/index.module.css' import styles from './Ticker.module.css' import { fadeIn } from '../Animations' diff --git a/src/renderer/src/components/Home/Ticker.module.css b/src/renderer/components/Home/Ticker.module.css similarity index 100% rename from src/renderer/src/components/Home/Ticker.module.css rename to src/renderer/components/Home/Ticker.module.css diff --git a/src/renderer/src/components/Home/Total.jsx b/src/renderer/components/Home/Total.jsx similarity index 94% rename from src/renderer/src/components/Home/Total.jsx rename to src/renderer/components/Home/Total.jsx index dda91ab..9462ba9 100644 --- a/src/renderer/src/components/Home/Total.jsx +++ b/src/renderer/components/Home/Total.jsx @@ -1,7 +1,7 @@ import React, { useContext } from 'react' import { AppContext } from '../../store/createContext' import Balance from '../Balance' -import { conversions } from '../../../../config' +import { conversions } from '../../../config' const calculateTotalBalance = (accounts, currency) => { const balanceTotalArray = [] diff --git a/src/renderer/src/components/Home/Welcome.jsx b/src/renderer/components/Home/Welcome.jsx similarity index 100% rename from src/renderer/src/components/Home/Welcome.jsx rename to src/renderer/components/Home/Welcome.jsx diff --git a/src/renderer/src/components/Home/Welcome.module.css b/src/renderer/components/Home/Welcome.module.css similarity index 100% rename from src/renderer/src/components/Home/Welcome.module.css rename to src/renderer/components/Home/Welcome.module.css diff --git a/src/renderer/src/components/Label.jsx b/src/renderer/components/Label.jsx similarity index 100% rename from src/renderer/src/components/Label.jsx rename to src/renderer/components/Label.jsx diff --git a/src/renderer/src/components/Label.module.css b/src/renderer/components/Label.module.css similarity index 100% rename from src/renderer/src/components/Label.module.css rename to src/renderer/components/Label.module.css diff --git a/src/renderer/src/components/Spinner.jsx b/src/renderer/components/Spinner.jsx similarity index 100% rename from src/renderer/src/components/Spinner.jsx rename to src/renderer/components/Spinner.jsx diff --git a/src/renderer/src/components/Spinner.module.css b/src/renderer/components/Spinner.module.css similarity index 100% rename from src/renderer/src/components/Spinner.module.css rename to src/renderer/components/Spinner.module.css diff --git a/src/renderer/src/components/Titlebar.jsx b/src/renderer/components/Titlebar.jsx similarity index 84% rename from src/renderer/src/components/Titlebar.jsx rename to src/renderer/components/Titlebar.jsx index 99ad876..d0d1acf 100644 --- a/src/renderer/src/components/Titlebar.jsx +++ b/src/renderer/components/Titlebar.jsx @@ -1,5 +1,5 @@ import React from 'react' -import pkg from '../../../../package.json' +import pkg from '../../../package.json' import styles from './Titlebar.module.css' const Titlebar = () => ( diff --git a/src/renderer/src/components/Titlebar.module.css b/src/renderer/components/Titlebar.module.css similarity index 100% rename from src/renderer/src/components/Titlebar.module.css rename to src/renderer/components/Titlebar.module.css diff --git a/src/renderer/src/global.css b/src/renderer/global.css similarity index 100% rename from src/renderer/src/global.css rename to src/renderer/global.css diff --git a/src/renderer/src/images/cog.svg b/src/renderer/images/cog.svg similarity index 100% rename from src/renderer/src/images/cog.svg rename to src/renderer/images/cog.svg diff --git a/src/renderer/src/images/icon.icns b/src/renderer/images/icon.icns similarity index 100% rename from src/renderer/src/images/icon.icns rename to src/renderer/images/icon.icns diff --git a/src/renderer/src/images/icon.ico b/src/renderer/images/icon.ico similarity index 100% rename from src/renderer/src/images/icon.ico rename to src/renderer/images/icon.ico diff --git a/src/renderer/src/images/icon1024.png b/src/renderer/images/icon1024.png similarity index 100% rename from src/renderer/src/images/icon1024.png rename to src/renderer/images/icon1024.png diff --git a/src/renderer/src/images/rocket.svg b/src/renderer/images/rocket.svg similarity index 100% rename from src/renderer/src/images/rocket.svg rename to src/renderer/images/rocket.svg diff --git a/src/renderer/jest/App.test.jsx b/src/renderer/jest/App.test.jsx deleted file mode 100644 index d55e078..0000000 --- a/src/renderer/jest/App.test.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react' -import { render } from '@testing-library/react' -import AppProvider from '../store/AppProvider' -import App from './App' - -describe('App', () => { - it('renders correctly', () => { - const { container } = render( - - - - ) - expect(container.firstChild).toBeInTheDocument() - }) -}) diff --git a/src/renderer/jest/setup-test-env.js b/src/renderer/jest/setup-test-env.js deleted file mode 100644 index 264828a..0000000 --- a/src/renderer/jest/setup-test-env.js +++ /dev/null @@ -1 +0,0 @@ -import '@testing-library/jest-dom/extend-expect' diff --git a/src/renderer/next.config.js b/src/renderer/next.config.js index f000d6a..2156737 100644 --- a/src/renderer/next.config.js +++ b/src/renderer/next.config.js @@ -26,16 +26,12 @@ const withSvgr = (nextConfig = {}, nextComposePlugins = {}) => { module.exports = withSvgr({ webpack: config => { config.target = 'electron-renderer' - return config + }, + exportPathMap() { + return { + '/': { page: '/' }, + '/preferences': { page: '/preferences' } + } } - // exportPathMap() { - // // Let Next.js know where to find the entry page - // // when it's exporting the static bundle for the use - // // in the production version of your app - // return { - // '/': { page: '/' }, - // '/preferences': { page: '/preferences' } - // } - // } }) diff --git a/src/renderer/src/pages/_app.jsx b/src/renderer/pages/_app.jsx similarity index 85% rename from src/renderer/src/pages/_app.jsx rename to src/renderer/pages/_app.jsx index 07e4609..8436c55 100644 --- a/src/renderer/src/pages/_app.jsx +++ b/src/renderer/pages/_app.jsx @@ -1,7 +1,7 @@ import React, { useEffect } from 'react' import PropTypes from 'prop-types' import Router from 'next/router' -import { ipcRenderer } from 'electron' +// import { ipcRenderer } from 'electron' import '../global.css' import Layout from '../Layout' @@ -14,7 +14,7 @@ import Layout from '../Layout' export default function App({ Component, pageProps }) { useEffect(() => { - ipcRenderer.on('goTo', (evt, route) => { + global.ipcRenderer.on('goTo', (evt, route) => { Router.push(route) }) }, []) diff --git a/src/renderer/src/pages/index.jsx b/src/renderer/pages/index.jsx similarity index 100% rename from src/renderer/src/pages/index.jsx rename to src/renderer/pages/index.jsx diff --git a/src/renderer/src/pages/index.module.css b/src/renderer/pages/index.module.css similarity index 100% rename from src/renderer/src/pages/index.module.css rename to src/renderer/pages/index.module.css diff --git a/src/renderer/src/pages/preferences.jsx b/src/renderer/pages/preferences.jsx similarity index 83% rename from src/renderer/src/pages/preferences.jsx rename to src/renderer/pages/preferences.jsx index 2b592bf..f6a7af3 100644 --- a/src/renderer/src/pages/preferences.jsx +++ b/src/renderer/pages/preferences.jsx @@ -1,6 +1,6 @@ import React from 'react' import Link from 'next/link' -import Accounts from '../components/Preferences/Accounts' +import AccountsList from '../components/AccountsList' import styles from './preferences.module.css' const Preferences = () => ( @@ -11,7 +11,7 @@ const Preferences = () => ( × - + ) diff --git a/src/renderer/src/pages/preferences.module.css b/src/renderer/pages/preferences.module.css similarity index 100% rename from src/renderer/src/pages/preferences.module.css rename to src/renderer/pages/preferences.module.css diff --git a/src/renderer/src/store/AppProvider.jsx b/src/renderer/store/AppProvider.jsx similarity index 86% rename from src/renderer/src/store/AppProvider.jsx rename to src/renderer/store/AppProvider.jsx index 34d997d..819a918 100644 --- a/src/renderer/src/store/AppProvider.jsx +++ b/src/renderer/store/AppProvider.jsx @@ -1,15 +1,11 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import ms from 'ms' -import { ipcRenderer } from 'electron' +// import { ipcRenderer } from 'electron' import Store from 'electron-store' import { AppContext } from './createContext' -import { fetchData } from '../../../utils' -import { - refreshInterval, - conversions, - oceanTokenContract -} from '../../../config' +import { fetchData } from '../../utils' +import { refreshInterval, conversions, oceanTokenContract } from '../../config' // construct initial prices Map to get consistent // order for Ticker and Touchbar @@ -22,7 +18,7 @@ export default class AppProvider extends PureComponent { children: PropTypes.any.isRequired } - store = new Store() + store = process.env.NODE_ENV === 'test' ? new Store() : global.store state = { isLoading: true, @@ -42,12 +38,12 @@ export default class AppProvider extends PureComponent { async componentDidMount() { // listener for accent color - ipcRenderer.on('accent-color', (event, accentColor) => { + global.ipcRenderer.on('accent-color', (event, accentColor) => { this.setState({ accentColor }) }) // listener for touchbar - ipcRenderer.on('setCurrency', (evt, currency) => + global.ipcRenderer.on('setCurrency', (evt, currency) => this.state.toggleCurrencies(currency) ) @@ -103,7 +99,7 @@ export default class AppProvider extends PureComponent { })) ) - ipcRenderer.send('prices-updated', Array.from(newPrices)) // convert Map to array, ipc messages seem to kill it + global.ipcRenderer.send('prices-updated', Array.from(newPrices)) // convert Map to array, ipc messages seem to kill it this.setState({ prices: newPrices, priceChanges: newPriceChanges }) return newPrices } @@ -140,7 +136,7 @@ export default class AppProvider extends PureComponent { toggleCurrencies(currency) { const pricesNew = Array.from(this.state.prices) - ipcRenderer.send('currency-updated', pricesNew, currency) + global.ipcRenderer.send('currency-updated', pricesNew, currency) this.setState({ currency }) } diff --git a/src/renderer/src/store/createContext.jsx b/src/renderer/store/createContext.jsx similarity index 100% rename from src/renderer/src/store/createContext.jsx rename to src/renderer/store/createContext.jsx diff --git a/tests/Layout.test.jsx b/tests/Layout.test.jsx new file mode 100644 index 0000000..a6b445a --- /dev/null +++ b/tests/Layout.test.jsx @@ -0,0 +1,10 @@ +import React from 'react' +import { render } from '@testing-library/react' +import Layout from '../src/renderer/Layout' + +describe('Layout', () => { + it('renders correctly', () => { + const { container } = render(Hello) + expect(container.firstChild).toBeInTheDocument() + }) +}) diff --git a/src/renderer/jest/__fixtures__/context.js b/tests/__fixtures__/context.js similarity index 100% rename from src/renderer/jest/__fixtures__/context.js rename to tests/__fixtures__/context.js diff --git a/src/renderer/jest/__mocks__/file-mock.js b/tests/__mocks__/file-mock.js similarity index 100% rename from src/renderer/jest/__mocks__/file-mock.js rename to tests/__mocks__/file-mock.js diff --git a/src/renderer/jest/__mocks__/svgr-mock.js b/tests/__mocks__/svgr-mock.js similarity index 100% rename from src/renderer/jest/__mocks__/svgr-mock.js rename to tests/__mocks__/svgr-mock.js diff --git a/src/renderer/src/components/Preferences/Accounts/index.test.jsx b/tests/components/AccountsList.test.jsx similarity index 91% rename from src/renderer/src/components/Preferences/Accounts/index.test.jsx rename to tests/components/AccountsList.test.jsx index dc366c1..a8e69b0 100644 --- a/src/renderer/src/components/Preferences/Accounts/index.test.jsx +++ b/tests/components/AccountsList.test.jsx @@ -1,8 +1,8 @@ import React from 'react' import { render, fireEvent } from '@testing-library/react' -import { AppContext } from '../../../store/createContext' import { StateMock } from '@react-mock/state' -import Accounts from '.' +import { AppContext } from '../../src/renderer/store/createContext' +import Accounts from '../../src/renderer/components/AccountsList' describe('Accounts', () => { const ui = ( diff --git a/tests/components/Spinner.test.jsx b/tests/components/Spinner.test.jsx new file mode 100644 index 0000000..fac7358 --- /dev/null +++ b/tests/components/Spinner.test.jsx @@ -0,0 +1,10 @@ +import React from 'react' +import { render } from '@testing-library/react' +import Spinner from '../../src/renderer/components/Spinner' + +describe('Spinner', () => { + it('renders correctly', () => { + const { container } = render() + expect(container.firstChild).toBeInTheDocument() + }) +}) diff --git a/tests/jest.config.js b/tests/jest.config.js new file mode 100644 index 0000000..45e26dd --- /dev/null +++ b/tests/jest.config.js @@ -0,0 +1,32 @@ +module.exports = { + rootDir: '../', + transform: { + '^.+\\.jsx?$': 'babel-jest' + }, + moduleNameMapper: { + '.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy', + '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': + '/tests/__mocks__/file-mock.js', + '\\.svg': '/tests/__mocks__/svgr-mock.js' + }, + testMatch: ['**/?(*.)+(spec|test).jsx'], + testPathIgnorePatterns: [ + '/src/renderer/.next', + '/src/renderer/out', + '/node_modules', + '/build', + '/dist', + '/coverage' + ], + testURL: 'http://localhost', + setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'], + runner: '@jest-runner/electron', + testEnvironment: '@jest-runner/electron/environment', + coverageDirectory: '../../coverage/', + collectCoverage: true, + collectCoverageFrom: [ + '/src/renderer/**/*.jsx', + '!/dist', + '!**/node_modules/**' + ] +} diff --git a/src/renderer/jest/index.test.jsx b/tests/pages/index.test.jsx similarity index 80% rename from src/renderer/jest/index.test.jsx rename to tests/pages/index.test.jsx index a2adff5..5a79b3b 100644 --- a/src/renderer/jest/index.test.jsx +++ b/tests/pages/index.test.jsx @@ -1,8 +1,8 @@ import React from 'react' import { render, fireEvent } from '@testing-library/react' -import { AppContext } from '../store/createContext' -import context from './__fixtures__/context' -import Home from '.' +import { AppContext } from '../../src/renderer/store/createContext' +import context from '../__fixtures__/context' +import Home from '../../src/renderer/pages/index' describe('Home', () => { it('renders correctly', () => { diff --git a/src/renderer/jest/preferences.test.jsx b/tests/pages/preferences.test.jsx similarity index 73% rename from src/renderer/jest/preferences.test.jsx rename to tests/pages/preferences.test.jsx index 369408f..b8c72cc 100644 --- a/src/renderer/jest/preferences.test.jsx +++ b/tests/pages/preferences.test.jsx @@ -1,7 +1,7 @@ import React from 'react' import { render } from '@testing-library/react' -import { AppContext } from '../store/createContext' -import Preferences from '.' +import { AppContext } from '../../src/renderer/store/createContext' +import Preferences from '../../src/renderer/pages/preferences' describe('Preferences', () => { it('renders correctly', () => {