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