Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] TESTS #63

Open
wants to merge 50 commits into
base: feature-tests
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8cadde2
(meta) add husky pre-commit test hook, jest + nyc + chai
f3rno Mar 6, 2020
e2843c9
(manifest) bump to 3.0.6
f3rno Mar 6, 2020
705b64e
(refactor) mild linter/style tweaks in scripts/test.js, add --no-watc…
f3rno Mar 6, 2020
1748bfb
(meta) npm update
f3rno Mar 6, 2020
82f91de
(meta) manually update remaining dependencies
f3rno Mar 6, 2020
e21c1b3
(gitignore) add vim session file
f3rno Mar 6, 2020
1d7ecf1
(fix) new linter errors, react-scripts start upgrade
f3rno Mar 6, 2020
d235679
(fix) eslint config
f3rno Mar 6, 2020
a0eff00
(fix) get jest running
f3rno Mar 6, 2020
78e703f
(refactor) update scripts/start.js, forgot to add in older commit
f3rno Mar 6, 2020
40058af
(feature) add first tests with enzyme
f3rno Mar 18, 2020
b8db769
(manifest) downgrade to last release version 3.0.5
f3rno Mar 26, 2020
413d8ca
(fix) add missing empty unit script to manifest
f3rno Mar 26, 2020
955db32
remove old db
Mar 16, 2020
88e72a6
fix: remove on activate
Mar 20, 2020
5d4f20a
(manifest) bump with lockfile
f3rno Mar 27, 2020
d1627bd
updated webpack config
Mar 27, 2020
ab9ee74
add algo orders table test
Mar 27, 2020
52bfdf0
add snapshot
Mar 27, 2020
59c9e6e
fix default_value issue
Mar 27, 2020
0cc2784
fixed default value
Mar 27, 2020
a0f8c07
add redux mock store
Apr 1, 2020
14c594a
settings test
Apr 1, 2020
00b50a2
add snapshot
Apr 1, 2020
3679a73
update settings test
Apr 3, 2020
2cb03b1
submitApiKeyModal
Apr 3, 2020
0565f86
submitapikey modal
Apr 3, 2020
6753e4a
(manifest) add new dependecies
Apr 7, 2020
d46caa9
update algo orders table test
Apr 7, 2020
cd92c11
add mock data
Apr 7, 2020
1781cdb
(feature) require api credentials
Apr 7, 2020
9802ab5
(feature) integrate settings test with test enttis
Apr 7, 2020
170b8af
(feature) test entities
Apr 7, 2020
c635272
update algoorderstable test
Apr 9, 2020
1cefd6c
add new classes
Apr 9, 2020
992e206
add new tests
Apr 9, 2020
7333a70
add new test
Apr 9, 2020
8914770
add new classes
Apr 9, 2020
1ee4b59
delete testEntities
Apr 9, 2020
68f4e80
remove testentities
Apr 9, 2020
96ec7d8
CreateNewLayoutModal
Apr 10, 2020
98c12b4
add cypress
Apr 14, 2020
27b9467
add cy script
Apr 14, 2020
b1640f0
add market specs
Apr 16, 2020
383e6c9
add example.json
Apr 16, 2020
dbbdf46
add ga
Apr 17, 2020
4d60087
react-ga
Apr 17, 2020
9dbb5b0
integrate with GA
Apr 17, 2020
8104385
add react joyride
Apr 21, 2020
2bcde54
add joyride
Apr 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

12 changes: 10 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"parser": "babel-eslint",
"extends": [
"airbnb"
"airbnb",
"eslint:recommended",
"plugin:react/recommended"
],
"rules": {
"jsx-quotes": ["error", "prefer-single"],
Expand All @@ -19,10 +21,16 @@
"jsx-a11y/no-static-element-interactions": 0,
"jsx-a11y/no-noninteractive-element-interactions": 0,
"jsx-a11y/label-has-for": 0,
"jsx-a11y/control-has-associated-label": 0,
"no-plusplus": 0,
"react/prefer-stateless-function": 0,
"no-nested-ternary": 0,
"import/prefer-default-export": 0
"import/prefer-default-export": 0,
"comma-dangle": ["error", "always-multiline"],
"arrow-parens": [2, "as-needed", { "requireForBlockBody": true }],
"react/static-property-placement": ["error", "static public field"],
"react/state-in-constructor": 0,
"react/jsx-props-no-spreading": 0
},
"settings": {
"import/resolver": {
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ yarn.lock
todo
/db
/logs/*.log
tags

Session.vim
.undodir
coverage
66 changes: 66 additions & 0 deletions config/getHttpsConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const chalk = require('react-dev-utils/chalk');
const paths = require('./paths');

// Ensure the certificate and key provided are valid and if not
// throw an easy to debug error
function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
let encrypted;
try {
// publicEncrypt will throw an error with an invalid cert
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
} catch (err) {
throw new Error(
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
);
}

try {
// privateDecrypt will throw an error with an invalid key
crypto.privateDecrypt(key, encrypted);
} catch (err) {
throw new Error(
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
err.message
}`
);
}
}

// Read file and throw an error if it doesn't exist
function readEnvFile(file, type) {
if (!fs.existsSync(file)) {
throw new Error(
`You specified ${chalk.cyan(
type
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`
);
}
return fs.readFileSync(file);
}

// Get the https config
// Return cert files if provided in env, otherwise just true or false
function getHttpsConfig() {
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
const isHttps = HTTPS === 'true';

if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
const config = {
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
};

validateKeyAndCerts({ ...config, keyFile, crtFile });
return config;
}
return isHttps;
}

module.exports = getHttpsConfig;
60 changes: 23 additions & 37 deletions config/paths.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@


const path = require('path')
const fs = require('fs')
const url = require('url')
const path = require('path');
const fs = require('fs');
const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd())
const resolveApp = relativePath => path.resolve(appDirectory, relativePath)

const envPublicUrl = process.env.PUBLIC_URL

function ensureSlash(inputPath, needsSlash) {
const hasSlash = inputPath.endsWith('/')
if (hasSlash && !needsSlash) {
return inputPath.substr(0, inputPath.length - 1)
} if (!hasSlash && needsSlash) {
return `${inputPath}/`
}
return inputPath

}

const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);

// We use `PUBLIC_URL` environment variable or "homepage" field to infer
// "public path" at which the app is served.
// Webpack needs to know it to put the right <script> hrefs into HTML even in
// webpack needs to know it to put the right <script> hrefs into HTML even in
// single-page apps that may serve index.html for nested URLs like /todos/42.
// We can't use a relative path in HTML because we don't want to load something
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson)
const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/')
return ensureSlash(servedUrl, true)
}
const publicUrlOrPath = getPublicUrlOrPath(
process.env.NODE_ENV === 'development',
require(resolveApp('package.json')).homepage,
process.env.PUBLIC_URL
);

const moduleFileExtensions = [
'web.mjs',
Expand All @@ -48,18 +31,20 @@ const moduleFileExtensions = [
'json',
'web.jsx',
'jsx',
]
];

// Resolve file paths in the same order as webpack
const resolveModule = (resolveFn, filePath) => {
const extension = moduleFileExtensions.find(extension => fs.existsSync(resolveFn(`${filePath}.${extension}`)))
const extension = moduleFileExtensions.find(extension =>
fs.existsSync(resolveFn(`${filePath}.${extension}`))
);

if (extension) {
return resolveFn(`${filePath}.${extension}`)
return resolveFn(`${filePath}.${extension}`);
}

return resolveFn(`${filePath}.js`)
}
return resolveFn(`${filePath}.js`);
};

// config after eject: we're in ./config/
module.exports = {
Expand All @@ -77,8 +62,9 @@ module.exports = {
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
proxySetup: resolveApp('src/setupProxy.js'),
appNodeModules: resolveApp('node_modules'),
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json')),
}
publicUrlOrPath,
};



module.exports.moduleFileExtensions = moduleFileExtensions
module.exports.moduleFileExtensions = moduleFileExtensions;
5 changes: 2 additions & 3 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = function(webpackEnv) {
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
const publicUrl = isEnvProduction
? publicPath.slice(0, -1)
? paths.publicUrlOrPath.slice(0, -1)
: isEnvDevelopment && '';
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);
Expand Down Expand Up @@ -597,9 +597,8 @@ module.exports = function(webpackEnv) {
new WorkboxWebpackPlugin.GenerateSW({
clientsClaim: true,
exclude: [/\.map$/, /asset-manifest\.json$/],
importWorkboxFrom: 'cdn',
navigateFallback: publicUrl + '/index.html',
navigateFallbackBlacklist: [
navigateFallbackDenylist: [
// Exclude URLs starting with /_, as they're likely an API call
new RegExp('^/_'),
// Exclude URLs containing a dot, as they're likely a resource in
Expand Down
82 changes: 53 additions & 29 deletions config/webpackDevServer.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use strict';
const fs = require('fs')
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware')
const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware')
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware')
const ignoredFiles = require('react-dev-utils/ignoredFiles')
const redirectServedPath = require('react-dev-utils/redirectServedPathMiddleware')
const paths = require('./paths')
const getHttpsConfig = require('./getHttpsConfig')

const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
const ignoredFiles = require('react-dev-utils/ignoredFiles');
const paths = require('./paths');
const fs = require('fs');
const host = process.env.HOST || '0.0.0.0'
const sockHost = process.env.WDS_SOCKET_HOST
const sockPath = process.env.WDS_SOCKET_PATH // default: '/sockjs-node'
const sockPort = process.env.WDS_SOCKET_PORT

const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const host = process.env.HOST || '0.0.0.0';

module.exports = function(proxy, allowedHost) {
module.exports = function (proxy, allowedHost) {
return {
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
// websites from potentially accessing local content through DNS rebinding:
Expand Down Expand Up @@ -43,24 +45,39 @@ module.exports = function(proxy, allowedHost) {
// Instead, we establish a convention that only files in `public` directory
// get served. Our build script will copy `public` into the `build` folder.
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
// Note that we only recommend to use `public` folder as an escape hatch
// for files like `favicon.ico`, `manifest.json`, and libraries that are
// for some reason broken when imported through Webpack. If you just want to
// for some reason broken when imported through webpack. If you just want to
// use an image, put it in `src` and `import` it from JavaScript instead.
contentBase: paths.appPublic,
contentBasePublicPath: paths.publicUrlOrPath,
// By default files from `contentBase` will not trigger a page reload.
watchContentBase: true,
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
// Enable hot reloading server. It will provide WDS_SOCKET_PATH endpoint
// for the WebpackDevServer client so it can learn when the files were
// updated. The WebpackDevServer client is included as an entry point
// in the Webpack development configuration. Note that only changes
// in the webpack development configuration. Note that only changes
// to CSS are currently hot reloaded. JS changes will refresh the browser.
hot: true,
// It is important to tell WebpackDevServer to use the same "root" path
// as we specified in the config. In development, we always serve from /.
publicPath: '/',
// Use 'ws' instead of 'sockjs-node' on server since we're using native
// websockets in `webpackHotDevClient`.
transportMode: 'ws',
// Prevent a WS client from getting injected as we're already including
// `webpackHotDevClient`.
injectClient: false,
// Enable custom sockjs pathname for websocket connection to hot reloading server.
// Enable custom sockjs hostname, pathname and port for websocket connection
// to hot reloading server.
sockHost,
sockPath,
sockPort,
// It is important to tell WebpackDevServer to use the same "publicPath" path as
// we specified in the webpack config. When homepage is '.', default to serving
// from the root.
// remove last slash so user can land on `/test` instead of `/test/`
publicPath: paths.publicUrlOrPath.slice(0, -1),
// WebpackDevServer is noisy by default so we emit custom message instead
// by listening to the compiler events with `compiler.hooks[...].tap` calls above.
quiet: true,
Expand All @@ -71,34 +88,41 @@ module.exports = function(proxy, allowedHost) {
watchOptions: {
ignored: ignoredFiles(paths.appSrc),
},
// Enable HTTPS if the HTTPS environment variable is set to 'true'
https: protocol === 'https',
https: getHttpsConfig(),
host,
overlay: false,
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebook/create-react-app/issues/387.
disableDotRule: true,
index: paths.publicUrlOrPath,
},
public: allowedHost,
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
proxy,
before(app, server) {
// Keep `evalSourceMapMiddleware` and `errorOverlayMiddleware`
// middlewares before `redirectServedPath` otherwise will not have any effect
// This lets us fetch source contents from webpack for the error overlay
app.use(evalSourceMapMiddleware(server))
// This lets us open files from the runtime error overlay.
app.use(errorOverlayMiddleware())

if (fs.existsSync(paths.proxySetup)) {
// This registers user provided middleware for proxy reasons
require(paths.proxySetup)(app);
require(paths.proxySetup)(app)
}

// This lets us fetch source contents from webpack for the error overlay
app.use(evalSourceMapMiddleware(server));
// This lets us open files from the runtime error overlay.
app.use(errorOverlayMiddleware());
},
after(app) {
// Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
app.use(redirectServedPath(paths.publicUrlOrPath))

// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// We do this in development to avoid hitting the production cache if
// it used the same host and port.
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
app.use(noopServiceWorkerMiddleware());
app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath))
},
};
};
}
}
4 changes: 4 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"video": false,
"screenshotOnRunFailure": false
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Loading