@contentful/react-apps-toolkit 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ var jsx_runtime_1 = require("react/jsx-runtime");
19
19
  var react_1 = __importDefault(require("react"));
20
20
  var app_sdk_1 = require("@contentful/app-sdk");
21
21
  exports.SDKContext = react_1.default.createContext({ sdk: null });
22
+ var DELAY_TIMEOUT = 4 * 1000;
22
23
  /**
23
24
  * The Component providing the AppSdk, the useSDK hook can only be used within this Provider
24
25
  * @param props.loading an optional loading element that gets rendered while initializing the app
@@ -26,7 +27,14 @@ exports.SDKContext = react_1.default.createContext({ sdk: null });
26
27
  var SDKProvider = function (props) {
27
28
  var _a = react_1.default.useState(), sdk = _a[0], setSDK = _a[1];
28
29
  react_1.default.useEffect(function () {
29
- (0, app_sdk_1.init)(setSDK);
30
+ var timeout = window.setTimeout(function () {
31
+ console.warn("Your app is taking longer than expected to initialize. If you think this is an error with Contentful's App SDK, let us know: https://github.com/contentful/ui-extensions-sdk/issues");
32
+ }, DELAY_TIMEOUT);
33
+ (0, app_sdk_1.init)(function (sdk) {
34
+ setSDK(sdk);
35
+ window.clearTimeout(timeout);
36
+ });
37
+ return function () { return window.clearTimeout(timeout); };
30
38
  }, []);
31
39
  if (!sdk) {
32
40
  if (props.loading) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var jsx_runtime_1 = require("react/jsx-runtime");
4
+ var react_1 = require("@testing-library/react");
5
+ var SDKProvider_1 = require("./SDKProvider");
6
+ var app_sdk_1 = require("@contentful/app-sdk");
7
+ jest.useFakeTimers();
8
+ jest.mock('@contentful/app-sdk', function () { return ({
9
+ init: jest.fn(),
10
+ }); });
11
+ describe('SDKProvider', function () {
12
+ var consoleWarnMock;
13
+ beforeEach(function () {
14
+ // @ts-ignore
15
+ app_sdk_1.init.mockImplementation(function (callback) {
16
+ callback({});
17
+ });
18
+ consoleWarnMock = jest.spyOn(console, 'warn').mockImplementation();
19
+ });
20
+ afterEach(function () {
21
+ consoleWarnMock === null || consoleWarnMock === void 0 ? void 0 : consoleWarnMock.mockRestore();
22
+ });
23
+ it('renders its children when sdk the init returns the sdk', function () {
24
+ var getByText = (0, react_1.render)((0, jsx_runtime_1.jsx)(SDKProvider_1.SDKProvider, { children: (0, jsx_runtime_1.jsx)("div", { children: "children" }) })).getByText;
25
+ expect(getByText('children')).toBeTruthy();
26
+ });
27
+ it('calls console warn after timeout if callback is not returning ', function () {
28
+ // @ts-ignore
29
+ app_sdk_1.init.mockImplementation(function () { });
30
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(SDKProvider_1.SDKProvider, { children: (0, jsx_runtime_1.jsx)("div", { children: "children" }) }));
31
+ jest.runAllTimers();
32
+ expect(consoleWarnMock).toHaveBeenCalled();
33
+ });
34
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/react-apps-toolkit",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Toolkit for building a Contentful app in React",
5
5
  "keywords": [],
6
6
  "author": "Contentful GmbH",
@@ -48,5 +48,5 @@
48
48
  "dependencies": {
49
49
  "@contentful/app-sdk": "^4.0.0"
50
50
  },
51
- "gitHead": "97a40b53cd03af999d289ac3e40ae90149d9c92a"
51
+ "gitHead": "8de11c51bc4d238157b026236e1b5bf62e227058"
52
52
  }