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.  * @emails react-core
    
  8.  */
    
  9. 
    
  10. 'use strict';
    
  11. 
    
  12. const rule = require('../prod-error-codes');
    
  13. const {RuleTester} = require('eslint');
    
  14. const ruleTester = new RuleTester({
    
  15.   parserOptions: {
    
  16.     ecmaVersion: 2017,
    
  17.   },
    
  18. });
    
  19. 
    
  20. ruleTester.run('eslint-rules/prod-error-codes', rule, {
    
  21.   valid: [
    
  22.     'arbitraryFunction(a, b)',
    
  23.     'Error(`Expected ${foo} target to be an array; got ${bar}`)',
    
  24.     "Error('Expected ' + foo + ' target to be an array; got ' + bar)",
    
  25.     'Error(`Expected ${foo} target to ` + `be an array; got ${bar}`)',
    
  26.   ],
    
  27.   invalid: [
    
  28.     {
    
  29.       code: "Error('Not in error map')",
    
  30.       errors: [
    
  31.         {
    
  32.           message:
    
  33.             'Error message does not have a corresponding production error ' +
    
  34.             'code. Add the following message to codes.json so it can be stripped from ' +
    
  35.             'the production builds:\n\n' +
    
  36.             'Not in error map',
    
  37.         },
    
  38.       ],
    
  39.     },
    
  40.     {
    
  41.       code: "Error('Not in ' + 'error map')",
    
  42.       errors: [
    
  43.         {
    
  44.           message:
    
  45.             'Error message does not have a corresponding production error ' +
    
  46.             'code. Add the following message to codes.json so it can be stripped from ' +
    
  47.             'the production builds:\n\n' +
    
  48.             'Not in error map',
    
  49.         },
    
  50.       ],
    
  51.     },
    
  52.     {
    
  53.       code: 'Error(`Not in ` + `error map`)',
    
  54.       errors: [
    
  55.         {
    
  56.           message:
    
  57.             'Error message does not have a corresponding production error ' +
    
  58.             'code. Add the following message to codes.json so it can be stripped from ' +
    
  59.             'the production builds:\n\n' +
    
  60.             'Not in error map',
    
  61.         },
    
  62.       ],
    
  63.     },
    
  64.     {
    
  65.       code: "Error(`Not in ${'error'} map`)",
    
  66.       errors: [
    
  67.         {
    
  68.           message:
    
  69.             'Error message does not have a corresponding production error ' +
    
  70.             'code. Add the following message to codes.json so it can be stripped from ' +
    
  71.             'the production builds:\n\n' +
    
  72.             'Not in %s map',
    
  73.         },
    
  74.       ],
    
  75.     },
    
  76.   ],
    
  77. });