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" ] }; 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 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__", 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", 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/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 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}`, 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) + }); +}); 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"; 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";