@carbonorm/carbonreact 3.3.0 → 3.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbonorm/carbonreact",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "browser": "dist/index.umd.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "main": "dist/index.cjs.js",
@@ -4,64 +4,67 @@ import {checkAllRequestsComplete, isVerbose} from "@carbonorm/carbonnode";
4
4
  import {waitFor} from "@testing-library/react";
5
5
  import {validSQL} from "./validSQL";
6
6
 
7
- const origionalWindowLocation = window.location
7
+ export default function () {
8
8
 
9
- const testName = () => expect.getState().currentTestName?.replaceAll(" ", "_").toLowerCase()
9
+ const origionalWindowLocation = window.location
10
10
 
11
- const validSqlFile = () => './logs/rest/' + testName() + '.json';
11
+ const testName = () => expect.getState().currentTestName?.replaceAll(" ", "_").toLowerCase()
12
12
 
13
- const logsFile = () => './logs/tests/' + testName() + '.log';
13
+ const validSqlFile = () => './logs/rest/' + testName() + '.json';
14
14
 
15
- /* eslint-disable no-undef */
16
- expect(document).not.toBeNull();
15
+ const logsFile = () => './logs/tests/' + testName() + '.log';
17
16
 
17
+ /* eslint-disable no-undef */
18
+ expect(document).not.toBeNull();
18
19
 
19
- const orig = console;
20
+
21
+ const orig = console;
20
22
 
21
23
  // @link https://stackoverflow.com/questions/13542667/create-directory-when-writing-to-file-in-node-js
22
- const superLogger = async (...args) => fs.writeFileSync(
23
- logsFile(),
24
- '\n' + inspect(args.length === 1 ? args.pop() : args, false, 10, true),
25
- {flag: "a+"});
24
+ const superLogger = async (...args) => fs.writeFileSync(
25
+ logsFile(),
26
+ '\n' + inspect(args.length === 1 ? args.pop() : args, false, 10, true),
27
+ {flag: "a+"});
26
28
 
27
29
  // noinspection CommaExpressionJS
28
- global.console = {
29
- ...console,
30
- // use jest.fn() to silence, comment out to leave as it is
31
- log: (...args) => (isVerbose && orig.log(...args), superLogger('log', ...args)),
32
- error: (...args) => (isVerbose && orig.error(...args), superLogger('error', ...args)),
33
- warn: (...args) => (isVerbose && orig.warn(...args), superLogger('warn', ...args)),
34
- info: (...args) => (isVerbose && orig.info(...args), superLogger('info', ...args)),
35
- debug: (...args) => (isVerbose && orig.debug(...args), superLogger('debug', ...args)),
36
- table: (...args) => (isVerbose && orig.table(...args), superLogger('table', ...args)),
37
- trace: (...args) => (isVerbose && orig.trace(...args), superLogger((() => {
38
- const err = new Error();
39
- return err.stack;
40
- })())),
41
- group: (...args) => (isVerbose && orig.group(...args), superLogger('group', ...args)),
42
- groupCollapsed: (...args) => (isVerbose && orig.groupCollapsed(args), superLogger('groupCollapsed', ...args)),
43
- groupEnd: () => (isVerbose && orig.groupEnd(), superLogger('groupEnd')),
44
- };
30
+ global.console = {
31
+ ...console,
32
+ // use jest.fn() to silence, comment out to leave as it is
33
+ log: (...args) => (isVerbose && orig.log(...args), superLogger('log', ...args)),
34
+ error: (...args) => (isVerbose && orig.error(...args), superLogger('error', ...args)),
35
+ warn: (...args) => (isVerbose && orig.warn(...args), superLogger('warn', ...args)),
36
+ info: (...args) => (isVerbose && orig.info(...args), superLogger('info', ...args)),
37
+ debug: (...args) => (isVerbose && orig.debug(...args), superLogger('debug', ...args)),
38
+ table: (...args) => (isVerbose && orig.table(...args), superLogger('table', ...args)),
39
+ trace: (...args) => (isVerbose && orig.trace(...args), superLogger((() => {
40
+ const err = new Error();
41
+ return err.stack;
42
+ })())),
43
+ group: (...args) => (isVerbose && orig.group(...args), superLogger('group', ...args)),
44
+ groupCollapsed: (...args) => (isVerbose && orig.groupCollapsed(args), superLogger('groupCollapsed', ...args)),
45
+ groupEnd: () => (isVerbose && orig.groupEnd(), superLogger('groupEnd')),
46
+ };
45
47
 
46
- afterEach(async () => {
48
+ afterEach(async () => {
47
49
 
48
- await waitFor(async () => {
50
+ await waitFor(async () => {
49
51
 
50
- expect(checkAllRequestsComplete()).toEqual(true);
52
+ expect(checkAllRequestsComplete()).toEqual(true);
51
53
 
52
- }, {timeout: 3000, interval: 1000});
54
+ }, {timeout: 3000, interval: 1000});
53
55
 
54
- // this must be a dynamic import to avoid loading dependencies out of order
55
- // await waitForTrailingRequests({testPassed: true, timeout: 12000})
56
+ // this must be a dynamic import to avoid loading dependencies out of order
57
+ // await waitForTrailingRequests({testPassed: true, timeout: 12000})
56
58
 
57
- console.log('After each Test (' + expect.getState().currentTestName + ')', expect.getState());
59
+ console.log('After each Test (' + expect.getState().currentTestName + ')', expect.getState());
58
60
 
59
- // restore `window.location` to the original `jsdom`
60
- // `Location` object
61
- window.location = origionalWindowLocation
61
+ // restore `window.location` to the original `jsdom`
62
+ // `Location` object
63
+ window.location = origionalWindowLocation
62
64
 
63
- fs.writeFileSync(validSqlFile(), JSON.stringify(validSQL , undefined, 2) ?? '');
65
+ fs.writeFileSync(validSqlFile(), JSON.stringify(validSQL, undefined, 2) ?? '');
64
66
 
65
- }, 65000)
67
+ }, 65000)
66
68
 
67
69
 
70
+ }
package/src/index.ts CHANGED
@@ -41,6 +41,7 @@ export { default as setCookies } from "./hoc/setCookies";
41
41
  export * from "./hoc/setCookies";
42
42
  export { default as setUrl } from "./hoc/setUrl";
43
43
  export * from "./hoc/setUrl";
44
+ export { default as setupTests } from "./hoc/setupTests";
44
45
  export * from "./hoc/setupTests";
45
46
  export { default as updateRestfulObjectArrays } from "./hoc/updateRestfulObjectArrays";
46
47
  export * from "./hoc/updateRestfulObjectArrays";