@carbonorm/carbonreact 3.3.0 → 3.3.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.
package/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ export { default as setCookies } from "./hoc/setCookies";
40
40
  export * from "./hoc/setCookies";
41
41
  export { default as setUrl } from "./hoc/setUrl";
42
42
  export * from "./hoc/setUrl";
43
+ export { default as setupTests } from "./hoc/setupTests";
43
44
  export * from "./hoc/setupTests";
44
45
  export { default as updateRestfulObjectArrays } from "./hoc/updateRestfulObjectArrays";
45
46
  export * from "./hoc/updateRestfulObjectArrays";
package/dist/index.esm.js CHANGED
@@ -4251,45 +4251,47 @@ function validSQL$1 (sql) {
4251
4251
  validSQL.push({ [expect.getState().currentTestName.replaceAll(" ", "_").toLowerCase()]: sql });
4252
4252
  }
4253
4253
 
4254
- const origionalWindowLocation = window.location;
4255
- const testName = () => expect.getState().currentTestName?.replaceAll(" ", "_").toLowerCase();
4256
- const validSqlFile = () => './logs/rest/' + testName() + '.json';
4257
- const logsFile = () => './logs/tests/' + testName() + '.log';
4258
- /* eslint-disable no-undef */
4259
- expect(document).not.toBeNull();
4260
- const orig = console;
4261
- // @link https://stackoverflow.com/questions/13542667/create-directory-when-writing-to-file-in-node-js
4262
- const superLogger = async (...args) => fs.writeFileSync(logsFile(), '\n' + inspect(args.length === 1 ? args.pop() : args, false, 10, true), { flag: "a+" });
4263
- // noinspection CommaExpressionJS
4264
- global.console = {
4265
- ...console,
4266
- // use jest.fn() to silence, comment out to leave as it is
4267
- log: (...args) => (isVerbose && orig.log(...args), superLogger('log', ...args)),
4268
- error: (...args) => (isVerbose && orig.error(...args), superLogger('error', ...args)),
4269
- warn: (...args) => (isVerbose && orig.warn(...args), superLogger('warn', ...args)),
4270
- info: (...args) => (isVerbose && orig.info(...args), superLogger('info', ...args)),
4271
- debug: (...args) => (isVerbose && orig.debug(...args), superLogger('debug', ...args)),
4272
- table: (...args) => (isVerbose && orig.table(...args), superLogger('table', ...args)),
4273
- trace: (...args) => (isVerbose && orig.trace(...args), superLogger((() => {
4274
- const err = new Error();
4275
- return err.stack;
4276
- })())),
4277
- group: (...args) => (isVerbose && orig.group(...args), superLogger('group', ...args)),
4278
- groupCollapsed: (...args) => (isVerbose && orig.groupCollapsed(args), superLogger('groupCollapsed', ...args)),
4279
- groupEnd: () => (isVerbose && orig.groupEnd(), superLogger('groupEnd')),
4280
- };
4281
- afterEach(async () => {
4282
- await waitFor(async () => {
4283
- expect(checkAllRequestsComplete()).toEqual(true);
4284
- }, { timeout: 3000, interval: 1000 });
4285
- // this must be a dynamic import to avoid loading dependencies out of order
4286
- // await waitForTrailingRequests({testPassed: true, timeout: 12000})
4287
- console.log('After each Test (' + expect.getState().currentTestName + ')', expect.getState());
4288
- // restore `window.location` to the original `jsdom`
4289
- // `Location` object
4290
- window.location = origionalWindowLocation;
4291
- fs.writeFileSync(validSqlFile(), JSON.stringify(validSQL, undefined, 2) ?? '');
4292
- }, 65000);
4254
+ function setupTests ({ sqlDirectory = './logs/rest/', logsDirectory = './logs/tests/' }) {
4255
+ const originalWindowLocation = window.location;
4256
+ const testName = () => expect.getState().currentTestName?.replaceAll(" ", "_").toLowerCase();
4257
+ const validSqlFile = () => sqlDirectory + testName() + '.json';
4258
+ const logsFile = () => logsDirectory + testName() + '.log';
4259
+ /* eslint-disable no-undef */
4260
+ expect(document).not.toBeNull();
4261
+ const orig = console;
4262
+ // @link https://stackoverflow.com/questions/13542667/create-directory-when-writing-to-file-in-node-js
4263
+ const asyncFileLogging = async (...args) => fs.writeFileSync(logsFile(), '\n' + inspect(args.length === 1 ? args.pop() : args, false, 10, true), { flag: "a+" });
4264
+ // noinspection CommaExpressionJS
4265
+ global.console = {
4266
+ ...console,
4267
+ // use jest.fn() to silence, comment out to leave as it is
4268
+ log: (...args) => (isVerbose && orig.log(...args), asyncFileLogging('log', ...args)),
4269
+ error: (...args) => (isVerbose && orig.error(...args), asyncFileLogging('error', ...args)),
4270
+ warn: (...args) => (isVerbose && orig.warn(...args), asyncFileLogging('warn', ...args)),
4271
+ info: (...args) => (isVerbose && orig.info(...args), asyncFileLogging('info', ...args)),
4272
+ debug: (...args) => (isVerbose && orig.debug(...args), asyncFileLogging('debug', ...args)),
4273
+ table: (...args) => (isVerbose && orig.table(...args), asyncFileLogging('table', ...args)),
4274
+ trace: (...args) => (isVerbose && orig.trace(...args), asyncFileLogging((() => {
4275
+ const err = new Error();
4276
+ return err.stack;
4277
+ })())),
4278
+ group: (...args) => (isVerbose && orig.group(...args), asyncFileLogging('group', ...args)),
4279
+ groupCollapsed: (...args) => (isVerbose && orig.groupCollapsed(args), asyncFileLogging('groupCollapsed', ...args)),
4280
+ groupEnd: () => (isVerbose && orig.groupEnd(), asyncFileLogging('groupEnd')),
4281
+ };
4282
+ afterEach(async () => {
4283
+ await waitFor(async () => {
4284
+ expect(checkAllRequestsComplete()).toEqual(true);
4285
+ }, { timeout: 3000, interval: 1000 });
4286
+ // this must be a dynamic import to avoid loading dependencies out of order
4287
+ // await waitForTrailingRequests({testPassed: true, timeout: 12000})
4288
+ console.log('After each Test (' + expect.getState().currentTestName + ')', expect.getState());
4289
+ // restore `window.location` to the original `jsdom`
4290
+ // `Location` object
4291
+ window.location = originalWindowLocation;
4292
+ fs.writeFileSync(validSqlFile(), JSON.stringify(validSQL, undefined, 2) ?? '');
4293
+ }, 65000);
4294
+ }
4293
4295
 
4294
4296
  var eUpdateInsertMethod;
4295
4297
  (function (eUpdateInsertMethod) {
@@ -4472,5 +4474,5 @@ function useWindowDimensions() {
4472
4474
  return windowDimensions;
4473
4475
  }
4474
4476
 
4475
- export { AccessDenied, Alert, BackendThrowable, C6, COLUMNS, CarbonReact, ErrorHttpCode, GlobalHistory, Loading, Nest, PageNotFound, Popup, TABLES, addAlert, addValidSQL$1 as addValidSQL, carbons, changed, comments, deleteRestfulObjectArrays, documentation, eUpdateInsertMethod, feature_group_references, features, getRootStyleValue, getStyles, globalNavigate, group_references, groups, hexToRgb, history_logs, initialCarbonReactState, initialRequiredCarbonORMState, initialRestfulObjectsState, isEdgeBrowser, isProduction, location_references, locations, parseMultipleJson, photos, range, reports, ScrollIntoViewDirective as scrollIntoView, setCookies, setUrl, toDataURL, updateRestfulObjectArrays, uploadImage, uploadImageChange, user_followers, user_groups, user_messages, user_sessions, user_tasks, users, validSQL$1 as validSQL, useWindowDimensions as windowDimensions, wp_commentmeta, wp_comments, wp_links, wp_options, wp_postmeta, wp_posts, wp_term_relationships, wp_term_taxonomy, wp_termmeta, wp_terms, wp_usermeta, wp_users };
4477
+ export { AccessDenied, Alert, BackendThrowable, C6, COLUMNS, CarbonReact, ErrorHttpCode, GlobalHistory, Loading, Nest, PageNotFound, Popup, TABLES, addAlert, addValidSQL$1 as addValidSQL, carbons, changed, comments, deleteRestfulObjectArrays, documentation, eUpdateInsertMethod, feature_group_references, features, getRootStyleValue, getStyles, globalNavigate, group_references, groups, hexToRgb, history_logs, initialCarbonReactState, initialRequiredCarbonORMState, initialRestfulObjectsState, isEdgeBrowser, isProduction, location_references, locations, parseMultipleJson, photos, range, reports, ScrollIntoViewDirective as scrollIntoView, setCookies, setUrl, setupTests, toDataURL, updateRestfulObjectArrays, uploadImage, uploadImageChange, user_followers, user_groups, user_messages, user_sessions, user_tasks, users, validSQL$1 as validSQL, useWindowDimensions as windowDimensions, wp_commentmeta, wp_comments, wp_links, wp_options, wp_postmeta, wp_posts, wp_term_relationships, wp_term_taxonomy, wp_termmeta, wp_terms, wp_usermeta, wp_users };
4476
4478
  //# sourceMappingURL=index.esm.js.map