From d8d15f45b0d8a50f88896c1cc58b5adcf7ab8340 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Mon, 13 Apr 2020 14:38:22 -0700 Subject: [PATCH 1/9] chore: move polyfills to scripts Signed-off-by: Mike Murray --- package/{config/test-polyfills.js => scripts/testPolyfills.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename package/{config/test-polyfills.js => scripts/testPolyfills.js} (100%) diff --git a/package/config/test-polyfills.js b/package/scripts/testPolyfills.js similarity index 100% rename from package/config/test-polyfills.js rename to package/scripts/testPolyfills.js From 75dcfa09ea144973324107d2719e83c2b203e2cd Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Mon, 13 Apr 2020 14:39:34 -0700 Subject: [PATCH 2/9] fix: move test setup to scripts and import required modules Signed-off-by: Mike Murray --- package/scripts/setupTests.js | 9 +++++++++ package/src/test-utils/setupTests.js | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 package/scripts/setupTests.js delete mode 100644 package/src/test-utils/setupTests.js diff --git a/package/scripts/setupTests.js b/package/scripts/setupTests.js new file mode 100644 index 0000000..fe36a49 --- /dev/null +++ b/package/scripts/setupTests.js @@ -0,0 +1,9 @@ +// Add async/await features +// eslint-disable-next-line node/no-extraneous-require +require("regenerator-runtime/runtime"); + +// add some helpful assertions +require("@testing-library/jest-dom/extend-expect"); + +// Polyfill fetch +require("unfetch/polyfill"); diff --git a/package/src/test-utils/setupTests.js b/package/src/test-utils/setupTests.js deleted file mode 100644 index 2efd787..0000000 --- a/package/src/test-utils/setupTests.js +++ /dev/null @@ -1,8 +0,0 @@ -// // Add async/await features -// import "regenerator-runtime/runtime"; - -// // add some helpful assertions -import "@testing-library/jest-dom/extend-expect"; - -// // Polyfill fetch -// import "unfetch/polyfill"; From e864ea762cdb0bd3f519894a7abafc6c3e6697a1 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Mon, 13 Apr 2020 14:40:06 -0700 Subject: [PATCH 3/9] fix: update paths Signed-off-by: Mike Murray --- jest.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jest.config.js b/jest.config.js index 412b99c..892550f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,9 +3,9 @@ const config = require("./package/config/jest.config"); module.exports = { ...config, setupFiles: [ - "/package/config/test-polyfills.js" + "/package/scripts/testPolyfills.js" ], setupFilesAfterEnv: [ - "/package/src/test-utils/setupTests.js" + "/package/scripts/setupTests.js" ] }; From 4fb3cb5ebe614536ce7db75f41b9e9a66dc0fdfc Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Mon, 13 Apr 2020 14:40:40 -0700 Subject: [PATCH 4/9] fix: don't copy test-utils, babel handles it Signed-off-by: Mike Murray --- package/bin/build-plugin | 1 - 1 file changed, 1 deletion(-) diff --git a/package/bin/build-plugin b/package/bin/build-plugin index 15f8c73..51a9c2a 100755 --- a/package/bin/build-plugin +++ b/package/bin/build-plugin @@ -13,7 +13,6 @@ cp -r bin dist cp -r config dist cp -r scripts dist cp -r src/graphql dist -cp -r src/test-utils dist cp package.json dist cp README.md dist cp LICENSE dist From 4f8f6a239460aaefac8e66335977eef30905e0a1 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Mon, 13 Apr 2020 14:40:53 -0700 Subject: [PATCH 5/9] fix: use babel env Signed-off-by: Mike Murray --- package/config/babel.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/config/babel.config.js b/package/config/babel.config.js index 2bb50b9..3cddae1 100644 --- a/package/config/babel.config.js +++ b/package/config/babel.config.js @@ -73,7 +73,7 @@ module.exports = function (api) { ]; let ignore; - if (process.env.NODE_ENV === "production") { + if (process.env.BABEL_ENV === "production") { ignore = [ "**/*.test.js", "__snapshots__", From 153b7c054f24df67e86b4b58705807a0be3c8b49 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Mon, 13 Apr 2020 14:41:18 -0700 Subject: [PATCH 6/9] fix: update paths and ignores Signed-off-by: Mike Murray --- package/config/jest.config.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package/config/jest.config.js b/package/config/jest.config.js index 78365ee..2c08bba 100644 --- a/package/config/jest.config.js +++ b/package/config/jest.config.js @@ -9,17 +9,18 @@ module.exports = { "graphql" ], setupFiles: [ - "/node_modules/@reactioncommerce/admin-core/config/test-polyfills.js" + "/node_modules/@reactioncommerce/admin-core/scripts/testPolyfills.js" ], setupFilesAfterEnv: [ - "/node_modules/@reactioncommerce/admin-core/test-utils/setupTests.js" + "/node_modules/@reactioncommerce/admin-core/scripts/setupTests.js" ], testPathIgnorePatterns: [ "/config/", "/reports/", "/bin/", "/dist/", - "/node_modules/" + "/node_modules/", + "/package/dist/" ], transform: { "\\.(gql|graphql)$": "@jagi/jest-transform-graphql", From 2c5d22daee2429b597828fe0d4f9e0f630f778fe Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Tue, 14 Apr 2020 09:36:51 -0700 Subject: [PATCH 7/9] fix: call register routes Signed-off-by: Mike Murray --- package/src/lib/core/routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/src/lib/core/routes.js b/package/src/lib/core/routes.js index 6703d5e..1a6cdfd 100644 --- a/package/src/lib/core/routes.js +++ b/package/src/lib/core/routes.js @@ -36,7 +36,7 @@ export function registerRoute(route) { * @returns {undefined} */ export function registerSetting(route) { - routes.push({ + registerRoute({ ...route, path: `/settings/${route.name}`, href: `/settings/${route.name || route.href || route.path}`, From ec142c0769e395234c4673e37d1d86b78bedc002 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Tue, 14 Apr 2020 09:47:36 -0700 Subject: [PATCH 8/9] fix: remove unfetch polyfill fron apollo init file Signed-off-by: Mike Murray --- package/src/lib/graphql/initApollo.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/package/src/lib/graphql/initApollo.js b/package/src/lib/graphql/initApollo.js index f2055d8..bc2a5f1 100644 --- a/package/src/lib/graphql/initApollo.js +++ b/package/src/lib/graphql/initApollo.js @@ -1,7 +1,5 @@ import { ApolloClient } from "apollo-client"; import { ApolloLink } from "apollo-link"; -// Polyfill fetch -import "unfetch/polyfill"; import { HttpLink } from "apollo-link-http"; import { InMemoryCache } from "apollo-cache-inmemory"; From 8afca9dc9c41ad2e2b30a0a690b4420a6f5b39c6 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Tue, 14 Apr 2020 09:47:52 -0700 Subject: [PATCH 9/9] test: add routes api test Signed-off-by: Mike Murray --- package/src/lib/core/routes.test.js | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 package/src/lib/core/routes.test.js diff --git a/package/src/lib/core/routes.test.js b/package/src/lib/core/routes.test.js new file mode 100644 index 0000000..3ab9ca2 --- /dev/null +++ b/package/src/lib/core/routes.test.js @@ -0,0 +1,47 @@ +/* eslint-disable react/no-multi-comp */ +/* eslint-disable react/display-name */ +import React from "react"; +import { registerRoute, registerSetting, routes, defaultRouteGroups } from "./routes"; + +beforeEach(() => { + // Clear the routes array for each test + routes.splice(0, routes.length); +}); + +test("should register a route", () => { + registerRoute({ + navigationItemLabel: "Test", + path: "/test", + MainComponent: () => (Test Component) + }); + + expect(routes.length).toEqual(1); + expect(routes[0].navigationItemLabel).toEqual("Test"); + expect(typeof routes[0].MainComponent).toEqual("function"); + expect(routes[0]).toEqual({ + priority: expect.any(Number), + navigationItemLabel: "Test", + path: "/test", + MainComponent: expect.any(Function) + }); +}); + +test("should register a setting route", () => { + registerSetting({ + name: "test-setting", + navigationItemLabel: "Test Setting", + MainComponent: () => (Test Component) + }); + + expect(routes.length).toEqual(1); + + expect(routes[0]).toEqual({ + priority: expect.any(Number), + name: "test-setting", + group: defaultRouteGroups.settings, + navigationItemLabel: "Test Setting", + path: "/settings/test-setting", + href: "/settings/test-setting", + MainComponent: expect.any(Function) + }); +});