@khanacademy/wonder-blocks-testing-core 2.1.0 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @khanacademy/wonder-blocks-testing-core
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - eb47d37: Improve error messaging for the router test harness adapter
8
+
9
+ ## 2.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - ee8d95a: Rollback rollup version from v4 to v2 to prevent an issue with CJS builds in unit tests
14
+
3
15
  ## 2.1.0
4
16
 
5
17
  ### Minor Changes
package/dist/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
- import { StaticRouter, MemoryRouter, Switch, Route } from 'react-router-dom';
3
+ import { StaticRouter, MemoryRouter, useLocation, Switch, Route } from 'react-router-dom';
4
4
  import _extends from '@babel/runtime/helpers/extends';
5
5
  import * as ReactDOMServer from 'react-dom/server';
6
6
 
@@ -213,8 +213,8 @@ class SettleSignal extends EventTarget {
213
213
 
214
214
  class SettleController {
215
215
  constructor() {
216
- this._settleFn = undefined;
217
- this._signal = undefined;
216
+ this._settleFn = void 0;
217
+ this._signal = void 0;
218
218
  this._signal = new SettleSignal(settleFn => this._settleFn = settleFn);
219
219
  }
220
220
  get signal() {
@@ -300,7 +300,13 @@ const adapter$1 = (children, config) => React.createElement(React.Fragment, null
300
300
  const defaultConfig = {
301
301
  location: "/"
302
302
  };
303
- const maybeWithRoute = (children, path) => {
303
+ const MaybeWithRoute = ({
304
+ children,
305
+ path,
306
+ configLocation
307
+ }) => {
308
+ const actualLocation = useLocation();
309
+ const configuredLocation = typeof configLocation === "string" ? configLocation : configLocation.pathname;
304
310
  if (path == null) {
305
311
  return React.createElement(React.Fragment, null, children);
306
312
  }
@@ -310,27 +316,33 @@ const maybeWithRoute = (children, path) => {
310
316
  }, children), React.createElement(Route, {
311
317
  path: "*",
312
318
  render: () => {
313
- throw new Error("The configured path must match the configured location or your harnessed component will not render.");
319
+ throw new Error(`The current location '${actualLocation.pathname}' ` + `does not match the configured path '${path}'. ` + `Did you provide the correct configured ` + `location, '${configuredLocation}', or did the ` + `routing lead to a different place than you ` + `expected?`);
314
320
  }
315
321
  }));
316
322
  };
317
323
  const adapter = (children, config) => {
324
+ var _config$initialIndex;
318
325
  if (typeof config === "string") {
319
326
  config = {
320
327
  location: config
321
328
  };
322
329
  }
323
- const wrappedWithRoute = maybeWithRoute(children, config.path);
324
330
  if ("forceStatic" in config && config.forceStatic) {
325
331
  return React.createElement(StaticRouter, {
326
332
  location: config.location,
327
333
  context: {}
328
- }, wrappedWithRoute);
334
+ }, React.createElement(MaybeWithRoute, {
335
+ path: config.path,
336
+ configLocation: config.location
337
+ }, children));
329
338
  }
330
339
  if ("location" in config && config.location !== undefined) {
331
340
  return React.createElement(MemoryRouter, {
332
341
  initialEntries: [config.location]
333
- }, wrappedWithRoute);
342
+ }, React.createElement(MaybeWithRoute, {
343
+ path: config.path,
344
+ configLocation: config.location
345
+ }, children));
334
346
  }
335
347
  if (!("initialEntries" in config) || config.initialEntries === undefined) {
336
348
  throw new Error("A location or initial history entries must be provided.");
@@ -345,7 +357,10 @@ const adapter = (children, config) => {
345
357
  if (config.getUserConfirmation != null) {
346
358
  routerProps.getUserConfirmation = config.getUserConfirmation;
347
359
  }
348
- return React.createElement(MemoryRouter, routerProps, wrappedWithRoute);
360
+ return React.createElement(MemoryRouter, routerProps, React.createElement(MaybeWithRoute, {
361
+ path: config.path,
362
+ configLocation: entries[(_config$initialIndex = config.initialIndex) != null ? _config$initialIndex : 0]
363
+ }, children));
349
364
  };
350
365
 
351
366
  const DefaultAdapters = {
package/dist/index.js CHANGED
@@ -1,12 +1,17 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var React = require('react');
4
6
  var addonActions = require('@storybook/addon-actions');
5
7
  var reactRouterDom = require('react-router-dom');
6
8
  var _extends = require('@babel/runtime/helpers/extends');
7
9
  var ReactDOMServer = require('react-dom/server');
8
10
 
9
- function _interopNamespaceDefault(e) {
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
10
15
  var n = Object.create(null);
11
16
  if (e) {
12
17
  Object.keys(e).forEach(function (k) {
@@ -19,12 +24,13 @@ function _interopNamespaceDefault(e) {
19
24
  }
20
25
  });
21
26
  }
22
- n.default = e;
27
+ n["default"] = e;
23
28
  return Object.freeze(n);
24
29
  }
25
30
 
26
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
27
- var ReactDOMServer__namespace = /*#__PURE__*/_interopNamespaceDefault(ReactDOMServer);
31
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
33
+ var ReactDOMServer__namespace = /*#__PURE__*/_interopNamespace(ReactDOMServer);
28
34
 
29
35
  const fixtures = Component => {
30
36
  const templateMap = new WeakMap();
@@ -235,8 +241,8 @@ class SettleSignal extends EventTarget {
235
241
 
236
242
  class SettleController {
237
243
  constructor() {
238
- this._settleFn = undefined;
239
- this._signal = undefined;
244
+ this._settleFn = void 0;
245
+ this._signal = void 0;
240
246
  this._signal = new SettleSignal(settleFn => this._settleFn = settleFn);
241
247
  }
242
248
  get signal() {
@@ -322,7 +328,13 @@ const adapter$1 = (children, config) => React__namespace.createElement(React__na
322
328
  const defaultConfig = {
323
329
  location: "/"
324
330
  };
325
- const maybeWithRoute = (children, path) => {
331
+ const MaybeWithRoute = ({
332
+ children,
333
+ path,
334
+ configLocation
335
+ }) => {
336
+ const actualLocation = reactRouterDom.useLocation();
337
+ const configuredLocation = typeof configLocation === "string" ? configLocation : configLocation.pathname;
326
338
  if (path == null) {
327
339
  return React__namespace.createElement(React__namespace.Fragment, null, children);
328
340
  }
@@ -332,27 +344,33 @@ const maybeWithRoute = (children, path) => {
332
344
  }, children), React__namespace.createElement(reactRouterDom.Route, {
333
345
  path: "*",
334
346
  render: () => {
335
- throw new Error("The configured path must match the configured location or your harnessed component will not render.");
347
+ throw new Error(`The current location '${actualLocation.pathname}' ` + `does not match the configured path '${path}'. ` + `Did you provide the correct configured ` + `location, '${configuredLocation}', or did the ` + `routing lead to a different place than you ` + `expected?`);
336
348
  }
337
349
  }));
338
350
  };
339
351
  const adapter = (children, config) => {
352
+ var _config$initialIndex;
340
353
  if (typeof config === "string") {
341
354
  config = {
342
355
  location: config
343
356
  };
344
357
  }
345
- const wrappedWithRoute = maybeWithRoute(children, config.path);
346
358
  if ("forceStatic" in config && config.forceStatic) {
347
359
  return React__namespace.createElement(reactRouterDom.StaticRouter, {
348
360
  location: config.location,
349
361
  context: {}
350
- }, wrappedWithRoute);
362
+ }, React__namespace.createElement(MaybeWithRoute, {
363
+ path: config.path,
364
+ configLocation: config.location
365
+ }, children));
351
366
  }
352
367
  if ("location" in config && config.location !== undefined) {
353
368
  return React__namespace.createElement(reactRouterDom.MemoryRouter, {
354
369
  initialEntries: [config.location]
355
- }, wrappedWithRoute);
370
+ }, React__namespace.createElement(MaybeWithRoute, {
371
+ path: config.path,
372
+ configLocation: config.location
373
+ }, children));
356
374
  }
357
375
  if (!("initialEntries" in config) || config.initialEntries === undefined) {
358
376
  throw new Error("A location or initial history entries must be provided.");
@@ -367,7 +385,10 @@ const adapter = (children, config) => {
367
385
  if (config.getUserConfirmation != null) {
368
386
  routerProps.getUserConfirmation = config.getUserConfirmation;
369
387
  }
370
- return React__namespace.createElement(reactRouterDom.MemoryRouter, routerProps, wrappedWithRoute);
388
+ return React__namespace.createElement(reactRouterDom.MemoryRouter, routerProps, React__namespace.createElement(MaybeWithRoute, {
389
+ path: config.path,
390
+ configLocation: entries[(_config$initialIndex = config.initialIndex) != null ? _config$initialIndex : 0]
391
+ }, children));
371
392
  };
372
393
 
373
394
  const DefaultAdapters = {
@@ -426,11 +447,11 @@ const Adapt = ({
426
447
 
427
448
  const makeTestHarness = (adapters, defaultConfigs) => {
428
449
  return (Component, configs) => {
429
- const fullConfig = _extends({}, defaultConfigs, configs);
450
+ const fullConfig = _extends__default["default"]({}, defaultConfigs, configs);
430
451
  const harnessedComponent = React__namespace.forwardRef((props, ref) => React__namespace.createElement(Adapt, {
431
452
  adapters: adapters,
432
453
  configs: fullConfig
433
- }, React__namespace.createElement(Component, _extends({}, props, {
454
+ }, React__namespace.createElement(Component, _extends__default["default"]({}, props, {
434
455
  ref: ref
435
456
  }))));
436
457
  harnessedComponent.displayName = `testHarness(${Component.displayName || Component.name || "Component"})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-testing-core",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@khanacademy/wonder-stuff-testing": "^3.0.1",
26
- "@khanacademy/wb-dev-build-settings": "2.1.0"
26
+ "@khanacademy/wb-dev-build-settings": "2.1.1"
27
27
  },
28
28
  "author": "",
29
29
  "license": "MIT",