@khanacademy/wonder-blocks-testing-core 1.0.0 → 1.0.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/es/index.js +3 -22
  3. package/dist/index.js +9 -24
  4. package/package.json +32 -32
  5. package/src/__tests__/mock-requester.test.ts +0 -212
  6. package/src/__tests__/render-hook-static.test.ts +0 -48
  7. package/src/__tests__/respond-with.test.ts +0 -524
  8. package/src/__tests__/response-impl.test.js +0 -47
  9. package/src/__tests__/settle-controller.test.ts +0 -28
  10. package/src/__tests__/settle-signal.test.ts +0 -104
  11. package/src/fetch/__tests__/__snapshots__/mock-fetch.test.ts.snap +0 -29
  12. package/src/fetch/__tests__/fetch-request-matches-mock.test.ts +0 -98
  13. package/src/fetch/__tests__/mock-fetch.test.ts +0 -83
  14. package/src/fetch/fetch-request-matches-mock.ts +0 -42
  15. package/src/fetch/mock-fetch.ts +0 -20
  16. package/src/fetch/types.ts +0 -14
  17. package/src/fixtures/__tests__/fixtures.test.tsx +0 -147
  18. package/src/fixtures/fixtures.basic.stories.tsx +0 -62
  19. package/src/fixtures/fixtures.defaultwrapper.stories.tsx +0 -49
  20. package/src/fixtures/fixtures.tsx +0 -72
  21. package/src/fixtures/types.ts +0 -42
  22. package/src/harness/__tests__/adapt.test.tsx +0 -248
  23. package/src/harness/__tests__/hook-harness.test.ts +0 -73
  24. package/src/harness/__tests__/make-hook-harness.test.tsx +0 -93
  25. package/src/harness/__tests__/make-test-harness.test.tsx +0 -195
  26. package/src/harness/__tests__/test-harness.test.ts +0 -75
  27. package/src/harness/__tests__/types.typestest.tsx +0 -103
  28. package/src/harness/adapt.tsx +0 -41
  29. package/src/harness/adapters/__tests__/__snapshots__/router.test.tsx.snap +0 -5
  30. package/src/harness/adapters/__tests__/css.test.tsx +0 -95
  31. package/src/harness/adapters/__tests__/error-boundary.test.tsx +0 -121
  32. package/src/harness/adapters/__tests__/portal.test.tsx +0 -30
  33. package/src/harness/adapters/__tests__/router.test.tsx +0 -252
  34. package/src/harness/adapters/adapters.ts +0 -35
  35. package/src/harness/adapters/css.tsx +0 -66
  36. package/src/harness/adapters/error-boundary.tsx +0 -56
  37. package/src/harness/adapters/portal.tsx +0 -25
  38. package/src/harness/adapters/router.tsx +0 -205
  39. package/src/harness/get-named-adapter-component.tsx +0 -36
  40. package/src/harness/hook-harness.ts +0 -22
  41. package/src/harness/make-hook-harness.tsx +0 -40
  42. package/src/harness/make-test-harness.tsx +0 -60
  43. package/src/harness/test-harness.ts +0 -13
  44. package/src/harness/types.ts +0 -47
  45. package/src/index.ts +0 -29
  46. package/src/mock-requester.ts +0 -68
  47. package/src/render-hook-static.tsx +0 -60
  48. package/src/respond-with.ts +0 -263
  49. package/src/response-impl.ts +0 -8
  50. package/src/settle-controller.ts +0 -34
  51. package/src/settle-signal.ts +0 -42
  52. package/src/types.ts +0 -40
  53. package/tsconfig-build.json +0 -10
  54. package/tsconfig-build.tsbuildinfo +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @khanacademy/wonder-blocks-testing-core
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
8
+
9
+ ## 1.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - c954464a: Fix how react-dom/server is imported in Wonder Blocks Testing Core
14
+ - 559e82d5: Update to build tooling, generating smaller output
15
+
3
16
  ## 1.0.0
4
17
 
5
18
  ### Major Changes
package/dist/es/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
3
  import { StaticRouter, MemoryRouter, Switch, Route } from 'react-router-dom';
4
+ import _extends from '@babel/runtime/helpers/extends';
5
+ import * as ReactDOMServer from 'react-dom/server';
4
6
 
5
7
  const fixtures = Component => {
6
8
  const templateMap = new WeakMap();
@@ -347,21 +349,6 @@ var adapters = /*#__PURE__*/Object.freeze({
347
349
  DefaultConfigs: DefaultConfigs
348
350
  });
349
351
 
350
- function _extends() {
351
- _extends = Object.assign ? Object.assign.bind() : function (target) {
352
- for (var i = 1; i < arguments.length; i++) {
353
- var source = arguments[i];
354
- for (var key in source) {
355
- if (Object.prototype.hasOwnProperty.call(source, key)) {
356
- target[key] = source[key];
357
- }
358
- }
359
- }
360
- return target;
361
- };
362
- return _extends.apply(this, arguments);
363
- }
364
-
365
352
  const componentCache = new Map();
366
353
  const getNamedAdapterComponent = name => {
367
354
  const existing = componentCache.get(name);
@@ -423,12 +410,6 @@ const hookHarness = makeHookHarness(DefaultAdapters, DefaultConfigs);
423
410
 
424
411
  const testHarness = makeTestHarness(DefaultAdapters, DefaultConfigs);
425
412
 
426
- if (process.env.NODE_ENV === 'production') {
427
- module.exports = require('./cjs/react-dom-server.browser.production.min.js');
428
- } else {
429
- module.exports = require('./cjs/react-dom-server.browser.development.js');
430
- }
431
-
432
413
  const renderHookStatic = (render, {
433
414
  wrapper,
434
415
  initialProps
@@ -444,7 +425,7 @@ const renderHookStatic = (render, {
444
425
  renderCallbackProps: initialProps
445
426
  });
446
427
  const componentWithWrapper = wrapper == null ? component : React.createElement(wrapper, null, component);
447
- undefined(componentWithWrapper);
428
+ ReactDOMServer.renderToString(componentWithWrapper);
448
429
  return {
449
430
  result: {
450
431
  current: result
package/dist/index.js CHANGED
@@ -5,6 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var addonActions = require('@storybook/addon-actions');
7
7
  var reactRouterDom = require('react-router-dom');
8
+ var _extends = require('@babel/runtime/helpers/extends');
9
+ var ReactDOMServer = require('react-dom/server');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
12
 
9
13
  function _interopNamespace(e) {
10
14
  if (e && e.__esModule) return e;
@@ -25,6 +29,8 @@ function _interopNamespace(e) {
25
29
  }
26
30
 
27
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();
@@ -371,21 +377,6 @@ var adapters = /*#__PURE__*/Object.freeze({
371
377
  DefaultConfigs: DefaultConfigs
372
378
  });
373
379
 
374
- function _extends() {
375
- _extends = Object.assign ? Object.assign.bind() : function (target) {
376
- for (var i = 1; i < arguments.length; i++) {
377
- var source = arguments[i];
378
- for (var key in source) {
379
- if (Object.prototype.hasOwnProperty.call(source, key)) {
380
- target[key] = source[key];
381
- }
382
- }
383
- }
384
- return target;
385
- };
386
- return _extends.apply(this, arguments);
387
- }
388
-
389
380
  const componentCache = new Map();
390
381
  const getNamedAdapterComponent = name => {
391
382
  const existing = componentCache.get(name);
@@ -423,11 +414,11 @@ const Adapt = ({
423
414
 
424
415
  const makeTestHarness = (adapters, defaultConfigs) => {
425
416
  return (Component, configs) => {
426
- const fullConfig = _extends({}, defaultConfigs, configs);
417
+ const fullConfig = _extends__default["default"]({}, defaultConfigs, configs);
427
418
  const harnessedComponent = React__namespace.forwardRef((props, ref) => React__namespace.createElement(Adapt, {
428
419
  adapters: adapters,
429
420
  configs: fullConfig
430
- }, React__namespace.createElement(Component, _extends({}, props, {
421
+ }, React__namespace.createElement(Component, _extends__default["default"]({}, props, {
431
422
  ref: ref
432
423
  }))));
433
424
  harnessedComponent.displayName = `testHarness(${Component.displayName || Component.name || "Component"})`;
@@ -447,12 +438,6 @@ const hookHarness = makeHookHarness(DefaultAdapters, DefaultConfigs);
447
438
 
448
439
  const testHarness = makeTestHarness(DefaultAdapters, DefaultConfigs);
449
440
 
450
- if (process.env.NODE_ENV === 'production') {
451
- module.exports = require('./cjs/react-dom-server.browser.production.min.js');
452
- } else {
453
- module.exports = require('./cjs/react-dom-server.browser.development.js');
454
- }
455
-
456
441
  const renderHookStatic = (render, {
457
442
  wrapper,
458
443
  initialProps
@@ -468,7 +453,7 @@ const renderHookStatic = (render, {
468
453
  renderCallbackProps: initialProps
469
454
  });
470
455
  const componentWithWrapper = wrapper == null ? component : React__namespace.createElement(wrapper, null, component);
471
- undefined(componentWithWrapper);
456
+ ReactDOMServer__namespace.renderToString(componentWithWrapper);
472
457
  return {
473
458
  result: {
474
459
  current: result
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
1
  {
2
- "name": "@khanacademy/wonder-blocks-testing-core",
3
- "version": "1.0.0",
4
- "design": "v1",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "description": "",
9
- "main": "dist/index.js",
10
- "module": "dist/es/index.js",
11
- "types": "dist/index.d.ts",
12
- "scripts": {
13
- "test": "echo \"Error: no test specified\" && exit 1"
14
- },
15
- "dependencies": {
16
- "@babel/runtime": "^7.18.6"
17
- },
18
- "peerDependencies": {
19
- "@khanacademy/wonder-stuff-core": "^1.2.2",
20
- "@storybook/addon-actions": "^7.0.0",
21
- "aphrodite": "^1.2.5",
22
- "node-fetch": "^2.6.7",
23
- "react": "16.14.0",
24
- "react-dom": "16.14.0",
25
- "react-router-dom": "5.3.0"
26
- },
27
- "devDependencies": {
28
- "@khanacademy/wb-dev-build-settings": "^1.0.0",
29
- "@khanacademy/wonder-stuff-testing": "^3.0.1"
30
- },
31
- "author": "",
32
- "license": "MIT"
33
- }
2
+ "name": "@khanacademy/wonder-blocks-testing-core",
3
+ "version": "1.0.2",
4
+ "design": "v1",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "",
9
+ "main": "dist/index.js",
10
+ "module": "dist/es/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "dependencies": {
16
+ "@babel/runtime": "^7.18.6"
17
+ },
18
+ "peerDependencies": {
19
+ "@khanacademy/wonder-stuff-core": "^1.2.2",
20
+ "@storybook/addon-actions": "^7.0.0",
21
+ "aphrodite": "^1.2.5",
22
+ "node-fetch": "^2.6.7",
23
+ "react": "16.14.0",
24
+ "react-dom": "16.14.0",
25
+ "react-router-dom": "5.3.0"
26
+ },
27
+ "devDependencies": {
28
+ "@khanacademy/wb-dev-build-settings": "^1.0.1",
29
+ "@khanacademy/wonder-stuff-testing": "^3.0.1"
30
+ },
31
+ "author": "",
32
+ "license": "MIT"
33
+ }
@@ -1,212 +0,0 @@
1
- import {RespondWith} from "../respond-with";
2
- import {mockRequester} from "../mock-requester";
3
-
4
- describe("#mockRequester", () => {
5
- it("should return a function", () => {
6
- // Arrange
7
-
8
- // Act
9
- const result = mockRequester(jest.fn(), jest.fn());
10
-
11
- // Assert
12
- expect(result).toBeInstanceOf(Function);
13
- });
14
-
15
- it("should provide mockOperation API", () => {
16
- // Arrange
17
-
18
- // Act
19
- const result = mockRequester(jest.fn(), jest.fn());
20
-
21
- // Assert
22
- expect(result).toHaveProperty("mockOperation", expect.any(Function));
23
- });
24
-
25
- it("should provide mockOperationOnce API", () => {
26
- // Arrange
27
-
28
- // Act
29
- const result = mockRequester(jest.fn(), jest.fn());
30
-
31
- // Assert
32
- expect(result).toHaveProperty(
33
- "mockOperationOnce",
34
- expect.any(Function),
35
- );
36
- });
37
-
38
- it("should throw with helpful details formatted by operationToString if no matching mock is found", async () => {
39
- // Arrange
40
- const mockFn = mockRequester(
41
- jest.fn(),
42
- (...args: any) => `TEST FORMATTING: ${JSON.stringify(args)}`,
43
- );
44
-
45
- // Act
46
- const underTest = mockFn("any", "arguments", {we: {want: 42}});
47
-
48
- // Assert
49
- await expect(underTest).rejects.toThrowErrorMatchingInlineSnapshot(`
50
- "No matching mock response found for request:
51
- TEST FORMATTING: ["any","arguments",{"we":{"want":42}}]"
52
- `);
53
- });
54
-
55
- describe("mockOperation", () => {
56
- it("should invoke matcher with mock for a request", async () => {
57
- // Arrange
58
- const matcher = jest.fn().mockReturnValue(true);
59
- const operationToString = jest.fn();
60
- const mockFn = mockRequester(matcher, operationToString);
61
-
62
- // Act
63
- mockFn.mockOperation(
64
- "THE MOCK DESCRIPTION",
65
- RespondWith.text("TADA!"),
66
- );
67
- await mockFn("any", "arguments", {we: {want: 42}});
68
-
69
- // Assert
70
- expect(matcher).toHaveBeenCalledWith(
71
- "THE MOCK DESCRIPTION",
72
- "any",
73
- "arguments",
74
- {
75
- we: {want: 42},
76
- },
77
- );
78
- });
79
-
80
- it("should return mocked operation response if matcher returns true", async () => {
81
- // Arrange
82
- const matcher = jest.fn().mockReturnValue(true);
83
- const operationToString = jest.fn();
84
- const mockFn = mockRequester(matcher, operationToString);
85
-
86
- // Act
87
- mockFn.mockOperation(
88
- "THE MOCK DESCRIPTION",
89
- RespondWith.text("TADA!"),
90
- );
91
- const response = await mockFn("DO SOMETHING");
92
- const result = response.text();
93
-
94
- // Assert
95
- await expect(result).resolves.toBe("TADA!");
96
- });
97
-
98
- it("should skip mock if matcher returns false and try more mocks", async () => {
99
- // Arrange
100
- const matcher = jest
101
- .fn()
102
- .mockReturnValueOnce(false)
103
- .mockReturnValueOnce(true);
104
- const operationToString = jest.fn();
105
- const mockFn = mockRequester(matcher, operationToString);
106
-
107
- // Act
108
- mockFn.mockOperation(
109
- "THE MOCK DESCRIPTION 1",
110
- RespondWith.text("ONE"),
111
- );
112
- mockFn.mockOperation(
113
- "THE MOCK DESCRIPTION 2",
114
- RespondWith.text("TWO"),
115
- );
116
- const response = await mockFn("DO SOMETHING");
117
- const result = response.text();
118
-
119
- // Assert
120
- await expect(result).resolves.toBe("TWO");
121
- });
122
- });
123
-
124
- describe("mockOperationOnce", () => {
125
- it("should invoke matcher with mock for a request", async () => {
126
- // Arrange
127
- const matcher = jest.fn().mockReturnValue(true);
128
- const operationToString = jest.fn();
129
- const mockFn = mockRequester(matcher, operationToString);
130
-
131
- // Act
132
- mockFn.mockOperationOnce(
133
- "THE MOCK DESCRIPTION",
134
- RespondWith.text("TADA!"),
135
- );
136
- await mockFn("any", "arguments", {we: {want: 42}});
137
-
138
- // Assert
139
- expect(matcher).toHaveBeenCalledWith(
140
- "THE MOCK DESCRIPTION",
141
- "any",
142
- "arguments",
143
- {
144
- we: {want: 42},
145
- },
146
- );
147
- });
148
-
149
- it("should match once", async () => {
150
- // Arrange
151
- const matcher = jest.fn().mockReturnValue(true);
152
- const operationToString = jest.fn();
153
- const mockFn = mockRequester(matcher, operationToString);
154
-
155
- // Act
156
- mockFn.mockOperationOnce(
157
- "THE MOCK DESCRIPTION",
158
- RespondWith.text("TADA!"),
159
- );
160
- const response = await mockFn("DO SOMETHING");
161
- const result = response.text();
162
-
163
- // Assert
164
- await expect(result).resolves.toBe("TADA!");
165
- });
166
-
167
- it("should only match once", async () => {
168
- // Arrange
169
- const matcher = jest.fn().mockReturnValue(true);
170
- const operationToString = jest.fn();
171
- const mockFn = mockRequester(matcher, operationToString);
172
-
173
- // Act
174
- mockFn.mockOperationOnce(
175
- "THE MOCK DESCRIPTION",
176
- RespondWith.text("TADA!"),
177
- );
178
- const result = Promise.all([
179
- mockFn("DO SOMETHING"),
180
- mockFn("DO SOMETHING"),
181
- ]);
182
-
183
- // Assert
184
- await expect(result).rejects.toThrowError();
185
- });
186
-
187
- it("should skip mock if matcher returns false and try more mocks", async () => {
188
- // Arrange
189
- const matcher = jest
190
- .fn()
191
- .mockReturnValueOnce(false)
192
- .mockReturnValueOnce(true);
193
- const operationToString = jest.fn();
194
- const mockFn = mockRequester(matcher, operationToString);
195
-
196
- // Act
197
- mockFn.mockOperationOnce(
198
- "THE MOCK DESCRIPTION 1",
199
- RespondWith.text("ONE"),
200
- );
201
- mockFn.mockOperationOnce(
202
- "THE MOCK DESCRIPTION 2",
203
- RespondWith.text("TWO"),
204
- );
205
- const response = await mockFn("DO SOMETHING");
206
- const result = response.text();
207
-
208
- // Assert
209
- await expect(result).resolves.toBe("TWO");
210
- });
211
- });
212
- });
@@ -1,48 +0,0 @@
1
- import {useLocation} from "react-router-dom";
2
-
3
- import {hookHarness} from "../harness/hook-harness";
4
- import {renderHookStatic} from "../render-hook-static";
5
-
6
- describe("renderHookStatic", () => {
7
- it("should return the result of rendering the hook", () => {
8
- // Arrange
9
- const useTestHook = () => "Hello, World!";
10
-
11
- // Act
12
- const result = renderHookStatic(useTestHook);
13
-
14
- // Assert
15
- expect(result).toStrictEqual({result: {current: "Hello, World!"}});
16
- });
17
-
18
- it("should render the hook with the given initialProps", () => {
19
- // Arrange
20
- const useTestHook = (initialProps?: string) =>
21
- initialProps ?? "BAD RESULT";
22
-
23
- // Act
24
- const result = renderHookStatic(useTestHook, {
25
- initialProps: "Hello, World!",
26
- });
27
-
28
- // Assert
29
- expect(result).toStrictEqual({result: {current: "Hello, World!"}});
30
- });
31
-
32
- it("should return the result of rendering the hook inside the wrapper", () => {
33
- // Arrange
34
- const Wrapper = hookHarness({
35
- router: "/test/route",
36
- });
37
- const useTestHook = () => {
38
- const location = useLocation();
39
- return location.pathname;
40
- };
41
-
42
- // Act
43
- const result = renderHookStatic(useTestHook, {wrapper: Wrapper});
44
-
45
- // Assert
46
- expect(result).toStrictEqual({result: {current: "/test/route"}});
47
- });
48
- });