Repository: dubzzz/fast-check
Pull request #625 (2020-06-13 17:15:50)

🐛 FIX Scheduler forgets to pass the metadata when calling report
## Why is this PR for?

FIX Scheduler forgets to pass the metadata when calling report.

## In a nutshell

❌ New feature
✔️ Fix an issue
❌ Documentation improvement
❌ Other: *please explain*

(✔️: yes, ❌: no)

## Potential impacts

None.


codesandbox[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/625/builds/32219) or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ba51f922c855516d5268c895527298dfb3d113ea:

|Sandbox| Source |
|--|--|
|[focused-architecture-y8im1](https://codesandbox.io/s/focused-architecture-y8im1)| Configuration |
|[elegant-rubin-4x71v](https://codesandbox.io/s/elegant-rubin-4x71v)| Configuration |

coveralls: 
[![Coverage Status](https://coveralls.io/builds/31434777/badge)](https://coveralls.io/builds/31434777)

Coverage increased (+0.03%) to 95.805% when pulling **ba51f922c855516d5268c895527298dfb3d113ea on fix/report-do-not-export-metadata** into **cb29836a7fa3228a821fe25586df60fda6a5d7ed on master**.


Patch:
diff --git a/src/check/arbitrary/AsyncSchedulerArbitrary.ts b/src/check/arbitrary/AsyncSchedulerArbitrary.ts
index bec07b4f..b5606bf8 100644
--- a/src/check/arbitrary/AsyncSchedulerArbitrary.ts
+++ b/src/check/arbitrary/AsyncSchedulerArbitrary.ts
@@ -156,6 +156,7 @@ class SchedulerImplem<TMetaData> implements Scheduler<TMetaData> {
     schedulingType: 'promise' | 'function' | 'sequence',
     taskId: number,
     label: string,
+    metadata: TMetaData | undefined,
     status: 'resolved' | 'rejected',
     data: unknown
   ) {
@@ -164,6 +165,7 @@ class SchedulerImplem<TMetaData> implements Scheduler<TMetaData> {
       schedulingType,
       taskId,
       label,
+      metadata,
       outputValue: data !== undefined ? stringify(data) : undefined,
     });
   }
@@ -181,11 +183,11 @@ class SchedulerImplem<TMetaData> implements Scheduler<TMetaData> {
       trigger = () => {
         (thenTaskToBeAwaited ? task.then(() => thenTaskToBeAwaited()) : task).then(
           (data) => {
-            this.log(schedulingType, taskId, label, 'resolved', data);
+            this.log(schedulingType, taskId, label, metadata, 'resolved', data);
             return resolve(data);
           },
           (err) => {
-            this.log(schedulingType, taskId, label, 'rejected', err);
+            this.log(schedulingType, taskId, label, metadata, 'rejected', err);
             return reject(err);
           }
         );
@@ -198,6 +200,7 @@ class SchedulerImplem<TMetaData> implements Scheduler<TMetaData> {
       schedulingType,
       taskId,
       label,
+      metadata,
     });
     return scheduledPromise;
   }
@@ -303,6 +306,7 @@ class SchedulerImplem<TMetaData> implements Scheduler<TMetaData> {
           schedulingType: t.schedulingType,
           taskId: t.taskId,
           label: t.label,
+          metadata: t.metadata,
         })
       ),
     ];


Test patch:
diff --git a/test/unit/check/arbitrary/AsyncSchedulerArbitrary.spec.ts b/test/unit/check/arbitrary/AsyncSchedulerArbitrary.spec.ts
index 75093a6b..4b80a1c2 100644
--- a/test/unit/check/arbitrary/AsyncSchedulerArbitrary.spec.ts
+++ b/test/unit/check/arbitrary/AsyncSchedulerArbitrary.spec.ts
@@ -355,6 +355,39 @@ describe('AsyncSchedulerArbitrary', () => {
         // Assert
         expect(then1Function.mock.calls).toEqual(then2Function.mock.calls);
       });
+
+      it('Should attach passed metadata into the report', async () => {
+        // Arrange
+        const expectedMetadata = Symbol('123');
+
+        // Act
+        const mrng = stubRng.mutable.counter(42);
+        const s = scheduler().generate(mrng).value;
+        s.schedule(Promise.resolve(), 'label', expectedMetadata);
+
+        // Assert
+        await s.waitAll();
+        const report = s.report();
+        expect(report).toHaveLength(1);
+        expect(report[0].status).toBe('resolved');
+        expect(report[0].metadata).toBe(expectedMetadata);
+      });
+
+      it('Should attach passed metadata into the report even if not executed', async () => {
+        // Arrange
+        const expectedMetadata = Symbol('123');
+
+        // Act
+        const mrng = stubRng.mutable.counter(42);
+        const s = scheduler().generate(mrng).value;
+        s.schedule(Promise.resolve(), 'label', expectedMetadata);
+
+        // Assert
+        const report = s.report();
+        expect(report).toHaveLength(1);
+        expect(report[0].status).toBe('pending');
+        expect(report[0].metadata).toBe(expectedMetadata);
+      });
     });
 
     describe('scheduleFunction', () => {
@@ -787,6 +820,49 @@ describe('AsyncSchedulerArbitrary', () => {
         expect(taskResolvedValue).toEqual({ done: false, faulty: true });
       });
     });
+
+    it('Should attach passed metadata into the report', async () => {
+      // Arrange
+      const expectedMetadataFirst = Symbol('123');
+      const expectedMetadataSecond = Symbol('1234');
+
+      // Act
+      const mrng = stubRng.mutable.counter(42);
+      const s = scheduler().generate(mrng).value;
+      s.scheduleSequence([
+        { builder: () => Promise.resolve(42), label: 'firstStep', metadata: expectedMetadataFirst },
+        { builder: () => Promise.reject(8), label: 'secondStep', metadata: expectedMetadataSecond },
+      ]);
+
+      // Assert
+      await s.waitAll();
+      const report = s.report();
+      expect(report).toHaveLength(2);
+      expect(report[0].status).toBe('resolved');
+      expect(report[0].metadata).toBe(expectedMetadataFirst);
+      expect(report[1].status).toBe('rejected');
+      expect(report[1].metadata).toBe(expectedMetadataSecond);
+    });
+
+    it('Should attach passed metadata into the report even if not executed', async () => {
+      // Arrange
+      const expectedMetadataFirst = Symbol('123');
+      const expectedMetadataSecond = Symbol('1234');
+
+      // Act
+      const mrng = stubRng.mutable.counter(42);
+      const s = scheduler().generate(mrng).value;
+      s.scheduleSequence([
+        { builder: () => Promise.resolve(42), label: 'firstStep', metadata: expectedMetadataFirst },
+        { builder: () => Promise.reject(8), label: 'secondStep', metadata: expectedMetadataSecond },
+      ]);
+
+      // Assert
+      const report = s.report();
+      expect(report).toHaveLength(1); // second task cannot be scheduled as first one is still pending
+      expect(report[0].status).toBe('pending');
+      expect(report[0].metadata).toBe(expectedMetadataFirst);
+    });
   });
   describe('schedulerFor', () => {
     it('Should execute tasks in the required order when using template string from error logs', async () => {