diff --git a/.babelrc b/.babelrc index cc7ce7603..5f210a388 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,18 @@ { - "presets": ["next/babel"], + "env": { + "development": { + "presets": "next/babel" + }, + "production": { + "presets": "next/babel" + }, + "test": { + "presets": [ + ["env", { "modules": "commonjs" }], + "next/babel" + ] + } + }, "plugins": [ [ "lodash", diff --git a/__tests__/index.test.js b/__tests__/index.test.js new file mode 100644 index 000000000..6e9a7a543 --- /dev/null +++ b/__tests__/index.test.js @@ -0,0 +1,5 @@ +describe('Setting up jest', () => { + it('Runs tests', () => { + expect('foo').toEqual('foo'); + }); +}); diff --git a/package.json b/package.json index 49891c3fc..32044b442 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "test": "xo", - "lint": - "prettier 'utils/**/*.js' 'components/**/*.js' 'pages/**/*.js' 'lib/**/*.js' 'hocs/**/*.js' '*.js' --write --single-quote --print-width='80' --trailing-comma='all' && xo --fix", + "test": "xo && jest", + "lint": "prettier 'utils/**/*.js' 'components/**/*.js' 'pages/**/*.js' 'lib/**/*.js' 'hocs/**/*.js' '*.js' --write --single-quote --print-width='80' --trailing-comma='all' && xo --fix", "precommit": "lint-staged", "analyze": "cross-env ANALYZE=1 next build", "dev": "cross-env NODE_ENV=development node server.js", @@ -16,20 +15,40 @@ }, "xo": { "parser": "babel-eslint", - "extends": ["prettier", "prettier/react", "plugin:react/recommended"], - "env": ["browser", "node"], + "extends": [ + "prettier", + "prettier/react", + "plugin:react/recommended" + ], + "env": [ + "browser", + "node" + ], "rules": { "linebreak-style": 0, "react/display-name": 0, "react/prop-types": 0 }, "space:": 2, - "ignores": ["next.config.js"] + "ignores": [ + "next.config.js" + ], + "overrides": [ + { + "files": "**/__tests__/*.test.js", + "globals": [ + "describe", + "it", + "expect" + ] + } + ] }, "lint-staged": { "*.js": [ "prettier --write --single-quote --print-width=80 --trailing-comma=all", "xo", + "jest --findRelatedTests", "git add" ] }, @@ -68,6 +87,7 @@ "eslint-config-prettier": "^2.3.0", "eslint-plugin-react": "^7.1.0", "husky": "^0.14.3", + "jest": "^21.2.1", "lint-staged": "^4.0.2", "normalize-url": "1.9.1", "now": "8.3.10",