@carbonorm/carbonreact 3.3.1 → 3.3.3
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/dist/hoc/setupTests.d.ts +4 -1
- package/dist/index.cjs.js +16 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +16 -16
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/hoc/setupTests.tsx +18 -18
- package/src/hoc/validSQL.tsx +2 -1
package/package.json
CHANGED
package/src/hoc/setupTests.tsx
CHANGED
|
@@ -4,15 +4,15 @@ import {checkAllRequestsComplete, isVerbose} from "@carbonorm/carbonnode";
|
|
|
4
4
|
import {waitFor} from "@testing-library/react";
|
|
5
5
|
import {validSQL} from "./validSQL";
|
|
6
6
|
|
|
7
|
-
export default function () {
|
|
7
|
+
export default function ({sqlDirectory = './logs/rest/', logsDirectory = './logs/tests/'}: { sqlDirectory?: string, logsDirectory?: string } = {}) {
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const originalWindowLocation = window.location
|
|
10
10
|
|
|
11
11
|
const testName = () => expect.getState().currentTestName?.replaceAll(" ", "_").toLowerCase()
|
|
12
12
|
|
|
13
|
-
const validSqlFile = () =>
|
|
13
|
+
const validSqlFile = () => sqlDirectory + testName() + '.json';
|
|
14
14
|
|
|
15
|
-
const logsFile = () =>
|
|
15
|
+
const logsFile = () => logsDirectory + testName() + '.log';
|
|
16
16
|
|
|
17
17
|
/* eslint-disable no-undef */
|
|
18
18
|
expect(document).not.toBeNull();
|
|
@@ -20,29 +20,29 @@ export default function () {
|
|
|
20
20
|
|
|
21
21
|
const orig = console;
|
|
22
22
|
|
|
23
|
-
// @link https://stackoverflow.com/questions/13542667/create-directory-when-writing-to-file-in-node-js
|
|
24
|
-
const
|
|
23
|
+
// @link https://stackoverflow.com/questions/13542667/create-directory-when-writing-to-file-in-node-js
|
|
24
|
+
const asyncFileLogging = async (...args) => fs.writeFileSync(
|
|
25
25
|
logsFile(),
|
|
26
26
|
'\n' + inspect(args.length === 1 ? args.pop() : args, false, 10, true),
|
|
27
27
|
{flag: "a+"});
|
|
28
28
|
|
|
29
|
-
// noinspection CommaExpressionJS
|
|
29
|
+
// noinspection CommaExpressionJS
|
|
30
30
|
global.console = {
|
|
31
31
|
...console,
|
|
32
32
|
// use jest.fn() to silence, comment out to leave as it is
|
|
33
|
-
log: (...args) => (isVerbose && orig.log(...args),
|
|
34
|
-
error: (...args) => (isVerbose && orig.error(...args),
|
|
35
|
-
warn: (...args) => (isVerbose && orig.warn(...args),
|
|
36
|
-
info: (...args) => (isVerbose && orig.info(...args),
|
|
37
|
-
debug: (...args) => (isVerbose && orig.debug(...args),
|
|
38
|
-
table: (...args) => (isVerbose && orig.table(...args),
|
|
39
|
-
trace: (...args) => (isVerbose && orig.trace(...args),
|
|
33
|
+
log: (...args) => (isVerbose && orig.log(...args), asyncFileLogging('log', ...args)),
|
|
34
|
+
error: (...args) => (isVerbose && orig.error(...args), asyncFileLogging('error', ...args)),
|
|
35
|
+
warn: (...args) => (isVerbose && orig.warn(...args), asyncFileLogging('warn', ...args)),
|
|
36
|
+
info: (...args) => (isVerbose && orig.info(...args), asyncFileLogging('info', ...args)),
|
|
37
|
+
debug: (...args) => (isVerbose && orig.debug(...args), asyncFileLogging('debug', ...args)),
|
|
38
|
+
table: (...args) => (isVerbose && orig.table(...args), asyncFileLogging('table', ...args)),
|
|
39
|
+
trace: (...args) => (isVerbose && orig.trace(...args), asyncFileLogging((() => {
|
|
40
40
|
const err = new Error();
|
|
41
41
|
return err.stack;
|
|
42
42
|
})())),
|
|
43
|
-
group: (...args) => (isVerbose && orig.group(...args),
|
|
44
|
-
groupCollapsed: (...args) => (isVerbose && orig.groupCollapsed(args),
|
|
45
|
-
groupEnd: () => (isVerbose && orig.groupEnd(),
|
|
43
|
+
group: (...args) => (isVerbose && orig.group(...args), asyncFileLogging('group', ...args)),
|
|
44
|
+
groupCollapsed: (...args) => (isVerbose && orig.groupCollapsed(args), asyncFileLogging('groupCollapsed', ...args)),
|
|
45
|
+
groupEnd: () => (isVerbose && orig.groupEnd(), asyncFileLogging('groupEnd')),
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
afterEach(async () => {
|
|
@@ -60,7 +60,7 @@ export default function () {
|
|
|
60
60
|
|
|
61
61
|
// restore `window.location` to the original `jsdom`
|
|
62
62
|
// `Location` object
|
|
63
|
-
window.location =
|
|
63
|
+
window.location = originalWindowLocation
|
|
64
64
|
|
|
65
65
|
fs.writeFileSync(validSqlFile(), JSON.stringify(validSQL, undefined, 2) ?? '');
|
|
66
66
|
|
package/src/hoc/validSQL.tsx
CHANGED