repeaterjs / repeater

The missing constructor for creating safe async iterators
https://repeater.js.org
MIT License
459 stars 12 forks source link

Some of the more fragile tests are failing in newer versions of node #60

Closed brainkim closed 4 years ago

brainkim commented 4 years ago
yarn run v1.22.4
$ jest --config ./jest.config.js --rootDir ./ --color --no-colors
PASS src/__tests__/buffers.ts
FAIL src/__tests__/repeater.ts
  ● Repeater › throw method caught in async function

    expect(received).resolves.toEqual()

    Received promise rejected instead of resolved
    Rejected to value: [Error: throw method caught in async function]

      1207 |     });
      1208 |     await expect(r.next()).resolves.toEqual({ value: 0, done: false });
    > 1209 |     await expect(r.throw(error)).resolves.toEqual({
           |           ^
      1210 |       value: 1,
      1211 |       done: false,
      1212 |     });

      at expect (../../node_modules/expect/build/index.js:134:15)
      at Object.<anonymous> (src/__tests__/repeater.ts:1209:11)

FAIL src/__tests__/combinators.ts (12.27 s)
  ● combinators › Repeater.race › generator vs Promise.resolve

    expect(received).resolves.toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 2

      Object {
    -   "done": false,
    -   "value": 1,
    +   "done": true,
    +   "value": "z",
      }

      40 |         Promise.resolve("z"),
      41 |       ]);
    > 42 |       await expect(iter.next()).resolves.toEqual({ value: 1, done: false });
         |                                          ^
      43 |       await expect(iter.next()).resolves.toEqual({ value: "z", done: true });
      44 |       await expect(iter.next()).resolves.toEqual({ done: true });
      45 |     });

      at Object.toEqual (../../node_modules/expect/build/index.js:198:20)
      at Object.<anonymous> (src/__tests__/combinators.ts:42:42)

  ● combinators › Repeater.merge › Promise.resolve vs generator

    expect(received).toEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 1

      Array [
    -   1,
        -1,
    +   1,
        2,
        3,
        4,
        5,
      ]

      257 |         }
      258 |       } while (!result.done);
    > 259 |       expect(nums).toEqual([1, -1, 2, 3, 4, 5]);
          |                    ^
      260 |       await expect(iter.next()).resolves.toEqual({ done: true });
      261 |     });
      262 | 

      at Object.<anonymous> (src/__tests__/combinators.ts:259:20)

Test Suites: 2 failed, 1 passed, 3 total
Tests:       3 failed, 140 passed, 143 total
Snapshots:   0 total
Time:        15.389 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Seems like some race conditions in tests which rely on async generators running in a specific order compared to async functions, as well as throwing promises not working.

brainkim commented 4 years ago

Fixed in 3.0.3