Skip to content
This repository has been archived by the owner on Nov 3, 2019. It is now read-only.

Commit

Permalink
Move Jest to root
Browse files Browse the repository at this point in the history
* Update babel.transforms to ignore global config files
* write some tests for MDXRenderer
  • Loading branch information
ChristopherBiscardi committed Oct 2, 2018
1 parent 1467eaa commit 3a93d01
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 8 deletions.
5 changes: 1 addition & 4 deletions .circleci/config.yml
Expand Up @@ -25,10 +25,7 @@ jobs:
paths:
- ~/.cache/yarn

- run: yarn workspace gatsby-mdx test
- run: yarn workspace babel-plugin-gather-exports test
- run: yarn workspace babel-plugin-pluck-imports test
- run: yarn workspace babel-plugin-pluck-exports test
- run: yarn test
- run: yarn lint
publish:
docker:
Expand Down
7 changes: 7 additions & 0 deletions babel.config.js
@@ -0,0 +1,7 @@
module.exports = {
env: {
test: {
presets: [["@babel/preset-env"], ["@babel/preset-react"]]
}
}
};
10 changes: 9 additions & 1 deletion package.json
Expand Up @@ -10,6 +10,7 @@
"precommit": "lint-staged",
"prepublish": "eslint .",
"publish-ci": "lerna publish -y --canary --preid ci --npm-tag=ci",
"test": "jest",
"lint": "eslint ."
},
"lint-staged": {
Expand All @@ -20,15 +21,22 @@
"*.{css,scss}": ["prettier --parser css --write", "git add"]
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^9.0.0",
"babel-jest": "^23.6.0",
"eslint": "^5.4.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-react": "^7.11.1",
"husky": "^0.14.3",
"jest": "^23.6.0",
"lerna": "^3.4.0",
"lint-staged": "^7.2.0",
"prettier": "^1.13.7"
"prettier": "^1.13.7",
"react-test-renderer": "^16.5.2"
},
"keywords": [
"gatsby",
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-gather-exports/index.test.js
Expand Up @@ -13,6 +13,7 @@ describe("babel-plugin-gather-exports", () => {
test("gathers all exports", () => {
const instance = new Plugin();
const result = babel.transform(testContents, {
configFile: false,
plugins: [instance.plugin],
presets: [require("@babel/preset-react")]
});
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-pluck-exports/index.test.js
Expand Up @@ -18,6 +18,7 @@ describe("babel-plugin-pluck-exports", () => {
test("plucks pageQuery", () => {
const instance = new Plugin();
const result = babel.transform(testContents, {
configFile: false,
plugins: [instance.plugin],
presets: [require("@babel/preset-react")]
});
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-pluck-imports/index.test.js
Expand Up @@ -18,6 +18,7 @@ describe("babel-plugin-pluck-imports", () => {
test("plucks imports", () => {
const instance = new Plugin();
const result = babel.transform(testContents, {
configFile: false,
plugins: [instance.plugin],
presets: [require("@babel/preset-react")]
});
Expand Down
67 changes: 67 additions & 0 deletions packages/gatsby-mdx/mdx-renderer.test.js
@@ -0,0 +1,67 @@
import React from "react";
import TestRenderer from "react-test-renderer";

import MDXRenderer from "./mdx-renderer";

describe("mdx-renderer", () => {
test("fails if there is no content (function body is empty)", () => {
/**
* spyOn is used to silence the following console warning in this test
```
console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6884
The above error occurred in one of your React components:
in Unknown (created by Context.Consumer)
in Unknown (created by Context.Consumer)
in Unknown
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries.
```
*/
const spy = jest.spyOn(console, "error").mockImplementation(() => {});
expect(() => TestRenderer.create(<MDXRenderer />)).toThrow(TypeError);
spy.mockRestore();
});

test("renders content if function body is passed in", () => {
const result = TestRenderer.create(
<MDXRenderer>{`return () => 2`}</MDXRenderer>
);
expect(result.toJSON()).toEqual("2");
});

test("fails to render React elements without scope", () => {
/**
* spyOn is used to silence the following console warning in this test
```
console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6884
The above error occurred in one of your React components:
in Unknown (created by Context.Consumer)
in Unknown (created by Context.Consumer)
in Unknown
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries.
```
*/
const spy = jest.spyOn(console, "error").mockImplementation(() => {});
expect(() => {
TestRenderer.create(
<MDXRenderer>{`return () => React.createElement('div')`}</MDXRenderer>
);
}).toThrow(ReferenceError);
spy.mockRestore();
});

test("renders React elements when scope is provided", () => {
const result = TestRenderer.create(
<MDXRenderer
scope={{ React: React }}
>{`return () => React.createElement('div')`}</MDXRenderer>
);

expect(result.toJSON()).toEqual({ type: "div", props: {}, children: null });
});
});
91 changes: 88 additions & 3 deletions yarn.lock
Expand Up @@ -53,6 +53,26 @@
semver "^5.4.1"
source-map "^0.5.0"

"@babel/core@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.1.2.tgz#f8d2a9ceb6832887329a7b60f9d035791400ba4e"
integrity sha512-IFeSSnjXdhDaoysIlev//UzHZbdEmm7D0EIH2qtse9xK7mXEZQpYjs2P00XlP1qYsYvid79p+Zgg6tz1mp6iVw==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.1.2"
"@babel/helpers" "^7.1.2"
"@babel/parser" "^7.1.2"
"@babel/template" "^7.1.2"
"@babel/traverse" "^7.1.0"
"@babel/types" "^7.1.2"
convert-source-map "^1.1.0"
debug "^3.1.0"
json5 "^0.5.0"
lodash "^4.17.10"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"

"@babel/generator@7.0.0-beta.44":
version "7.0.0-beta.44"
resolved "http://registry.npmjs.org/@babel/generator/-/generator-7.0.0-beta.44.tgz#c7e67b9b5284afcf69b309b50d7d37f3e5033d42"
Expand All @@ -75,6 +95,17 @@
source-map "^0.5.0"
trim-right "^1.0.1"

"@babel/generator@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.1.2.tgz#fde75c072575ce7abbd97322e8fef5bae67e4630"
integrity sha512-70A9HWLS/1RHk3Ck8tNHKxOoKQuSKocYgwDN85Pyl/RBduss6AKxUR7RIZ/lzduQMSYfWEM4DDBu6A+XGbkFig==
dependencies:
"@babel/types" "^7.1.2"
jsesc "^2.5.1"
lodash "^4.17.10"
source-map "^0.5.0"
trim-right "^1.0.1"

"@babel/helper-annotate-as-pure@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32"
Expand Down Expand Up @@ -270,6 +301,15 @@
"@babel/traverse" "^7.1.0"
"@babel/types" "^7.0.0"

"@babel/helpers@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.1.2.tgz#ab752e8c35ef7d39987df4e8586c63b8846234b5"
integrity sha512-Myc3pUE8eswD73aWcartxB16K6CGmHDv9KxOmD2CeOs/FaEAQodr3VYGmlvOmog60vNQ2w8QbatuahepZwrHiA==
dependencies:
"@babel/template" "^7.1.2"
"@babel/traverse" "^7.1.0"
"@babel/types" "^7.1.2"

"@babel/highlight@7.0.0-beta.44":
version "7.0.0-beta.44"
resolved "http://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.44.tgz#18c94ce543916a80553edcdcf681890b200747d5"
Expand All @@ -293,6 +333,11 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.0.tgz#a7cd42cb3c12aec52e24375189a47b39759b783e"
integrity sha512-SmjnXCuPAlai75AFtzv+KCBcJ3sDDWbIn+WytKw1k+wAtEy6phqI2RqKh/zAnw53i1NR8su3Ep/UoqaKcimuLg==

"@babel/parser@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.2.tgz#85c5c47af6d244fab77bce6b9bd830e38c978409"
integrity sha512-x5HFsW+E/nQalGMw7hu+fvPqnBeBaIr0lWJ2SG0PPL2j+Pm9lYvCrsZJGIgauPIENx0v10INIyFjmSNUD/gSqQ==

"@babel/plugin-proposal-async-generator-functions@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.1.0.tgz#41c1a702e10081456e23a7b74d891922dd1bb6ce"
Expand Down Expand Up @@ -676,7 +721,7 @@
core-js "^2.5.7"
regenerator-runtime "^0.11.1"

"@babel/preset-env@^7.0.0":
"@babel/preset-env@^7.0.0", "@babel/preset-env@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.1.0.tgz#e67ea5b0441cfeab1d6f41e9b5c79798800e8d11"
integrity sha512-ZLVSynfAoDHB/34A17/JCZbyrzbQj59QC1Anyueb4Bwjh373nVPq5/HMph0z+tCmcDjXDe+DlKQq9ywQuvWrQg==
Expand Down Expand Up @@ -760,6 +805,15 @@
"@babel/parser" "^7.1.0"
"@babel/types" "^7.0.0"

"@babel/template@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.1.2.tgz#090484a574fef5a2d2d7726a674eceda5c5b5644"
integrity sha512-SY1MmplssORfFiLDcOETrW7fCLl+PavlwMh92rrGcikQaRq4iWPVH0MpwPpY3etVMx6RnDjXtr6VZYr/IbP/Ag==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/parser" "^7.1.2"
"@babel/types" "^7.1.2"

"@babel/traverse@7.0.0-beta.44":
version "7.0.0-beta.44"
resolved "http://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.44.tgz#a970a2c45477ad18017e2e465a0606feee0d2966"
Expand Down Expand Up @@ -809,6 +863,15 @@
lodash "^4.17.10"
to-fast-properties "^2.0.0"

"@babel/types@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.1.2.tgz#183e7952cf6691628afdc2e2b90d03240bac80c0"
integrity sha512-pb1I05sZEKiSlMUV9UReaqsCPUpgbHHHu2n1piRm7JkuBkm6QxcaIzKu6FMnMtCbih/cEYTR+RGYYC96Yk9HAg==
dependencies:
esutils "^2.0.2"
lodash "^4.17.10"
to-fast-properties "^2.0.0"

"@contentful/axios@^0.18.0":
version "0.18.0"
resolved "https://registry.yarnpkg.com/@contentful/axios/-/axios-0.18.0.tgz#576e0e6047411a66971e82d40688a8c795e62f27"
Expand Down Expand Up @@ -2368,7 +2431,7 @@ babel-code-frame@6.26.0, babel-code-frame@^6.22.0, babel-code-frame@^6.26.0:
esutils "^2.0.2"
js-tokens "^3.0.2"

babel-core@7.0.0-bridge.0:
babel-core@7.0.0-bridge.0, babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==
Expand Down Expand Up @@ -10601,7 +10664,7 @@ jest-worker@^23.2.0:
dependencies:
merge-stream "^1.0.1"

jest@^23.4.2:
jest@^23.4.2, jest@^23.6.0:
version "23.6.0"
resolved "https://registry.yarnpkg.com/jest/-/jest-23.6.0.tgz#ad5835e923ebf6e19e7a1d7529a432edfee7813d"
integrity sha512-lWzcd+HSiqeuxyhG+EnZds6iO3Y3ZEnMrfZq/OTGvF/C+Z4fPMCdhWTGSAiO2Oym9rbEXfwddHhh6jqrTF3+Lw==
Expand Down Expand Up @@ -14801,6 +14864,11 @@ react-is@^16.3.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.5.1.tgz#c6e8734fd548a22e1cef4fd0833afbeb433b85ee"
integrity sha512-Q7S+9y2lJA9oJCMqLt045f+kLRhsMLA1wW2DAGXA6b7wcTQRHnUDMc5oR49tn0Z4swvnfV+/t8iZFXY74IQmpA==

react-is@^16.5.2:
version "16.5.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.5.2.tgz#e2a7b7c3f5d48062eb769fcb123505eb928722e3"
integrity sha512-hSl7E6l25GTjNEZATqZIuWOgSnpXb3kD0DVCujmg46K5zLxsbiKaaT6VO9slkSBDPZfYs30lwfJwbOFOnoEnKQ==

react-lifecycles-compat@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
Expand Down Expand Up @@ -14849,6 +14917,16 @@ react-smooshpack@0.0.49:
rollup-plugin-scss "^0.4.0"
smooshpack "^0.0.49"

react-test-renderer@^16.5.2:
version "16.5.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.5.2.tgz#92e9d2c6f763b9821b2e0b22f994ee675068b5ae"
integrity sha512-AGbJYbCVx1J6jdUgI4s0hNp+9LxlgzKvXl0ROA3DHTrtjAr00Po1RhDZ/eAq2VC/ww8AHgpDXULh5V2rhEqqJg==
dependencies:
object-assign "^4.1.1"
prop-types "^15.6.2"
react-is "^16.5.2"
schedule "^0.5.0"

react-typography@^0.16.13:
version "0.16.13"
resolved "https://registry.yarnpkg.com/react-typography/-/react-typography-0.16.13.tgz#94bdd2a9448823bc74d8ebf7465d86c7dbe20dcf"
Expand Down Expand Up @@ -15829,6 +15907,13 @@ schedule@^0.4.0:
dependencies:
object-assign "^4.1.1"

schedule@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/schedule/-/schedule-0.5.0.tgz#c128fffa0b402488b08b55ae74bb9df55cc29cc8"
integrity sha512-HUcJicG5Ou8xfR//c2rPT0lPIRR09vVvN81T9fqfVgBmhERUbDEQoYKjpBxbueJnCPpSu2ujXzOnRQt6x9o/jw==
dependencies:
object-assign "^4.1.1"

schema-utils@^0.4.0, schema-utils@^0.4.4, schema-utils@^0.4.5:
version "0.4.7"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187"
Expand Down

0 comments on commit 3a93d01

Please sign in to comment.