Skip to content

Commit

Permalink
Basic module tests (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrf1 authored Aug 16, 2021
1 parent eacb68a commit ce5f01f
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build": "yarn workspaces run build",
"presetup": "yarn clean",
"setup": "tsc --build",
"test": "export stage=DEV; yarn server test && yarn shared test",
"test": "export stage=DEV; yarn workspaces run test",
"riffraff": "node-riffraff-artifact"
},
"workspaces": [
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"presets": [
["@babel/preset-react",
{ "runtime": "automatic", "importSource": "@emotion/react" }
],
{ "runtime": "automatic", "importSource": "@emotion/react" }
],
["@emotion/babel-preset-css-prop"],
[
"@babel/preset-env",
Expand Down
5 changes: 5 additions & 0 deletions packages/modules/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
verbose: true,
};
8 changes: 5 additions & 3 deletions packages/modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "rollup --config",
"start": "rollup --config --watch",
"lint": "eslint 'src/**/*.{ts,tsx}'",
"storybook": "start-storybook -p 6006"
"storybook": "start-storybook -p 6006",
"test": "jest --silent"
},
"dependencies": {
"@babel/plugin-transform-react-jsx-compat": "^7.12.13",
Expand All @@ -27,12 +28,12 @@
"@sdc/shared": "1.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.13",
"@babel/core": "^7.15.0",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-numeric-separator": "^7.10.4",
"@babel/plugin-proposal-optional-chaining": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@babel/preset-typescript": "^7.15.0",
"@emotion/babel-preset-css-prop": "^11.2.0",
"@guardian/automat-deps": "^0.3.0",
"@guardian/node-riffraff-artifact": "^0.1.9",
Expand All @@ -52,6 +53,7 @@
"@testing-library/jest-dom": "^5.5.0",
"@testing-library/react": "^10.0.3",
"@types/jest": "^24.0.25",
"@types/react-dom": "17.0.2",
"babel-loader": "^8.0.6",
"chromatic": "^5.4.0",
"nodemon": "^2.0.4",
Expand Down
17 changes: 11 additions & 6 deletions packages/modules/src/hooks/useHasBeenSeen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ const useHasBeenSeen = (options: IntersectionObserverInit, debounce?: boolean):
observer.current.disconnect();
}

observer.current = new window.IntersectionObserver(intersectionCallback, options);
if (window.IntersectionObserver) {
observer.current = new window.IntersectionObserver(intersectionCallback, options);

const { current: currentObserver } = observer;
const { current: currentObserver } = observer;

if (node) {
currentObserver.observe(node);
}
if (node) {
currentObserver.observe(node);
}

return (): void => currentObserver.disconnect();
return (): void => currentObserver.disconnect();
} else {
// eslint-disable-next-line @typescript-eslint/no-empty-function
return (): void => {};
}
}, [node, options, intersectionCallback]);

return [hasBeenSeen, setNode];
Expand Down
18 changes: 18 additions & 0 deletions packages/modules/src/modules/epics/ContributionsEpic.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { render } from '@testing-library/react';
import { props as baseProps } from './utils/storybook';
import { ContributionsEpicUnvalidated as ContributionsEpic } from './ContributionsEpic';
import { EpicProps } from '@sdc/shared/types';

describe('ContributionsEpic', () => {
it('renders the epic', () => {
const heading = 'Epic';
const props: EpicProps = { ...baseProps, variant: { ...baseProps.variant, heading } };

const { getByText } = render(<ContributionsEpic {...props} />);

expect(getByText(heading)).toBeInTheDocument();
});
});
145 changes: 143 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.13.15.tgz#7e8eea42d0b64fda2b375b22d06c605222e848f4"
integrity sha512-ltnibHKR1VnrU4ymHyQ/CXtNXI6yZC0oJThyW78Hft8XndANwi+9H+UIklBDraIjFEJzw8wmcM427oDd9KS5wA==

"@babel/compat-data@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.15.0.tgz#2dbaf8b85334796cafbb0f5793a90a2fc010b176"
integrity sha512-0NqAC1IJE0S0+lL1SWFMxMkz1pKCNCjI4tr2Zx4LJSXxCLAdr6KyArnY+sno5m3yH9g737ygOyPABDsnXkpxiA==

"@babel/[email protected]":
version "7.12.9"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.9.tgz#fd450c4ec10cdbb980e2928b7aa7a28484593fc8"
Expand Down Expand Up @@ -105,7 +110,7 @@
semver "^6.3.0"
source-map "^0.5.0"

"@babel/core@^7.12.10", "@babel/core@^7.12.13", "@babel/core@^7.7.5":
"@babel/core@^7.12.10", "@babel/core@^7.7.5":
version "7.14.8"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.14.8.tgz#20cdf7c84b5d86d83fac8710a8bc605a7ba3f010"
integrity sha512-/AtaeEhT6ErpDhInbXmjHcUQXH0L0TEgscfcxk1qbOvLuKCa5aZT0SOOtDKFY96/CLROwbLSKyFor6idgNaU4Q==
Expand All @@ -126,6 +131,27 @@
semver "^6.3.0"
source-map "^0.5.0"

"@babel/core@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.15.0.tgz#749e57c68778b73ad8082775561f67f5196aafa8"
integrity sha512-tXtmTminrze5HEUPn/a0JtOzzfp0nk+UEXQ/tqIJo3WDGypl/2OFQEMll/zSFU8f/lfmfLXvTaORHF3cfXIQMw==
dependencies:
"@babel/code-frame" "^7.14.5"
"@babel/generator" "^7.15.0"
"@babel/helper-compilation-targets" "^7.15.0"
"@babel/helper-module-transforms" "^7.15.0"
"@babel/helpers" "^7.14.8"
"@babel/parser" "^7.15.0"
"@babel/template" "^7.14.5"
"@babel/traverse" "^7.15.0"
"@babel/types" "^7.15.0"
convert-source-map "^1.7.0"
debug "^4.1.0"
gensync "^1.0.0-beta.2"
json5 "^2.1.2"
semver "^6.3.0"
source-map "^0.5.0"

"@babel/generator@^7.12.11", "@babel/generator@^7.12.5", "@babel/generator@^7.14.8", "@babel/generator@^7.14.9":
version "7.14.9"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.14.9.tgz#23b19c597d38b4f7dc2e3fe42a69c88d9ecfaa16"
Expand All @@ -144,6 +170,15 @@
jsesc "^2.5.1"
source-map "^0.5.0"

"@babel/generator@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.15.0.tgz#a7d0c172e0d814974bad5aa77ace543b97917f15"
integrity sha512-eKl4XdMrbpYvuB505KTta4AV9g+wWzmVBW69tX0H2NwKVKd2YJbKgyK6M8j/rgLbmHOYJn6rUklV677nOyJrEQ==
dependencies:
"@babel/types" "^7.15.0"
jsesc "^2.5.1"
source-map "^0.5.0"

"@babel/helper-annotate-as-pure@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.14.5.tgz#7bf478ec3b71726d56a8ca5775b046fc29879e61"
Expand Down Expand Up @@ -187,6 +222,16 @@
browserslist "^4.14.5"
semver "^6.3.0"

"@babel/helper-compilation-targets@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.15.0.tgz#973df8cbd025515f3ff25db0c05efc704fa79818"
integrity sha512-h+/9t0ncd4jfZ8wsdAsoIxSa61qhBYlycXiHWqJaQBCXAhDCMbPRSMTGnZIkkmt1u4ag+UQmuqcILwqKzZ4N2A==
dependencies:
"@babel/compat-data" "^7.15.0"
"@babel/helper-validator-option" "^7.14.5"
browserslist "^4.16.6"
semver "^6.3.0"

"@babel/helper-create-class-features-plugin@^7.14.5", "@babel/helper-create-class-features-plugin@^7.14.6":
version "7.14.8"
resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.14.8.tgz#a6f8c3de208b1e5629424a9a63567f56501955fc"
Expand All @@ -199,6 +244,18 @@
"@babel/helper-replace-supers" "^7.14.5"
"@babel/helper-split-export-declaration" "^7.14.5"

"@babel/helper-create-class-features-plugin@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.15.0.tgz#c9a137a4d137b2d0e2c649acf536d7ba1a76c0f7"
integrity sha512-MdmDXgvTIi4heDVX/e9EFfeGpugqm9fobBVg/iioE8kueXrOHdRDe36FAY7SnE9xXLVeYCoJR/gdrBEIHRC83Q==
dependencies:
"@babel/helper-annotate-as-pure" "^7.14.5"
"@babel/helper-function-name" "^7.14.5"
"@babel/helper-member-expression-to-functions" "^7.15.0"
"@babel/helper-optimise-call-expression" "^7.14.5"
"@babel/helper-replace-supers" "^7.15.0"
"@babel/helper-split-export-declaration" "^7.14.5"

"@babel/helper-create-regexp-features-plugin@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.14.5.tgz#c7d5ac5e9cf621c26057722fb7a8a4c5889358c4"
Expand Down Expand Up @@ -295,6 +352,13 @@
dependencies:
"@babel/types" "^7.14.5"

"@babel/helper-member-expression-to-functions@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.15.0.tgz#0ddaf5299c8179f27f37327936553e9bba60990b"
integrity sha512-Jq8H8U2kYiafuj2xMTPQwkTBnEEdGKpT35lJEQsRRjnG0LW3neucsaMWLgKcwu3OHKNeYugfw+Z20BXBSEs2Lg==
dependencies:
"@babel/types" "^7.15.0"

"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.10.4", "@babel/helper-module-imports@^7.12.13", "@babel/helper-module-imports@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.14.5.tgz#6d1a44df6a38c957aa7c312da076429f11b422f3"
Expand Down Expand Up @@ -337,6 +401,20 @@
"@babel/traverse" "^7.13.13"
"@babel/types" "^7.13.14"

"@babel/helper-module-transforms@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.15.0.tgz#679275581ea056373eddbe360e1419ef23783b08"
integrity sha512-RkGiW5Rer7fpXv9m1B3iHIFDZdItnO2/BLfWVW/9q7+KqQSDY5kUfQEbzdXM1MVhJGcugKV7kRrNVzNxmk7NBg==
dependencies:
"@babel/helper-module-imports" "^7.14.5"
"@babel/helper-replace-supers" "^7.15.0"
"@babel/helper-simple-access" "^7.14.8"
"@babel/helper-split-export-declaration" "^7.14.5"
"@babel/helper-validator-identifier" "^7.14.9"
"@babel/template" "^7.14.5"
"@babel/traverse" "^7.15.0"
"@babel/types" "^7.15.0"

"@babel/helper-optimise-call-expression@^7.12.13":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.12.13.tgz#5c02d171b4c8615b1e7163f888c1c81c30a2aaea"
Expand Down Expand Up @@ -390,6 +468,16 @@
"@babel/traverse" "^7.14.5"
"@babel/types" "^7.14.5"

"@babel/helper-replace-supers@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.15.0.tgz#ace07708f5bf746bf2e6ba99572cce79b5d4e7f4"
integrity sha512-6O+eWrhx+HEra/uJnifCwhwMd6Bp5+ZfZeJwbqUTuqkhIT6YcRhiZCOOFChRypOIe0cV46kFrRBlm+t5vHCEaA==
dependencies:
"@babel/helper-member-expression-to-functions" "^7.15.0"
"@babel/helper-optimise-call-expression" "^7.14.5"
"@babel/traverse" "^7.15.0"
"@babel/types" "^7.15.0"

"@babel/helper-simple-access@^7.13.12":
version "7.13.12"
resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.13.12.tgz#dd6c538afb61819d205a012c31792a39c7a5eaf6"
Expand Down Expand Up @@ -506,6 +594,11 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.13.15.tgz#8e66775fb523599acb6a289e12929fa5ab0954d8"
integrity sha512-b9COtcAlVEQljy/9fbcMHpG+UIW9ReF+gpaxDHTlZd0c6/UU9ng8zdySAW9sRTzpvcdCHn6bUcbuYUgGzLAWVQ==

"@babel/parser@^7.15.0":
version "7.15.2"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.2.tgz#08d4ffcf90d211bf77e7cc7154c6f02d468d2b1d"
integrity sha512-bMJXql1Ss8lFnvr11TZDH4ArtwlAS5NG9qBmdiFW2UHHm6MVoR+GDc5XE2b9K938cyjc9O6/+vjjcffLDtfuDg==

"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining/-/plugin-bugfix-v8-spread-parameters-in-optional-chaining-7.14.5.tgz#4b467302e1548ed3b1be43beae2cc9cf45e0bb7e"
Expand Down Expand Up @@ -1125,6 +1218,15 @@
"@babel/helper-plugin-utils" "^7.14.5"
"@babel/plugin-syntax-typescript" "^7.14.5"

"@babel/plugin-transform-typescript@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.15.0.tgz#553f230b9d5385018716586fc48db10dd228eb7e"
integrity sha512-WIIEazmngMEEHDaPTx0IZY48SaAmjVWe3TRSX7cmJXn0bEv9midFzAjxiruOWYIVf5iQ10vFx7ASDpgEO08L5w==
dependencies:
"@babel/helper-create-class-features-plugin" "^7.15.0"
"@babel/helper-plugin-utils" "^7.14.5"
"@babel/plugin-syntax-typescript" "^7.14.5"

"@babel/plugin-transform-unicode-escapes@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.14.5.tgz#9d4bd2a681e3c5d7acf4f57fa9e51175d91d0c6b"
Expand Down Expand Up @@ -1251,7 +1353,7 @@
"@babel/plugin-transform-react-jsx-development" "^7.14.5"
"@babel/plugin-transform-react-pure-annotations" "^7.14.5"

"@babel/preset-typescript@^7.10.4", "@babel/preset-typescript@^7.12.7", "@babel/preset-typescript@^7.3.3", "@babel/preset-typescript@^7.8.3":
"@babel/preset-typescript@^7.12.7", "@babel/preset-typescript@^7.3.3", "@babel/preset-typescript@^7.8.3":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.14.5.tgz#aa98de119cf9852b79511f19e7f44a2d379bcce0"
integrity sha512-u4zO6CdbRKbS9TypMqrlGH7sd2TAJppZwn3c/ZRLeO/wGsbddxgbPDUZVNrie3JWYLQ9vpineKlsrWFvO6Pwkw==
Expand All @@ -1260,6 +1362,15 @@
"@babel/helper-validator-option" "^7.14.5"
"@babel/plugin-transform-typescript" "^7.14.5"

"@babel/preset-typescript@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.15.0.tgz#e8fca638a1a0f64f14e1119f7fe4500277840945"
integrity sha512-lt0Y/8V3y06Wq/8H/u0WakrqciZ7Fz7mwPDHWUJAXlABL5hiUG42BNlRXiELNjeWjO5rWmnNKlx+yzJvxezHow==
dependencies:
"@babel/helper-plugin-utils" "^7.14.5"
"@babel/helper-validator-option" "^7.14.5"
"@babel/plugin-transform-typescript" "^7.15.0"

"@babel/register@^7.12.1":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/register/-/register-7.14.5.tgz#d0eac615065d9c2f1995842f85d6e56c345f3233"
Expand Down Expand Up @@ -1338,6 +1449,21 @@
debug "^4.1.0"
globals "^11.1.0"

"@babel/traverse@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.15.0.tgz#4cca838fd1b2a03283c1f38e141f639d60b3fc98"
integrity sha512-392d8BN0C9eVxVWd8H6x9WfipgVH5IaIoLp23334Sc1vbKKWINnvwRpb4us0xtPaCumlwbTtIYNA0Dv/32sVFw==
dependencies:
"@babel/code-frame" "^7.14.5"
"@babel/generator" "^7.15.0"
"@babel/helper-function-name" "^7.14.5"
"@babel/helper-hoist-variables" "^7.14.5"
"@babel/helper-split-export-declaration" "^7.14.5"
"@babel/parser" "^7.15.0"
"@babel/types" "^7.15.0"
debug "^4.1.0"
globals "^11.1.0"

"@babel/types@^7.0.0", "@babel/types@^7.12.11", "@babel/types@^7.12.7", "@babel/types@^7.14.8", "@babel/types@^7.14.9", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4":
version "7.14.9"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.14.9.tgz#f2b19c3f2f77c5708d67fe8f6046e9cea2b5036d"
Expand All @@ -1363,6 +1489,14 @@
"@babel/helper-validator-identifier" "^7.14.8"
to-fast-properties "^2.0.0"

"@babel/types@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.15.0.tgz#61af11f2286c4e9c69ca8deb5f4375a73c72dcbd"
integrity sha512-OBvfqnllOIdX4ojTHpwZbpvz4j3EWyjkZEdmjH0/cgsd6QOdSgU8rLSk6ard/pcW7rlmjdVSX/AWOaORR1uNOQ==
dependencies:
"@babel/helper-validator-identifier" "^7.14.9"
to-fast-properties "^2.0.0"

"@bcoe/v8-coverage@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
Expand Down Expand Up @@ -3277,6 +3411,13 @@
dependencies:
"@types/react" "*"

"@types/[email protected]":
version "17.0.2"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.2.tgz#35654cf6c49ae162d5bc90843d5437dc38008d43"
integrity sha512-Icd9KEgdnFfJs39KyRyr0jQ7EKhq8U6CcHRMGAS45fp5qgUvxL3ujUCfWFttUK2UErqZNj97t9gsVPNAqcwoCg==
dependencies:
"@types/react" "*"

"@types/[email protected]":
version "11.0.5"
resolved "https://registry.yarnpkg.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-11.0.5.tgz#0d546261b4021e1f9d85b50401c0a42acb106087"
Expand Down

0 comments on commit ce5f01f

Please sign in to comment.