How to use runCount method in qawolf

Best JavaScript code snippet using qawolf

main.test.ts

Source:main.test.ts Github

copy

Full Screen

1import FakeTimers from "@sinonjs/fake-timers";2import chai from "chai";3import { expect } from "chai";4import chaiAsPromised from "chai-as-promised";5import PromiseLikeClass from "promise-polyfill";6import timeSpan from "time-span";7import { expectType, TypeEqual } from "ts-expect";8import util from "util";9import { Batcher, BATCHER_RETRY_TOKEN, BatcherOptions, BatchingResult } from "./imports";10const clock = FakeTimers.install();11const debug = util.debuglog("promise-batcher:test");12chai.use(chaiAsPromised);13// Make the promise like the PromiseLike interface14// @ts-expect-error: deleting a required type15delete PromiseLikeClass.prototype.catch;16// @ts-expect-error: deleting a required type17delete PromiseLikeClass.prototype.finally;18/**19 * Milliseconds per tick.20 */21const TICK = 100;22/**23 * Returns a promise which waits the specified amount of time before resolving.24 */25const wait = util.promisify(setTimeout);26/**27 * Maximum number of timers to advance before giving up. This is used to prevent infinite loops.28 */29const MAX_TIMER_ADVANCE = 100;30/**31 * Uses SinonJS Fake Timers to wait for a promise to complete.32 */33async function fakeAwait<T>(promise: Promise<T>): Promise<T> {34 let done = false;35 try {36 const v = await Promise.race([37 promise,38 (async () => {39 for (let timerCount = 0; timerCount < MAX_TIMER_ADVANCE; timerCount++) {40 if (done) {41 // exit the timer loop; this error should never be caught42 throw new Error("fakeAwait: done");43 }44 if ((await clock.nextAsync()) === 0) {45 throw new Error("fakeAwait: no timers to advance");46 }47 }48 throw new Error("fakeAwait: too many timers");49 })(),50 ]);51 done = true;52 return v;53 } catch (err: unknown) {54 done = true;55 throw err;56 }57}58// istanbul ignore next59function unhandledRejectionListener(err: unknown) {60 debug("unhandledRejectionListener: %O", (err as Error).stack);61 // Fail the test62 throw new Error("UnhandledPromiseRejection: " + (err as Error).message);63}64beforeEach(() => {65 process.removeAllListeners("unhandledRejection");66 process.addListener("unhandledRejection", unhandledRejectionListener);67});68describe("Batcher", () => {69 it("Core Functionality", async () => {70 let runCount = 0;71 const batcher = new Batcher<number, string>({72 batchingFunction: async (input) => {73 runCount++;74 await wait(TICK);75 return input.map(String);76 },77 });78 const inputs = [1, 5, 9];79 const elapsed = timeSpan();80 await fakeAwait(81 Promise.all(82 inputs.map(async (input) => {83 const output = await batcher.getResult(input);84 expect(output).to.equal(String(input), "Outputs");85 expect(elapsed()).to.equal(TICK + 1, "Timing Results");86 }),87 ),88 );89 expect(runCount).to.equal(1, "runCount");90 });91 it("Offset Batches", async () => {92 // Runs two batches of requests, offset so the seconds starts while the first is half finished.93 // The second batch should start before the first finishes.94 const elapsed = timeSpan();95 let runCount = 0;96 const batcher = new Batcher<number, string>({97 batchingFunction: async (input) => {98 runCount++;99 await wait(2 * TICK);100 return input.map(String);101 },102 });103 const inputs = [104 [1, 9],105 [5, 7],106 ];107 await fakeAwait(108 Promise.all(109 inputs.map(async (input, index) => {110 await wait(index * TICK);111 await Promise.all(112 input.map(async (value, index2) => {113 const result = await batcher.getResult(value);114 expect(result).to.equal(String(value));115 expect(elapsed()).to.equal((index + 2) * TICK + 1, `Timing result (${index},${index2})`);116 }),117 );118 }),119 ),120 );121 expect(runCount).to.equal(2, "runCount");122 });123 it("Delay Function", async () => {124 let runCount = 0;125 const batcher = new Batcher<undefined, undefined>({126 batchingFunction: async (input) => {127 runCount++;128 await wait(1);129 return input;130 },131 delayFunction: () => wait(TICK),132 maxBatchSize: 2,133 });134 const inputs = [1, 5, 9];135 const elapsed = timeSpan();136 const times = await fakeAwait(137 Promise.all(138 inputs.map(async () => {139 await batcher.getResult(undefined);140 return elapsed();141 }),142 ),143 );144 expect(times).to.deep.equal([TICK + 1, TICK + 1, 2 * TICK + 2], "Timing Results");145 expect(runCount).to.equal(2, "runCount");146 });147 it("Delay Function (PromiseLike)", async () => {148 const batcher = new Batcher<undefined, undefined>({149 batchingFunction: (input) => {150 return PromiseLikeClass.resolve(wait(TICK)).then(() => input);151 },152 delayFunction: () => PromiseLikeClass.resolve(wait(TICK)),153 maxBatchSize: 2,154 });155 const elapsed = timeSpan();156 await fakeAwait(batcher.getResult(undefined));157 expect(elapsed()).to.equal(2 * TICK + 2, "Timing Results");158 });159 describe("options.maxBatchSize", () => {160 it("Core Functionality", async () => {161 let runCount = 0;162 const batcher = new Batcher<number, string>({163 batchingFunction: async (input) => {164 runCount++;165 await wait(TICK);166 return input.map(String);167 },168 maxBatchSize: 2,169 });170 const elapsed = timeSpan();171 await fakeAwait(172 Promise.all(173 [1, 5, 9].map(async (input, i) => {174 const output = await batcher.getResult(input);175 expect(output).to.equal(String(input), "Outputs");176 expect(elapsed()).to.equal(TICK + Math.floor(i / 2), "Timing Results");177 }),178 ),179 );180 expect(runCount).to.equal(2, "runCount");181 });182 it("Instant Start", async () => {183 let runCount = 0;184 const batcher = new Batcher<undefined, undefined>({185 batchingFunction: async (input) => {186 runCount++;187 await wait(TICK);188 return input;189 },190 maxBatchSize: 2,191 });192 const runCounts = [0, 1, 1];193 await fakeAwait(194 Promise.all(195 runCounts.map((expectedRunCount) => {196 // The batching function should be triggered instantly when the max batch size is reached197 const promise = batcher.getResult(undefined);198 expect(runCount).to.equal(expectedRunCount);199 return promise;200 }),201 ),202 );203 });204 });205 it("options.queuingDelay", async () => {206 let runCount = 0;207 const batcher = new Batcher<undefined, undefined>({208 batchingFunction: async (input) => {209 runCount++;210 return new Array<undefined>(input.length);211 },212 queuingDelay: TICK * 2,213 });214 const delays = [0, 1, 3];215 const elapsed = timeSpan();216 const results = await fakeAwait(217 Promise.all(218 delays.map(async (delay) => {219 await wait(delay * TICK);220 await batcher.getResult(undefined);221 return elapsed();222 }),223 ),224 );225 expect(results).to.deep.equal([2 * TICK, 2 * TICK, 5 * TICK], "Timing Results");226 expect(runCount).to.equal(2, "runCount");227 });228 describe("options.queuingThresholds", () => {229 it("Core Functionality", async () => {230 let runCount = 0;231 const batcher = new Batcher<undefined, undefined>({232 batchingFunction: async (input) => {233 runCount++;234 await wait(5 * TICK);235 return new Array<undefined>(input.length);236 },237 queuingThresholds: [1, 2],238 });239 const delays = [0, 1, 2, 3, 4];240 const elapsed = timeSpan();241 const results = await fakeAwait(242 Promise.all(243 delays.map(async (delay) => {244 await wait(delay * TICK);245 await batcher.getResult(undefined);246 return elapsed();247 }),248 ),249 );250 expect(results).to.deep.equal(251 [5 * TICK + 1, 7 * TICK + 1, 7 * TICK + 1, 9 * TICK + 1, 9 * TICK + 1],252 "Timing Results",253 );254 expect(runCount).to.equal(3, "runCount");255 });256 it("Should Trigger On Batch Completion", async () => {257 const batcher = new Batcher<undefined, undefined>({258 batchingFunction: async (input) => {259 await wait(2 * TICK);260 return new Array<undefined>(input.length);261 },262 queuingThresholds: [1, 2],263 });264 const delays = [0, 1];265 const elapsed = timeSpan();266 const results = await fakeAwait(267 Promise.all(268 delays.map(async (delay) => {269 await wait(delay * TICK);270 await batcher.getResult(undefined);271 return elapsed();272 }),273 ),274 );275 expect(results).to.deep.equal([2 * TICK + 1, 4 * TICK + 2], "Timing Results");276 });277 it("Delay After Hitting Queuing Threshold", async () => {278 let runCount = 0;279 const batcher = new Batcher<undefined, undefined>({280 batchingFunction: async (input) => {281 runCount++;282 await wait(3 * TICK);283 return new Array<undefined>(input.length);284 },285 queuingDelay: TICK,286 queuingThresholds: [1, Infinity],287 });288 const elapsed = timeSpan();289 const results = await fakeAwait(290 Promise.all([291 (async () => {292 await batcher.getResult(undefined);293 await batcher.getResult(undefined);294 return elapsed();295 })(),296 (async () => {297 await wait(2 * TICK);298 await batcher.getResult(undefined);299 return elapsed();300 })(),301 ]),302 );303 expect(results).to.deep.equal([8 * TICK, 8 * TICK], "Timing Results");304 expect(runCount).to.equal(2, "runCount");305 });306 it("Obey Queuing Threshold Even When Hitting maxBatchSize", async () => {307 const batcher = new Batcher<undefined, undefined>({308 batchingFunction: async (input) => {309 await wait(TICK);310 return new Array<undefined>(input.length);311 },312 maxBatchSize: 1,313 queuingThresholds: [1, Infinity],314 });315 const elapsed = timeSpan();316 const results = await fakeAwait(317 Promise.all(318 [0, 1].map(async () => {319 await batcher.getResult(undefined);320 return elapsed();321 }),322 ),323 );324 expect(results).to.deep.equal([TICK, 2 * TICK], "Timing Results");325 });326 });327 describe("Retries", () => {328 it("Full", async () => {329 let batchNumber = 0;330 let runCount = 0;331 const batcher = new Batcher<number, number>({332 batchingFunction: async (inputs) => {333 runCount++;334 await wait(TICK);335 batchNumber++;336 if (batchNumber < 2) {337 return inputs.map((): typeof BATCHER_RETRY_TOKEN => BATCHER_RETRY_TOKEN);338 }339 return inputs.map((input) => input + 1);340 },341 });342 const elapsed = timeSpan();343 const results = await fakeAwait(344 Promise.all(345 [1, 2].map(async (input) => {346 const output = await batcher.getResult(input);347 expect(output).to.equal(input + 1, "getResult output");348 return elapsed();349 }),350 ),351 );352 expect(results).to.deep.equal([2 * TICK + 2, 2 * TICK + 2], "Timing Results");353 expect(runCount).to.equal(2, "runCount");354 });355 it("Partial", async () => {356 let batchNumber = 0;357 let runCount = 0;358 const batcher = new Batcher<number, number>({359 batchingFunction: async (inputs) => {360 runCount++;361 await wait(TICK);362 batchNumber++;363 return inputs.map((input, index) => {364 return batchNumber < 2 && index < 1 ? BATCHER_RETRY_TOKEN : input + 1;365 });366 },367 });368 const elapsed = timeSpan();369 const results = await fakeAwait(370 Promise.all(371 [1, 2].map(async (input) => {372 const output = await batcher.getResult(input);373 expect(output).to.equal(input + 1, "getResult output");374 return elapsed();375 }),376 ),377 );378 expect(results).to.deep.equal([2 * TICK + 2, TICK + 1], "Timing Results");379 expect(runCount).to.equal(2, "runCount");380 });381 it("Ordering", async () => {382 const batchInputs: number[][] = [];383 const batcher = new Batcher<number, number>({384 batchingFunction: async (inputs) => {385 batchInputs.push(inputs.slice());386 await wait(TICK);387 return inputs.map((input, index) => {388 return batchInputs.length < 2 && index < 2 ? BATCHER_RETRY_TOKEN : input + 1;389 });390 },391 maxBatchSize: 3,392 queuingThresholds: [1, Infinity],393 });394 const elapsed = timeSpan();395 const results = await fakeAwait(396 Promise.all(397 [1, 2, 3, 4].map(async (input) => {398 const output = await batcher.getResult(input);399 expect(output).to.equal(input + 1, "getResult output");400 return elapsed();401 }),402 ),403 );404 expect(results).to.deep.equal([2 * TICK, 2 * TICK, TICK, 2 * TICK], "Timing Results");405 expect(batchInputs).to.deep.equal(406 [407 [1, 2, 3],408 [1, 2, 4],409 ],410 "batchInputs",411 );412 });413 });414 describe(".prototype.send", () => {415 it("Single Use", async () => {416 let runCount = 0;417 const batcher = new Batcher<undefined, undefined>({418 batchingFunction: async (inputs) => {419 runCount++;420 await wait(TICK);421 return inputs;422 },423 queuingDelay: TICK,424 queuingThresholds: [1, Infinity],425 });426 const elapsed = timeSpan();427 const results = await fakeAwait(428 Promise.all(429 [1, 2, 3].map(async (_, index) => {430 const promise = batcher.getResult(undefined);431 if (index === 1) {432 expect(runCount).to.equal(0, "runCount before");433 batcher.send();434 expect(runCount).to.equal(1, "runCount after");435 }436 await promise;437 return elapsed();438 }),439 ),440 );441 expect(results).to.deep.equal([TICK, TICK, 3 * TICK], "Timing Results");442 });443 it("Effect Delayed By queuingThreshold", async () => {444 let runCount = 0;445 const batcher = new Batcher<undefined, undefined>({446 batchingFunction: async (inputs) => {447 runCount++;448 await wait(TICK);449 return inputs;450 },451 queuingDelay: TICK,452 queuingThresholds: [1, Infinity],453 });454 const elapsed = timeSpan();455 const results = await fakeAwait(456 Promise.all(457 [1, 2, 3].map(async (_, index) => {458 const promise = batcher.getResult(undefined);459 if (index === 1) {460 expect(runCount).to.equal(0, "runCount before");461 batcher.send();462 expect(runCount).to.equal(1, "runCount after");463 } else if (index === 2) {464 batcher.send();465 expect(runCount).to.equal(1, "runCount after second");466 }467 await promise;468 return elapsed();469 }),470 ),471 );472 expect(results).to.deep.equal([TICK, TICK, 2 * TICK], "Timing Results");473 });474 it("Effect Delayed By delayFunction", async () => {475 // This tests that the effect of the send method still obeys the delayFunction and that the effect476 // lasts even after a previous batch has been delayed by the delayFunction.477 const batcher = new Batcher<undefined, undefined>({478 batchingFunction: async (inputs) => {479 await wait(TICK);480 return inputs;481 },482 delayFunction: () => wait(TICK),483 maxBatchSize: 2,484 queuingThresholds: [1, Infinity],485 });486 const elapsed = timeSpan();487 const results = await fakeAwait(488 Promise.all(489 [1, 2, 3].map(async (_, index) => {490 const promise = batcher.getResult(undefined);491 if (index === 2) {492 batcher.send();493 }494 await promise;495 return elapsed();496 }),497 ),498 );499 expect(results).to.deep.equal([2 * TICK, 2 * TICK, 4 * TICK], "Timing Results");500 });501 it("Interaction With Retries", async () => {502 // This tests that the effect of the send method lasts even after a retry503 let runCount = 0;504 const batcher = new Batcher<undefined, undefined>({505 batchingFunction: async (inputs) => {506 runCount++;507 await wait(TICK);508 return runCount === 1 ? inputs.map((): typeof BATCHER_RETRY_TOKEN => BATCHER_RETRY_TOKEN) : inputs;509 },510 queuingDelay: TICK,511 queuingThresholds: [1, Infinity],512 });513 const elapsed = timeSpan();514 const results = await fakeAwait(515 Promise.all(516 [1, 2, 3].map(async (_, index) => {517 const promise = batcher.getResult(undefined);518 if (index >= 1) {519 batcher.send();520 }521 await promise;522 return elapsed();523 }),524 ),525 );526 expect(runCount).to.equal(2, "runCount");527 expect(results).to.deep.equal([2 * TICK, 2 * TICK, 2 * TICK], "Timing Results");528 });529 });530 describe(".prototype.idlePromise", () => {531 it("Nothing queued", async () => {532 const batcher = new Batcher<undefined, undefined>({533 batchingFunction: async (inputs) => inputs,534 });535 await batcher.idlePromise();536 });537 it("Waits for batches", async () => {538 const batcher = new Batcher<undefined, undefined>({539 batchingFunction: async (inputs) => {540 await wait(TICK);541 return inputs;542 },543 maxBatchSize: 1,544 queuingThresholds: [1, 9],545 });546 const elapsed = timeSpan();547 expect(batcher.idling).eq(true);548 void batcher.getResult(undefined);549 expect(batcher.idling).eq(false);550 await fakeAwait(Promise.all([batcher.idlePromise(), batcher.idlePromise(), batcher.getResult(undefined)]));551 expect(batcher.idling).eq(true);552 expect(elapsed()).eq(2 * TICK);553 });554 });555 describe("Error Handling", () => {556 it("Single Rejection", async () => {557 const batcher = new Batcher<string, undefined>({558 batchingFunction: async (input) => {559 await wait(TICK);560 return input.map((value) => {561 return value === "error" ? new Error("test") : undefined;562 });563 },564 });565 const inputs = ["a", "error", "b"];566 const results = await fakeAwait(567 Promise.all(568 inputs.map(async (input) => {569 try {570 await batcher.getResult(input);571 return true;572 } catch (err: unknown) {573 expect((err as Error).message).to.equal("test");574 return false;575 }576 }),577 ),578 );579 expect(results).to.deep.equal([true, false, true]);580 });581 it("Synchronous Batching Function Exception Followed By Success", async () => {582 const batcher = new Batcher<number, undefined>({583 batchingFunction: (input) => {584 if (input.includes(0)) {585 throw new Error("test");586 }587 return wait(1).then(() => new Array<undefined>(input.length));588 },589 maxBatchSize: 2,590 });591 const inputs = [0, 1, 2];592 const results = await fakeAwait(593 Promise.all(594 inputs.map(async (input) => {595 try {596 await batcher.getResult(input);597 return true;598 } catch (err: unknown) {599 expect((err as Error).message).to.equal("test");600 return false;601 }602 }),603 ),604 );605 expect(results).to.deep.equal([false, false, true]);606 });607 it("Asynchronous Batching Function Exception Followed By Success", async () => {608 const batcher = new Batcher<number, undefined>({609 batchingFunction: async (input) => {610 await wait(1);611 input.forEach((value) => {612 if (value === 0) {613 throw new Error("test");614 }615 });616 return new Array<undefined>(input.length);617 },618 maxBatchSize: 2,619 });620 await fakeAwait(621 Promise.all(622 [0, 1].map(async (input) => {623 await expect(batcher.getResult(input)).to.be.rejectedWith(Error, "test");624 }),625 ),626 );627 await fakeAwait(batcher.getResult(1));628 });629 it("Synchronous Delay Exception Followed By Success", async () => {630 let runCount = 0;631 const batcher = new Batcher<undefined, undefined>({632 batchingFunction: async (input) => {633 await wait(1);634 return input;635 },636 delayFunction: () => {637 runCount++;638 if (runCount < 2) {639 throw new Error("test");640 }641 },642 maxBatchSize: 2,643 });644 await fakeAwait(645 Promise.all(646 [0, 1].map(async () => {647 await expect(batcher.getResult(undefined)).to.be.rejectedWith(Error, "test");648 }),649 ),650 );651 await fakeAwait(batcher.getResult(undefined));652 });653 it("Asynchronous Delay Exception Followed By Success", async () => {654 let runCount = 0;655 const batcher = new Batcher<undefined, undefined>({656 batchingFunction: async (input) => {657 await wait(1);658 return input;659 },660 delayFunction: async () => {661 await wait(1);662 runCount++;663 if (runCount < 2) {664 throw new Error("test");665 }666 },667 maxBatchSize: 2,668 });669 await fakeAwait(670 Promise.all(671 [0, 1].map(async () => {672 await expect(batcher.getResult(undefined)).to.be.rejectedWith(Error, "test");673 }),674 ),675 );676 await fakeAwait(batcher.getResult(undefined));677 });678 it("Invalid Output Type", async () => {679 const batcher = new Batcher<number, undefined>({680 batchingFunction: () => {681 return "test" as unknown as undefined[];682 },683 });684 const inputs = [0, 1, 2];685 await fakeAwait(686 Promise.all(687 inputs.map(async (input) => {688 await expect(batcher.getResult(input)).to.be.rejectedWith(689 /^batchingFunction must return an array$/,690 );691 }),692 ),693 );694 });695 it("Invalid Output Length", async () => {696 const batcher = new Batcher<number, undefined>({697 batchingFunction: async (input) => {698 // Respond with an array larger than the input699 await wait(1);700 return new Array<undefined>(input.length + 1);701 },702 });703 const inputs = [0, 1, 2];704 await fakeAwait(705 Promise.all(706 inputs.map(async (input) => {707 await expect(batcher.getResult(input)).to.be.rejectedWith(708 Error,709 /^batchingFunction output length does not equal the input length$/,710 );711 }),712 ),713 );714 });715 });716 describe("Invalid Options", () => {717 it("options.maxBatchSize < 1", () => {718 expect(719 () =>720 new Batcher({721 batchingFunction: 1 as unknown as () => [],722 maxBatchSize: 0,723 }),724 ).to.throw(/^options\.maxBatchSize must be greater than 0$/);725 });726 it("options.queuingThresholds.length = 0", () => {727 expect(728 () =>729 new Batcher({730 batchingFunction: 1 as unknown as () => [],731 queuingThresholds: [],732 }),733 ).to.throw(/^options\.queuingThresholds must contain at least one number$/);734 });735 it("options.queuingThresholds[*] < 1", () => {736 expect(737 () =>738 new Batcher({739 batchingFunction: 1 as unknown as () => [],740 queuingThresholds: [0],741 }),742 ).to.throw(/^options.queuingThresholds must only contain numbers greater than 0$/);743 });744 it("options.queuingDelay < 0", () => {745 expect(746 () =>747 new Batcher({748 batchingFunction: 1 as unknown as () => [],749 queuingDelay: -1,750 }),751 ).to.throw(/^options.queuingDelay must be greater than or equal to 0$/);752 });753 });754 it("Typings", async () => {755 const options: BatcherOptions<number, string> = {756 // @ts-expect-error: invalid return type757 batchingFunction: async (input) => {758 expectType<TypeEqual<typeof input, readonly number[]>>(true);759 return input;760 },761 };762 expectType<TypeEqual<BatchingResult<string>, string | Error | typeof BATCHER_RETRY_TOKEN>>(true);763 const batcher = new Batcher<number, string>(options);764 expectType<TypeEqual<Parameters<typeof batcher["getResult"]>, [number]>>(true);765 expectType<TypeEqual<ReturnType<typeof batcher["getResult"]>, Promise<string>>>(true);766 });...

Full Screen

Full Screen

effect.spec.ts

Source:effect.spec.ts Github

copy

Full Screen

1import { IObservation, observable } from '@aurelia/runtime';2import { assert, createFixture } from '@aurelia/testing';3describe('3-runtime-html/effect.spec.ts', function () {4 it('runs effect with @observable', async function () {5 const { ctx, component, startPromise, tearDown } = createFixture('<div ref="div"></div>', class App {6 public div: HTMLDivElement;7 });8 await startPromise;9 class MouseTracker {10 @observable()11 public coord: [number, number] = [0, 0];12 public pretendMouseMove(x: number, y: number): void {13 this.coord = [x, y];14 }15 }16 assert.instanceOf(component.div, ctx.Element);17 let runCount = 0;18 const div = component.div;19 const observation = ctx.container.get(IObservation);20 const mouseTracker = new MouseTracker();21 const effect = observation.run(() => {22 runCount++;23 div.textContent = mouseTracker.coord.join(', ');24 });25 assert.strictEqual(runCount, 1);26 assert.strictEqual(div.textContent, '0, 0');27 mouseTracker.pretendMouseMove(1, 2);28 assert.strictEqual(runCount, 2);29 assert.strictEqual(div.textContent, '1, 2');30 effect.stop();31 mouseTracker.pretendMouseMove(3, 4);32 assert.strictEqual(runCount, 2);33 assert.strictEqual(div.textContent, '1, 2');34 await tearDown();35 mouseTracker.pretendMouseMove(5, 6);36 assert.strictEqual(runCount, 2);37 assert.strictEqual(div.textContent, '1, 2');38 });39 it('does not track @observable accessed outside of effect', async function () {40 const { ctx, component, startPromise, tearDown } = createFixture('<div ref="div"></div>', class App {41 public div: HTMLDivElement;42 });43 await startPromise;44 class MouseTracker {45 @observable()46 public coord: [number, number] = [0, 0];47 public pretendMouseMove(x: number, y: number): void {48 this.coord = [x, y];49 }50 }51 assert.instanceOf(component.div, ctx.Element);52 let runCount = 0;53 const div = component.div;54 const observation = ctx.container.get(IObservation);55 const mouseTracker = new MouseTracker();56 const { coord } = mouseTracker;57 const effect = observation.run(() => {58 runCount++;59 div.textContent = coord.join(', ');60 });61 assert.strictEqual(runCount, 1);62 assert.strictEqual(div.textContent, '0, 0');63 mouseTracker.pretendMouseMove(1, 2);64 assert.strictEqual(runCount, 1);65 assert.strictEqual(div.textContent, '0, 0');66 effect.stop();67 mouseTracker.pretendMouseMove(3, 4);68 assert.strictEqual(runCount, 1);69 assert.strictEqual(div.textContent, '0, 0');70 await tearDown();71 mouseTracker.pretendMouseMove(5, 6);72 assert.strictEqual(runCount, 1);73 assert.strictEqual(div.textContent, '0, 0');74 });75 it('does not track @observable accessed inside a promise inside an effect', async function () {76 const { ctx, component, startPromise, tearDown } = createFixture('<div ref="div"></div>', class App {77 public div: HTMLDivElement;78 });79 await startPromise;80 class MouseTracker {81 @observable()82 public coord: [number, number] = [0, 0];83 public pretendMouseMove(x: number, y: number): void {84 this.coord = [x, y];85 }86 }87 assert.instanceOf(component.div, ctx.Element);88 let runCount = 0;89 const div = component.div;90 const observation = ctx.container.get(IObservation);91 const mouseTracker = new MouseTracker();92 const effect = observation.run(() => {93 runCount++;94 Promise.resolve().then(() => {95 div.textContent = mouseTracker.coord.join(', ');96 }).catch(ex => {97 div.textContent = String(ex);98 });99 });100 assert.strictEqual(runCount, 1);101 assert.strictEqual(div.textContent, '');102 await Promise.resolve();103 assert.strictEqual(div.textContent, '0, 0');104 mouseTracker.pretendMouseMove(1, 2);105 assert.strictEqual(runCount, 1);106 assert.strictEqual(div.textContent, '0, 0');107 await Promise.resolve();108 assert.strictEqual(div.textContent, '0, 0');109 effect.stop();110 mouseTracker.pretendMouseMove(3, 4);111 assert.strictEqual(runCount, 1);112 assert.strictEqual(div.textContent, '0, 0');113 await Promise.resolve();114 assert.strictEqual(div.textContent, '0, 0');115 await tearDown();116 mouseTracker.pretendMouseMove(5, 6);117 assert.strictEqual(runCount, 1);118 assert.strictEqual(div.textContent, '0, 0');119 await Promise.resolve();120 assert.strictEqual(div.textContent, '0, 0');121 });122 it('runs recursive effect with @observable', async function () {123 const { ctx, component, startPromise, tearDown } = createFixture('<div ref="div"></div>', class App {124 public div: HTMLDivElement;125 });126 await startPromise;127 class MouseTracker {128 @observable()129 public coord: [number, number] = [0, 0];130 public pretendMouseMove(x: number, y: number): void {131 this.coord = [x, y];132 }133 }134 assert.instanceOf(component.div, ctx.Element);135 let runCount = 0;136 const div = component.div;137 const observation = ctx.container.get(IObservation);138 const mouseTracker = new MouseTracker();139 const effect = observation.run(() => {140 runCount++;141 div.textContent = mouseTracker.coord.join(', ');142 if (runCount < 10) {143 mouseTracker.coord = [runCount, runCount];144 } else {145 runCount = 0;146 }147 });148 assert.strictEqual(runCount, 0);149 assert.strictEqual(div.textContent, '9, 9');150 mouseTracker.pretendMouseMove(1, 2);151 assert.strictEqual(runCount, 0);152 assert.strictEqual(div.textContent, '9, 9');153 effect.stop();154 runCount = 1;155 mouseTracker.pretendMouseMove(3, 4);156 assert.strictEqual(runCount, 1);157 assert.strictEqual(div.textContent, '9, 9');158 await tearDown();159 mouseTracker.pretendMouseMove(5, 6);160 assert.strictEqual(runCount, 1);161 assert.strictEqual(div.textContent, '9, 9');162 });163 it('runs recursive effect with @observable until max', async function () {164 const { ctx, component, startPromise, tearDown } = createFixture('<div ref="div"></div>', class App {165 public div: HTMLDivElement;166 });167 await startPromise;168 class MouseTracker {169 @observable()170 public coord: [number, number] = [0, 0];171 public pretendMouseMove(x: number, y: number): void {172 this.coord = [x, y];173 }174 }175 assert.instanceOf(component.div, ctx.Element);176 let runCount = 0;177 let errorCaught = null;178 const div = component.div;179 const observation = ctx.container.get(IObservation);180 const mouseTracker = new MouseTracker();181 try {182 // stack:183 // --------184 // effect.run()185 // effect_fn() <--- IEffect starts running here186 // mutate(.coord)187 // Flushqueue.queue188 // SetterNotifier(.coord).flush189 // effect.handleChange <--- IEffect queues new run here and bails190 // effect is still [queued]191 // effect.run() <-- repeats the line above and this for the run, until max recursion exceeded192 observation.run(() => {193 runCount++;194 div.textContent = mouseTracker.coord.join(', ');195 if (runCount < 20) {196 mouseTracker.coord = [runCount, runCount];197 } else {198 runCount = 0;199 }200 });201 } catch (ex) {202 errorCaught = ex;203 }204 assert.instanceOf(errorCaught, Error);205 // 11 because effect only run recursively 10 items max206 assert.strictEqual(runCount, 11);207 assert.strictEqual(div.textContent, '10, 10');208 runCount = 0;209 errorCaught = null;210 try {211 mouseTracker.pretendMouseMove(1, 2);212 } catch (ex) {213 errorCaught = ex;214 }215 // different with the initial run above216 // effect is not already running during the mutation with "pretendMouseMove"217 // so that it will immediately complete a run218 // and thus, never throws an error on maximum recursion exceeded219 // stack:220 // --------221 // mutate(.coord)222 // Flushqueue.queue223 // SetterNotifier(.coord).flush224 // IEffect.handleChange225 // effect_fn()226 // mutate(.coord)227 // flush_queue.queue <--- IEffect stops running here228 // SetterNotifier(.coord).flush229 // IEffect.handleChange <--- IEffect starts running again, no recursion230 assert.strictEqual(errorCaught, null);231 assert.strictEqual(runCount, 0);232 assert.strictEqual(div.textContent, '19, 19');233 await tearDown();234 // effect are independent of application235 // so even after app torn down, it still runs236 // can only stop it via `effect.stop()`237 runCount = 10;238 errorCaught = null;239 try {240 mouseTracker.pretendMouseMove(1, 2);241 } catch (ex) {242 errorCaught = ex;243 }244 assert.strictEqual(errorCaught, null);245 assert.strictEqual(runCount, 0);246 assert.strictEqual(div.textContent, '19, 19');247 });...

Full Screen

Full Screen

generatedata-dataattributes.js

Source:generatedata-dataattributes.js Github

copy

Full Screen

1// Include all APIs and components to pull data2const dotenv = require('dotenv');3const path = require("path");4const uuid = require('uuid');5const crypto = require('crypto');6const config = process.env7dotenv.config({ path: path.resolve(__dirname, './.env') })8const db = require("./connectivity/general/connectors/dbConnections/postgresqlConnect")9const queryBuilder = require('./general/datatier/reusableQueries');10const express = require("express");11const router = express.Router();12const buildDataAttributes = require("./builders/buildDataAttributes");13const auditing = require("./general/platform/auditing");14const fs = require("fs");15const dataOutputting = require("./general/platform/dataOutput")16const { data } = require('./general/functions/general/randomFunctions');17//Outputs18const topicOutput = require("./connectivity/general/connectors/kafka-producer");19// Global Variable for usage in platform20global.__basedir = __dirname;21let outputType = config.outputAdapter;22let componentName;23let methodName;24var dataattributeName;25var runCount;26let systemOutputName;27const args = process.argv.slice(2);28const appName="DataSynthesis";29const appGUID=uuid.v4();30dataattributeName = args[0];31runCount = args[1];32// Set Start Value for timing33let auditEventMessage ="";34let startTime = new Date();35const runQuantity = 5000;36componentName = "buildDataAttriubutes";37methodName ="buildDataAttributes_"+dataattributeName.replace(/\s/g, "");38/*39 *40 * Code Methods to Return Data41 *42 * Mixed Regex: ^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$43 * Number Regex: ^[0-9]{9}$44 *45 */46/*47 * This works on command line options to run:48 * This example invokes the node base data generator for data attributes49 * Below this example will create accountnumbers with one of two random regular expressions50 * if no second argument is specified then the const runQuantity value is used51 * (currently set by default is 5000)52 * Example: node generatedata-dataattributes.js accountnumber53 * This example will create 525 accountnumbers with one of two random regular expressions54 * Example: node generatedata-dataattributes.js accountnumber 52555 */56if(dataattributeName=='accountnumbers')57{58 if(runCount==null)59 {60 runCount = runQuantity;61 }62 var randomValues = ["^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$","^[0-9]{9}$"];63 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];64 auditEventMessage ="Invoking Data Generator for "+ runCount+" Account Numbers"65 auditEventMessage = auditEventMessage +" with Random Value Used for Generation: "+randomValueSelection;66 console.log(auditEventMessage);67 accountnumbersDtl = buildDataAttributes.generateAccountNumbers(randomValueSelection, runCount)68 dataOutputting.processDataOutput(accountnumbersDtl, methodName);69}70/*71 * row.forEach not a function72 *73 */74if(dataattributeName=='address-us')75{76 if(runCount==null)77 {78 runCount = runQuantity;79 }80 auditEventMessage ="Invoking Data Generator for "+ runCount+" US based addresses"81 console.log(auditEventMessage)82 buildDataAttributes.generateAddress_Record_US(runCount).then(resp=>{83 dataOutputting.processDataOutput(resp, methodName);84 })85}86if(dataattributeName=='bankaccounts')87{88 if(runCount==null)89 {90 runCount = runQuantity;91 }92 auditEventMessage ="Invoking Data Generator for "+ runCount+" Bank Accounts"93 console.log(auditEventMessage)94 bankaccountDtl = buildDataAttributes.generateBankAccounts("^[0-9]{9}$",runCount)95 dataOutputting.processDataOutput(bankaccountDtl, methodName);96}97if(dataattributeName=='creditcards')98{99 if(runCount==null)100 {101 runCount = runQuantity;102 }103 var randomValues = ["Visa","Mastervard","Discover","AMEX"];104 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];105 auditEventMessage ="Invoking Data Generator for "+ runCount+" Credit Cards with random selected Card: "+randomValueSelection;106 console.log(auditEventMessage)107 creditcardDtl = buildDataAttributes.generateCreditCards(runCount,randomValueSelection)108 dataOutputting.processDataOutput(creditcardDtl, methodName);109}110if(dataattributeName=='dobs')111{112 if(runCount==null)113 {114 runCount = runQuantity;115 }116 auditEventMessage = "Invoking Data Generator for "+ runCount+" Date of Births"117 console.log(auditEventMessage)118 dobDtl = buildDataAttributes.generateDateOfBirths(1950,runCount)119 dataOutputting.processDataOutput(dobDtl, methodName);120}121if(dataattributeName=='dlns')122{123 if(runCount==null)124 {125 runCount = runQuantity;126 }127 auditEventMessage ="Invoking Data Generator for "+ runCount+" US Drivers Licenses "128 console.log(auditEventMessage)129 dobDtl = buildDataAttributes.generateDLN(runCount,"")130 dataOutputting.processDataOutput(dobDtl, methodName);131}132if(dataattributeName=='eins')133{134 if(runCount==null)135 {136 runCount = runQuantity;137 }138 auditEventMessage ="Invoking Data Generator for "+ runCount+" EIN - Employer Identification Numbers"139 console.log(auditEventMessage)140 dobDtl = buildDataAttributes.generateEIN(runCount)141 dataOutputting.processDataOutput(dobDtl, methodName);142}143if(dataattributeName=='phonenumber-us')144{145 if(runCount==null)146 {147 runCount = runQuantity;148 }149 auditEventMessage="Invoking Data Generator for "+ runCount+" US Phone Numbers"150 console.log(auditEventMessage)151 phonenumberDtl = buildDataAttributes.generatePhoneNumbersUS("us",runCount)152 dataOutputting.processDataOutput(phonenumberDtl, methodName);153}154if(dataattributeName=='phonenumber-intl')155{156 if(runCount==null)157 {158 runCount = runQuantity;159 }160 auditEventMessage ="Invoking Data Generator for "+ runCount+" Intl Phone Numbers"161 console.log(auditEventMessage)162 phonenumberDtl = buildDataAttributes.generatePhoneNumbersIntl("uk",runCount)163 dataOutputting.processDataOutput(phonenumberDtl, methodName);164}165if(dataattributeName=='serialnumbers')166{167 if(runCount==null)168 {169 runCount = runQuantity;170 }171 var randomValues = ["^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$","^[0-9]{9}$"];172 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];173 auditEventMessage="Invoking Data Generator for "+ runCount+" Serial Numbers with random value:"+ randomValueSelection;174 console.log("Invoking Data Generator for "+ runCount+" Social Security Numbers")175 console.log("Random Value Used for Generation: "+randomValueSelection)176 serialNumberDtl = buildDataAttributes.generateSerialNumbers_Basic(randomValueSelection,runCount)177 //serialNumberDtl = buildDataAttributes.generateSerialNumbers_Complex(5000)178 dataOutputting.processDataOutput(serialNumberDtl, methodName);179}180if(dataattributeName=='ssns')181{182 if(runCount==null)183 {184 runCount = runQuantity;185 }186 auditEventMessage="Invoking Data Generator for "+ runCount+" Social Security Numbers";187 console.log(auditEventMessage)188 socialsecurityDtl = buildDataAttributes.generateSSN(runCount)189 dataOutputting.processDataOutput(socialsecurityDtl, methodName);190}191if(dataattributeName=='useridentities')192{193 if(runCount==null)194 {195 runCount = runQuantity;196 }197 var randomValues = ["^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$","^[0-9]{9}$"];198 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];199 auditEventMessage="Invoking Data Generator for "+ runCount+" User Identities with random value:"+ randomValueSelection;200 console.log(auditEventMessage)201 useridentityDtl = buildDataAttributes.generateUserIdentities(randomValueSelection,runCount)202 dataOutputting.processDataOutput(useridentityDtl, methodName);203}204// console.log(generateSerialNumbers_Basic('^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$',10));205// console.log(generateSerialNumbers_Complex(10));206// console.log(module.exports.generateSSN(10))207// console.log(module.exports.generateEIN(10))208// console.log(module.exports.generateDateOfBirths(1960, 10))209// console.log(module.exports.generateCreditCards(12,'Discover'))210// console.log(module.exports.generateDLN('blah','blah'))211// console.log(module.exports.generateAccountNumbers('^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$',25))212// console.log(module.exports.generateUserIdentities('^[%#@&]{1}[A-Z]{3}[%#@&]{1}[0-9]{1}[A-Z]{2}$',25))...

Full Screen

Full Screen

generatedata_dataattributes.js

Source:generatedata_dataattributes.js Github

copy

Full Screen

1// Include all APIs and components to pull data2const dotenv = require('dotenv');3const path = require("path");4const uuid = require('uuid');5const crypto = require('crypto');6const config = process.env7dotenv.config({ path: path.resolve(__dirname, './.env') })8const db = require("./connectivity/general/connectors/dbConnections/postgresqlConnect")9const queryBuilder = require('./general/datatier/reusableQueries');10const express = require("express");11const router = express.Router();12const buildDataAttributes = require("./builders/buildDataAttributes");13const auditing = require("./general/platform/auditing");14const fs = require("fs");15const dataOutputting = require("./general/platform/dataOutput")16const { data } = require('./general/functions/general/randomFunctions');17//Outputs18const topicOutput = require("./connectivity/general/connectors/kafka-producer");19// Global Variable for usage in platform20global.__basedir = __dirname;21let outputType = config.outputAdapter;22let componentName;23let methodName;24var dataattributeName;25var runCount;26let systemOutputName;27const args = process.argv.slice(2);28const appName="DataSynthesis";29const appGUID=uuid.v4();30dataattributeName = args[0];31runCount = args[1];32// Set Start Value for timing33let auditEventMessage ="";34let startTime = new Date();35const runQuantity = 5000;36componentName = "buildDataAttriubutes";37methodName ="buildDataAttributes_"+dataattributeName.replace(/\s/g, "");38/*39 *40 * Code Methods to Return Data41 *42 * Mixed Regex: ^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$43 * Number Regex: ^[0-9]{9}$44 *45 */46/*47 * This works on command line options to run:48 * This example invokes the node base data generator for data attributes49 * Below this example will create accountnumbers with one of two random regular expressions50 * if no second argument is specified then the const runQuantity value is used51 * (currently set by default is 5000)52 * Example: node generatedata_dataattributes.js accountnumber53 * This example will create 525 accountnumbers with one of two random regular expressions54 * Example: node generatedata_dataattributes.js accountnumber 52555 */56if(dataattributeName=='accountnumbers')57{58 if(runCount==null)59 {60 runCount = runQuantity;61 }62 var randomValues = ["^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$","^[0-9]{9}$"];63 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];64 auditEventMessage ="Invoking Data Generator for "+ runCount+" Account Numbers"65 auditEventMessage = auditEventMessage +" with Random Value Used for Generation: "+randomValueSelection;66 console.log(auditEventMessage);67 accountnumbersDtl = buildDataAttributes.generateAccountNumbers(randomValueSelection, runCount)68 dataOutputting.processDataOutput(accountnumbersDtl, methodName);69}70/*71 * row.forEach not a function72 *73 */74if(dataattributeName=='address-us')75{76 if(runCount==null)77 {78 runCount = runQuantity;79 }80 auditEventMessage ="Invoking Data Generator for "+ runCount+" US based addresses"81 console.log(auditEventMessage)82 buildDataAttributes.generateAddress_Record_US(runCount).then(resp=>{83 dataOutputting.processDataOutput(resp, methodName);84 })85}86if(dataattributeName=='bankaccounts')87{88 if(runCount==null)89 {90 runCount = runQuantity;91 }92 auditEventMessage ="Invoking Data Generator for "+ runCount+" Bank Accounts"93 console.log(auditEventMessage)94 bankaccountDtl = buildDataAttributes.generateBankAccounts("^[0-9]{9}$",runCount)95 dataOutputting.processDataOutput(bankaccountDtl, methodName);96}97if(dataattributeName=='creditcards')98{99 if(runCount==null)100 {101 runCount = runQuantity;102 }103 var randomValues = ["Visa","Mastervard","Discover","AMEX"];104 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];105 auditEventMessage ="Invoking Data Generator for "+ runCount+" Credit Cards with random selected Card: "+randomValueSelection;106 console.log(auditEventMessage)107 creditcardDtl = buildDataAttributes.generateCreditCards(runCount,randomValueSelection)108 dataOutputting.processDataOutput(creditcardDtl, methodName);109}110if(dataattributeName=='dobs')111{112 if(runCount==null)113 {114 runCount = runQuantity;115 }116 auditEventMessage = "Invoking Data Generator for "+ runCount+" Date of Births"117 console.log(auditEventMessage)118 dobDtl = buildDataAttributes.generateDateOfBirths(1950,runCount)119 dataOutputting.processDataOutput(dobDtl, methodName);120}121if(dataattributeName=='dlns')122{123 if(runCount==null)124 {125 runCount = runQuantity;126 }127 auditEventMessage ="Invoking Data Generator for "+ runCount+" US Drivers Licenses "128 console.log(auditEventMessage)129 dobDtl = buildDataAttributes.generateDLN(runCount,"")130 dataOutputting.processDataOutput(dobDtl, methodName);131}132if(dataattributeName=='eins')133{134 if(runCount==null)135 {136 runCount = runQuantity;137 }138 auditEventMessage ="Invoking Data Generator for "+ runCount+" EIN - Employer Identification Numbers"139 console.log(auditEventMessage)140 dobDtl = buildDataAttributes.generateEIN(runCount)141 dataOutputting.processDataOutput(dobDtl, methodName);142}143if(dataattributeName=='phonenumber-us')144{145 if(runCount==null)146 {147 runCount = runQuantity;148 }149 auditEventMessage="Invoking Data Generator for "+ runCount+" US Phone Numbers"150 console.log(auditEventMessage)151 phonenumberDtl = buildDataAttributes.generatePhoneNumbersUS("us",runCount)152 dataOutputting.processDataOutput(phonenumberDtl, methodName);153}154if(dataattributeName=='phonenumber-intl')155{156 if(runCount==null)157 {158 runCount = runQuantity;159 }160 auditEventMessage ="Invoking Data Generator for "+ runCount+" Intl Phone Numbers"161 console.log(auditEventMessage)162 phonenumberDtl = buildDataAttributes.generatePhoneNumbersIntl("uk",runCount)163 dataOutputting.processDataOutput(phonenumberDtl, methodName);164}165if(dataattributeName=='serialnumbers')166{167 if(runCount==null)168 {169 runCount = runQuantity;170 }171 var randomValues = ["^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$","^[0-9]{9}$"];172 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];173 auditEventMessage="Invoking Data Generator for "+ runCount+" Serial Numbers with random value:"+ randomValueSelection;174 console.log("Invoking Data Generator for "+ runCount+" Social Security Numbers")175 console.log("Random Value Used for Generation: "+randomValueSelection)176 serialNumberDtl = buildDataAttributes.generateSerialNumbers_Basic(randomValueSelection,runCount)177 //serialNumberDtl = buildDataAttributes.generateSerialNumbers_Complex(5000)178 dataOutputting.processDataOutput(serialNumberDtl, methodName);179}180if(dataattributeName=='ssns')181{182 if(runCount==null)183 {184 runCount = runQuantity;185 }186 auditEventMessage="Invoking Data Generator for "+ runCount+" Social Security Numbers";187 console.log(auditEventMessage)188 socialsecurityDtl = buildDataAttributes.generateSSN(runCount)189 dataOutputting.processDataOutput(socialsecurityDtl, methodName);190}191if(dataattributeName=='useridentities')192{193 if(runCount==null)194 {195 runCount = runQuantity;196 }197 var randomValues = ["^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$","^[0-9]{9}$"];198 var randomValueSelection = randomValues[Math.floor(Math.random()*randomValues.length)];199 auditEventMessage="Invoking Data Generator for "+ runCount+" User Identities with random value:"+ randomValueSelection;200 console.log(auditEventMessage)201 useridentityDtl = buildDataAttributes.generateUserIdentities(randomValueSelection,runCount)202 dataOutputting.processDataOutput(useridentityDtl, methodName);203}204// console.log(generateSerialNumbers_Basic('^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$',10));205// console.log(generateSerialNumbers_Complex(10));206// console.log(module.exports.generateSSN(10))207// console.log(module.exports.generateEIN(10))208// console.log(module.exports.generateDateOfBirths(1960, 10))209// console.log(module.exports.generateCreditCards(12,'Discover'))210// console.log(module.exports.generateDLN('blah','blah'))211// console.log(module.exports.generateAccountNumbers('^[A-Z]{2}[%#@&]{1}[0-9]{5}[A-Z]{1}$',25))212// console.log(module.exports.generateUserIdentities('^[%#@&]{1}[A-Z]{3}[%#@&]{1}[0-9]{1}[A-Z]{2}$',25))...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1var test = require("tape");2var Trackr = require("../");3test("executes computation with context", function(t) {4 var ctx = {};5 var runCount = 0;6 var run = Trackr.autorun(function() {7 t.equal(this, ctx);8 runCount++;9 }, null, ctx);10 t.equal(runCount, 1);11 run.invalidate();12 Trackr.flush();13 t.equal(runCount, 2);14 t.end();15});16test("executes onInvalidate with computation context", function(t) {17 var ctx = {};18 var runCount = 0;19 var run = Trackr.autorun(function(c) {20 c.onInvalidate(function() {21 t.equal(this, ctx);22 runCount++;23 });24 }, null, ctx);25 t.equal(runCount, 0);26 run.invalidate();27 Trackr.flush();28 t.equal(runCount, 1);29 t.end();30});31test("executes onInvalidate with passed context", function(t) {32 var ctx = {};33 var runCount = 0;34 var run = Trackr.autorun(function(c) {35 c.onInvalidate(function() {36 t.equal(this, ctx);37 runCount++;38 }, ctx);39 });40 t.equal(runCount, 0);41 run.invalidate();42 Trackr.flush();43 t.equal(runCount, 1);44 t.end();45});46test("executes afterFlush with context", function(t) {47 var ctx = {};48 var runCount = 0;49 Trackr.afterFlush(function() {50 t.equal(this, ctx);51 runCount++;52 }, ctx);53 t.equal(runCount, 0);54 Trackr.flush();55 t.equal(runCount, 1);56 t.end();57});58test("executes nonreactive with context", function(t) {59 var ctx = {};60 var ret = 12345;61 var runCount = 0;62 var val = Trackr.nonreactive(function() {63 t.equal(this, ctx);64 runCount++;65 return ret;66 }, ctx);67 t.equal(val, ret);68 t.equal(runCount, 1);69 t.end();70});71test("executes nonreactable with bound context", function(t) {72 var ctx = {};73 var arg = "hello";74 var ret = 12345;75 var runCount = 0;76 var fn = Trackr.nonreactable(function(a) {77 t.equal(this, ctx);78 t.equal(a, arg);79 runCount++;80 return ret;81 }, ctx);82 t.equal(runCount, 0);83 var val = fn(arg);84 t.equal(val, ret);85 t.equal(runCount, 1);86 t.end();87});88test("executes nonreactable with unbound context", function(t) {89 var ctx = {};90 var ret = 12345;91 var runCount = 0;92 var fn = Trackr.nonreactable(function() {93 t.equal(this, ctx);94 runCount++;95 return ret;96 });97 t.equal(runCount, 0);98 var val = fn.call(ctx);99 t.equal(val, ret);100 t.equal(runCount, 1);101 t.end();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const runCount = require('qawolf').runCount;2const run = require('qawolf').run;3const create = require('qawolf').create;4const launch = require('qawolf').launch;5const stop = require('qawolf').stop;6const browser = require('qawolf').browser;7const create = require('qawolf').create;8const stop = require('qawolf').stop;9const launch = require('qawolf').launch;10const browser = require('qawolf').browser;11const create = require('qawolf').create;12const stop = require('qawolf').stop;13const launch = require('qawolf').launch;14const browser = require('qawolf').browser;15const create = require('qawolf').create;16const stop = require('qawolf').stop;17const launch = require('qawolf').launch;18const browser = require('qawolf').browser;19const create = require('qawolf').create;20const stop = require('qawolf').stop;21const launch = require('qawolf').launch;22const browser = require('qawolf').browser;23const create = require('qawolf').create;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { runCount } = require("qawolf");2(async () => {3 const count = await runCount("test");4 console.log("test was run " + count + " times");5})();6{7 "scripts": {8 }9}10{11 "scripts": {12 },13 "qawolf": {14 }15}

Full Screen

Using AI Code Generation

copy

Full Screen

1await runCount({2 { click: 'input[name="q"]'},3 { type: 'input[name="q"]', text: 'hello world' },4 { press: 'input[name="q"]', key: 'Enter' }5});6await runCount({7 { click: 'input[name="q"]'},8 { type: 'input[name="q"]', text: 'hello world' },9 { press: 'input[name="q"]', key: 'Enter' }10});11await runCount({12 { click: 'input[name="q"]'},13 { type: 'input[name="q"]', text: 'hello world' },14 { press: 'input[name="q"]', key: 'Enter' }15});16await runCount({17 { click: 'input[name="q"]'},18 { type: 'input[name="q"]', text: 'hello world' },19 { press: 'input[name="q"]', key: 'Enter' }20});21await runCount({22 { click: 'input[name="q"]'},23 { type: 'input[name="q"]', text: 'hello world' },24 { press: 'input[name="q"]', key: 'Enter' }25});26await runCount({27 {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { runCount } = require("qawolf");2runCount("test", 10);3"scripts": {4 }5const { runCount } = require("qawolf");6runCount("test", 10);7"scripts": {8 }9const { runCount } = require("qawolf");10runCount("test", 10);11"scripts": {12 }13const { runCount } = require("qawolf");14runCount("test", 10);15"scripts": {16 }17const { runCount } = require("qawolf");18runCount("test", 10);19"scripts": {20 }21const { runCount } = require("qawolf");22runCount("test", 10);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { runCount } = require("qawolf");2const assert = require("assert");3(async () => {4 const count = await runCount("my-test-id");5 assert(count > 0);6})();7const { runCount } = require("qawolf");8const assert = require("assert");9(async () => {10 const count = await runCount("my-test-id");11 assert(count > 0);12})();13const { runCount } = require("qawolf");14const assert = require("assert");15(async () => {16 const count = await runCount("my-test-id");17 assert(count > 0);18})();19const { runCount } = require("qawolf");20const assert = require("assert");21(async () => {22 const count = await runCount("my-test-id");23 assert(count > 0);24})();25const { runCount } = require("qawolf");26const assert = require("assert");27(async () => {28 const count = await runCount("my-test-id");29 assert(count > 0);30})();31const { runCount } = require("qawolf");32const assert = require("assert");33(async () => {34 const count = await runCount("my-test-id");35 assert(count > 0);36})();37const { runCount } = require("qawolf");38const assert = require("assert");39(async () => {40 const count = await runCount("my-test-id");41 assert(count > 0);42})();43const { runCount } = require("qawolf");44const assert = require("assert");45(async () => {46 const count = await runCount("my-test-id");47 assert(count > 0);48})();49const { runCount } = require("qawolf");50const assert = require("assert");51(async () => {52 const count = await runCount("my-test-id");53 assert(count > 0);54})();55const { runCount

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful