Skip to content
Snippets Groups Projects
Unverified Commit e9ca233f authored by Mauko Quiroga's avatar Mauko Quiroga
Browse files

Add Jest for testing

parent 2a0927b8
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
"flowtype",
"fp",
"import",
"jest",
"jsx-a11y",
"react",
],
......@@ -23,6 +24,7 @@
"airbnb",
"plugin:fp/recommended",
"plugin:flowtype/recommended",
"plugin:jest/recommended",
],
"settings": {
"react": {
......@@ -39,7 +41,7 @@
"import/no-unresolved": "off",
"indent": ["error", 4],
"max-nested-callbacks": ["error", 1],
"no-underscore-dangle": ["error", { "allow": ["__INIT_MATERIAL_UI__"] }],
"no-underscore-dangle": "error",
"quotes": ["error", "double", { "avoidEscape": false }],
"react/jsx-indent": ["error", 4, { checkAttributes: false, indentLogicalExpressions: true }],
"react/jsx-indent-props": ["error", 4],
......
......@@ -58,8 +58,8 @@ typings/
.env
# NextJS files
app/build
app/.next
.next
build
# OS X junk
.DS_Store
......@@ -12,10 +12,10 @@ module.exports = (api) => {
[
"module-resolver", {
alias: {
components: "./app/components",
lib: "./app/lib",
pages: "./app/pages",
styles: "./app/styles",
components: "./components",
lib: "./lib",
pages: "./pages",
styles: "./styles",
},
},
],
......
File moved
File moved
module.exports = {
moduleFileExtensions: ["js", "jsx"],
testMatch: ["**/tests/**/*.test.js?(x)"],
testPathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/node_modules/"],
}
import theme from "styles/theme"
import { SheetsRegistry } from "jss"
import { createMuiTheme, createGenerateClassName } from "@material-ui/core/styles"
// A theme with custom primary and secondary color.
// It's optional.
const theme = createMuiTheme({
typography: {
useNextVariants: true,
},
})
import { createGenerateClassName } from "@material-ui/core/styles"
function createPageContext() {
return {
......@@ -21,17 +14,4 @@ function createPageContext() {
}
}
export default function getPageContext() {
// Make sure to create a new context for every server-side request so that data
// isn't shared between connections (which would be bad).
if (!process.browser) {
return createPageContext()
}
// Reuse context on the client-side.
if (!global.__INIT_MATERIAL_UI__) {
global.__INIT_MATERIAL_UI__ = createPageContext()
}
return global.__INIT_MATERIAL_UI__
}
export default createPageContext
import createPageContext from "lib/createPageContext"
let pageContext
export default function getPageContext() {
// Make sure to create a new context for every server-side request so that data
// isn't shared between connections (which would be bad).
if (!process.browser) {
return createPageContext()
}
// Reuse context on the client-side.
if (!pageContext) {
pageContext = createPageContext()
}
return pageContext
}
File moved
File moved
This diff is collapsed.
......@@ -11,12 +11,13 @@
"keywords": [],
"license": "AGPL 3",
"scripts": {
"build": "next build app",
"start": "npm run build && env NODE_ENV=production node server.js",
"dev": "nodemon --ignore app/ server.js",
"build": "next build",
"dev": "nodemon --watch server.js server.js",
"prod": "npm run build && env NODE_ENV=production node server.js",
"style:check": "eslint -c .eslintrc --ext .js,.jsx --ignore-path .gitignore .",
"style:format": "npm run style:check -- --fix",
"style:rules": "eslint --print-config .eslintrc"
"style:rules": "eslint --print-config .eslintrc",
"test": "jest -c jest.config.js"
},
"dependencies": {
"@material-ui/core": "^3.9.3",
......@@ -42,6 +43,7 @@
"@babel/plugin-proposal-pipeline-operator": "^7.3.2",
"@babel/preset-flow": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.8.0",
"babel-plugin-flow-react-proptypes": "^25.1.0",
"babel-plugin-module-resolver": "^3.2.0",
"babel-plugin-wrap-in-js": "^1.1.1",
......@@ -50,8 +52,10 @@
"eslint-plugin-flowtype": "^3.7.0",
"eslint-plugin-fp": "^2.3.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.13.0",
"jest": "^24.8.0",
"nodemon": "^1.19.0"
}
}
File moved
File moved
......@@ -5,7 +5,7 @@ const cookieParser = require("cookie-parser")
const path = require("path")
const dev = process.env.NODE_ENV !== "production"
const app = next({ dev, dir: "./app" })
const app = next({ dev })
const handle = app.getRequestHandler()
const port = parseInt(process.env.PORT, 10) || 9001
......
File moved
import { createMuiTheme } from "@material-ui/core/styles"
const theme = createMuiTheme({
typography: {
useNextVariants: true,
},
})
export default theme
/* eslint-env jest */
import getPageContext from "./../../lib/getPageContext"
test("it works", () => {
const pageContext = getPageContext()
return expect(pageContext).toBe(3)
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment