@khanacademy/wonder-blocks-testing-core 2.1.1 → 2.2.1

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.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 1d7be37: Use pnpm catalog to pin dependency versions across packages
8
+
9
+ ## 2.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - eb47d37: Improve error messaging for the router test harness adapter
14
+
3
15
  ## 2.1.1
4
16
 
5
17
  ### Patch 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
 
@@ -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
@@ -328,7 +328,13 @@ const adapter$1 = (children, config) => React__namespace.createElement(React__na
328
328
  const defaultConfig = {
329
329
  location: "/"
330
330
  };
331
- 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;
332
338
  if (path == null) {
333
339
  return React__namespace.createElement(React__namespace.Fragment, null, children);
334
340
  }
@@ -338,27 +344,33 @@ const maybeWithRoute = (children, path) => {
338
344
  }, children), React__namespace.createElement(reactRouterDom.Route, {
339
345
  path: "*",
340
346
  render: () => {
341
- 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?`);
342
348
  }
343
349
  }));
344
350
  };
345
351
  const adapter = (children, config) => {
352
+ var _config$initialIndex;
346
353
  if (typeof config === "string") {
347
354
  config = {
348
355
  location: config
349
356
  };
350
357
  }
351
- const wrappedWithRoute = maybeWithRoute(children, config.path);
352
358
  if ("forceStatic" in config && config.forceStatic) {
353
359
  return React__namespace.createElement(reactRouterDom.StaticRouter, {
354
360
  location: config.location,
355
361
  context: {}
356
- }, wrappedWithRoute);
362
+ }, React__namespace.createElement(MaybeWithRoute, {
363
+ path: config.path,
364
+ configLocation: config.location
365
+ }, children));
357
366
  }
358
367
  if ("location" in config && config.location !== undefined) {
359
368
  return React__namespace.createElement(reactRouterDom.MemoryRouter, {
360
369
  initialEntries: [config.location]
361
- }, wrappedWithRoute);
370
+ }, React__namespace.createElement(MaybeWithRoute, {
371
+ path: config.path,
372
+ configLocation: config.location
373
+ }, children));
362
374
  }
363
375
  if (!("initialEntries" in config) || config.initialEntries === undefined) {
364
376
  throw new Error("A location or initial history entries must be provided.");
@@ -373,7 +385,10 @@ const adapter = (children, config) => {
373
385
  if (config.getUserConfirmation != null) {
374
386
  routerProps.getUserConfirmation = config.getUserConfirmation;
375
387
  }
376
- 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));
377
392
  };
378
393
 
379
394
  const DefaultAdapters = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-testing-core",
3
- "version": "2.1.1",
3
+ "version": "2.2.1",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"