|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its 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 | +const semver = require('semver'); |
| 10 | + |
| 11 | +let shouldPass; |
| 12 | +let isFocused; |
| 13 | +describe('transform-react-version-pragma', () => { |
| 14 | + // eslint-disable-next-line no-unused-vars |
| 15 | + const _test_react_version = (range, testName, cb) => { |
| 16 | + test(testName, (...args) => { |
| 17 | + shouldPass = semver.satisfies('18.0.0', range); |
| 18 | + return cb(...args); |
| 19 | + }); |
| 20 | + }; |
| 21 | + |
| 22 | + // eslint-disable-next-line no-unused-vars |
| 23 | + const _test_react_version_focus = (range, testName, cb) => { |
| 24 | + test(testName, (...args) => { |
| 25 | + shouldPass = semver.satisfies('18.0.0', range); |
| 26 | + isFocused = true; |
| 27 | + return cb(...args); |
| 28 | + }); |
| 29 | + }; |
| 30 | + |
| 31 | + beforeEach(() => { |
| 32 | + shouldPass = null; |
| 33 | + isFocused = false; |
| 34 | + }); |
| 35 | + |
| 36 | + // @reactVersion >= 17.9 |
| 37 | + test('reactVersion flag is on >=', () => { |
| 38 | + expect(shouldPass).toBe(true); |
| 39 | + }); |
| 40 | + |
| 41 | + // @reactVersion >= 18.1 |
| 42 | + test('reactVersion flag is off >=', () => { |
| 43 | + expect(shouldPass).toBe(false); |
| 44 | + }); |
| 45 | + |
| 46 | + // @reactVersion <= 18.1 |
| 47 | + test('reactVersion flag is on <=', () => { |
| 48 | + expect(shouldPass).toBe(true); |
| 49 | + }); |
| 50 | + |
| 51 | + // @reactVersion <= 17.9 |
| 52 | + test('reactVersion flag is off <=', () => { |
| 53 | + expect(shouldPass).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + // @reactVersion > 17.9 |
| 57 | + test('reactVersion flag is on >', () => { |
| 58 | + expect(shouldPass).toBe(true); |
| 59 | + }); |
| 60 | + |
| 61 | + // @reactVersion > 18.1 |
| 62 | + test('reactVersion flag is off >', () => { |
| 63 | + expect(shouldPass).toBe(false); |
| 64 | + }); |
| 65 | + |
| 66 | + // @reactVersion < 18.1 |
| 67 | + test('reactVersion flag is on <', () => { |
| 68 | + expect(shouldPass).toBe(true); |
| 69 | + }); |
| 70 | + |
| 71 | + // @reactVersion < 17.0.0 |
| 72 | + test('reactVersion flag is off <', () => { |
| 73 | + expect(shouldPass).toBe(false); |
| 74 | + }); |
| 75 | + |
| 76 | + // @reactVersion = 18.0 |
| 77 | + test('reactVersion flag is on =', () => { |
| 78 | + expect(shouldPass).toBe(true); |
| 79 | + }); |
| 80 | + |
| 81 | + // @reactVersion = 18.1 |
| 82 | + test('reactVersion flag is off =', () => { |
| 83 | + expect(shouldPass).toBe(false); |
| 84 | + }); |
| 85 | + |
| 86 | + /* eslint-disable jest/no-focused-tests */ |
| 87 | + |
| 88 | + // @reactVersion >= 18.1 |
| 89 | + fit('reactVersion fit', () => { |
| 90 | + expect(shouldPass).toBe(false); |
| 91 | + expect(isFocused).toBe(true); |
| 92 | + }); |
| 93 | + |
| 94 | + // @reactVersion <= 18.1 |
| 95 | + test.only('reactVersion test.only', () => { |
| 96 | + expect(shouldPass).toBe(true); |
| 97 | + expect(isFocused).toBe(true); |
| 98 | + }); |
| 99 | + |
| 100 | + // @reactVersion <= 18.1 |
| 101 | + // @reactVersion <= 17.1 |
| 102 | + test('reactVersion multiple pragmas fail', () => { |
| 103 | + expect(shouldPass).toBe(false); |
| 104 | + expect(isFocused).toBe(false); |
| 105 | + }); |
| 106 | + |
| 107 | + // @reactVersion <= 18.1 |
| 108 | + // @reactVersion >= 17.1 |
| 109 | + test('reactVersion multiple pragmas pass', () => { |
| 110 | + expect(shouldPass).toBe(true); |
| 111 | + expect(isFocused).toBe(false); |
| 112 | + }); |
| 113 | + |
| 114 | + // @reactVersion <= 18.1 |
| 115 | + // @reactVersion <= 17.1 |
| 116 | + test.only('reactVersion focused multiple pragmas fail', () => { |
| 117 | + expect(shouldPass).toBe(false); |
| 118 | + expect(isFocused).toBe(true); |
| 119 | + }); |
| 120 | + |
| 121 | + // @reactVersion <= 18.1 |
| 122 | + // @reactVersion >= 17.1 |
| 123 | + test.only('reactVersion focused multiple pragmas pass', () => { |
| 124 | + expect(shouldPass).toBe(true); |
| 125 | + expect(isFocused).toBe(true); |
| 126 | + }); |
| 127 | +}); |
0 commit comments