| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | 'use strict'; |
| 8 | |
| 9 | describe('transform-prevent-infinite-loops', () => { |
| 10 | // Note: instead of testing the transform by applying it, |
| 11 | // we assume that it *is* already applied. Since we expect |
| 12 | // it to be applied to all our tests. |
| 13 | |
| 14 | it('fails the test for `while` loops', () => { |
| 15 | expect(global.infiniteLoopError).toBe(null); |
| 16 | expect(() => { |
| 17 | while (true) { |
| 18 | // do nothing |
| 19 | } |
| 20 | }).toThrow(RangeError); |
| 21 | // Make sure this gets set so the test would fail regardless. |
| 22 | expect(global.infiniteLoopError).not.toBe(null); |
| 23 | // Clear the flag since otherwise *this* test would fail. |
| 24 | global.infiniteLoopError = null; |
| 25 | }); |
| 26 | |
| 27 | it('fails the test for `for` loops', () => { |
| 28 | expect(global.infiniteLoopError).toBe(null); |
| 29 | expect(() => { |
| 30 | for (;;) { |
| 31 | // do nothing |
| 32 | } |
| 33 | }).toThrow(RangeError); |
| 34 | // Make sure this gets set so the test would fail regardless. |
| 35 | expect(global.infiniteLoopError).not.toBe(null); |
| 36 | // Clear the flag since otherwise *this* test would fail. |
| 37 | global.infiniteLoopError = null; |
| 38 | }); |
| 39 | }); |