@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.
@@ -1 +1,4 @@
1
- export {};
1
+ export default function ({ sqlDirectory, logsDirectory }: {
2
+ sqlDirectory: string;
3
+ logsDirectory: string;
4
+ }): void;
package/dist/index.cjs.js CHANGED
@@ -4253,45 +4253,47 @@ function validSQL$1 (sql) {
4253
4253
  validSQL.push({ [expect.getState().currentTestName.replaceAll(" ", "_").toLowerCase()]: sql });
4254
4254
  }
4255
4255
 
4256
- const origionalWindowLocation = window.location;
4257
- const testName = () => expect.getState().currentTestName?.replaceAll(" ", "_").toLowerCase();
4258
- const validSqlFile = () => './logs/rest/' + testName() + '.json';
4259
- const logsFile = () => './logs/tests/' + testName() + '.log';
4260
- /* eslint-disable no-undef */
4261
- expect(document).not.toBeNull();
4262
- const orig = console;
4263
- // @link https://stackoverflow.com/questions/13542667/create-directory-when-writing-to-file-in-node-js
4264
- const superLogger = async (...args) => fs.writeFileSync(logsFile(), '\n' + util.inspect(args.length === 1 ? args.pop() : args, false, 10, true), { flag: "a+" });
4265
- // noinspection CommaExpressionJS
4266
- global.console = {
4267
- ...console,
4268
- // use jest.fn() to silence, comment out to leave as it is
4269
- log: (...args) => (carbonnode.isVerbose && orig.log(...args), superLogger('log', ...args)),
4270
- error: (...args) => (carbonnode.isVerbose && orig.error(...args), superLogger('error', ...args)),
4271
- warn: (...args) => (carbonnode.isVerbose && orig.warn(...args), superLogger('warn', ...args)),
4272
- info: (...args) => (carbonnode.isVerbose && orig.info(...args), superLogger('info', ...args)),
4273
- debug: (...args) => (carbonnode.isVerbose && orig.debug(...args), superLogger('debug', ...args)),
4274
- table: (...args) => (carbonnode.isVerbose && orig.table(...args), superLogger('table', ...args)),
4275
- trace: (...args) => (carbonnode.isVerbose && orig.trace(...args), superLogger((() => {
4276
- const err = new Error();
4277
- return err.stack;
4278
- })())),
4279
- group: (...args) => (carbonnode.isVerbose && orig.group(...args), superLogger('group', ...args)),
4280
- groupCollapsed: (...args) => (carbonnode.isVerbose && orig.groupCollapsed(args), superLogger('groupCollapsed', ...args)),
4281
- groupEnd: () => (carbonnode.isVerbose && orig.groupEnd(), superLogger('groupEnd')),
4282
- };
4283
- afterEach(async () => {
4284
- await react$1.waitFor(async () => {
4285
- expect(carbonnode.checkAllRequestsComplete()).toEqual(true);
4286
- }, { timeout: 3000, interval: 1000 });
4287
- // this must be a dynamic import to avoid loading dependencies out of order
4288
- // await waitForTrailingRequests({testPassed: true, timeout: 12000})
4289
- console.log('After each Test (' + expect.getState().currentTestName + ')', expect.getState());
4290
- // restore `window.location` to the original `jsdom`
4291
- // `Location` object
4292
- window.location = origionalWindowLocation;
4293
- fs.writeFileSync(validSqlFile(), JSON.stringify(validSQL, undefined, 2) ?? '');
4294
- }, 65000);
4256
+ function setupTests ({ sqlDirectory = './logs/rest/', logsDirectory = './logs/tests/' }) {
4257
+ const originalWindowLocation = window.location;
4258
+ const testName = () => expect.getState().currentTestName?.replaceAll(" ", "_").toLowerCase();
4259
+ const validSqlFile = () => sqlDirectory + testName() + '.json';
4260
+ const logsFile = () => logsDirectory + testName() + '.log';
4261
+ /* eslint-disable no-undef */
4262
+ expect(document).not.toBeNull();
4263
+ const orig = console;
4264
+ // @link https://stackoverflow.com/questions/13542667/create-directory-when-writing-to-file-in-node-js
4265
+ const asyncFileLogging = async (...args) => fs.writeFileSync(logsFile(), '\n' + util.inspect(args.length === 1 ? args.pop() : args, false, 10, true), { flag: "a+" });
4266
+ // noinspection CommaExpressionJS
4267
+ global.console = {
4268
+ ...console,
4269
+ // use jest.fn() to silence, comment out to leave as it is
4270
+ log: (...args) => (carbonnode.isVerbose && orig.log(...args), asyncFileLogging('log', ...args)),
4271
+ error: (...args) => (carbonnode.isVerbose && orig.error(...args), asyncFileLogging('error', ...args)),
4272
+ warn: (...args) => (carbonnode.isVerbose && orig.warn(...args), asyncFileLogging('warn', ...args)),
4273
+ info: (...args) => (carbonnode.isVerbose && orig.info(...args), asyncFileLogging('info', ...args)),
4274
+ debug: (...args) => (carbonnode.isVerbose && orig.debug(...args), asyncFileLogging('debug', ...args)),
4275
+ table: (...args) => (carbonnode.isVerbose && orig.table(...args), asyncFileLogging('table', ...args)),
4276
+ trace: (...args) => (carbonnode.isVerbose && orig.trace(...args), asyncFileLogging((() => {
4277
+ const err = new Error();
4278
+ return err.stack;
4279
+ })())),
4280
+ group: (...args) => (carbonnode.isVerbose && orig.group(...args), asyncFileLogging('group', ...args)),
4281
+ groupCollapsed: (...args) => (carbonnode.isVerbose && orig.groupCollapsed(args), asyncFileLogging('groupCollapsed', ...args)),
4282
+ groupEnd: () => (carbonnode.isVerbose && orig.groupEnd(), asyncFileLogging('groupEnd')),
4283
+ };
4284
+ afterEach(async () => {
4285
+ await react$1.waitFor(async () => {
4286
+ expect(carbonnode.checkAllRequestsComplete()).toEqual(true);
4287
+ }, { timeout: 3000, interval: 1000 });
4288
+ // this must be a dynamic import to avoid loading dependencies out of order
4289
+ // await waitForTrailingRequests({testPassed: true, timeout: 12000})
4290
+ console.log('After each Test (' + expect.getState().currentTestName + ')', expect.getState());
4291
+ // restore `window.location` to the original `jsdom`
4292
+ // `Location` object
4293
+ window.location = originalWindowLocation;
4294
+ fs.writeFileSync(validSqlFile(), JSON.stringify(validSQL, undefined, 2) ?? '');
4295
+ }, 65000);
4296
+ }
4295
4297
 
4296
4298
  exports.eUpdateInsertMethod = void 0;
4297
4299
  (function (eUpdateInsertMethod) {
@@ -4516,6 +4518,7 @@ exports.reports = reports;
4516
4518
  exports.scrollIntoView = ScrollIntoViewDirective;
4517
4519
  exports.setCookies = setCookies;
4518
4520
  exports.setUrl = setUrl;
4521
+ exports.setupTests = setupTests;
4519
4522
  exports.toDataURL = toDataURL;
4520
4523
  exports.updateRestfulObjectArrays = updateRestfulObjectArrays;
4521
4524
  exports.uploadImage = uploadImage;