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.  * @flow
    
  8.  */
    
  9. 
    
  10. import {exec} from 'child-process-promise';
    
  11. import {readFileSync} from 'fs';
    
  12. import path from 'path';
    
  13. import {rimrafSync} from 'rimraf';
    
  14. 
    
  15. describe('x_google_ignoreList source map extension', () => {
    
  16.   jest.setTimeout(60 * 1000);
    
  17. 
    
  18.   const pathToExtensionsPackage = path.resolve(__dirname, '..', '..');
    
  19.   const pathToChromeExtensionBuild = path.join(
    
  20.     pathToExtensionsPackage,
    
  21.     'chrome/build',
    
  22.   );
    
  23.   const pathToSourceMap = path.resolve(
    
  24.     pathToChromeExtensionBuild,
    
  25.     'unpacked/build/react_devtools_backend_compact.js.map',
    
  26.   );
    
  27. 
    
  28.   afterAll(() => {
    
  29.     rimrafSync(pathToChromeExtensionBuild);
    
  30.   });
    
  31. 
    
  32.   describe('for dev builds', () => {
    
  33.     it('should include only sources with /node_modules/ and /webpack/ in path', async () => {
    
  34.       await exec('yarn build:chrome:local', {
    
  35.         cwd: pathToExtensionsPackage,
    
  36.       });
    
  37. 
    
  38.       const sourceMapJSON = readFileSync(pathToSourceMap);
    
  39.       const sourceMap = JSON.parse(sourceMapJSON);
    
  40. 
    
  41.       const {sources, x_google_ignoreList} = sourceMap;
    
  42. 
    
  43.       const expectedIgnoreList = [];
    
  44.       for (let sourceIndex = 0; sourceIndex < sources.length; ++sourceIndex) {
    
  45.         const source = sources[sourceIndex];
    
  46. 
    
  47.         if (source.includes('/node_modules/') || source.includes('/webpack/')) {
    
  48.           expectedIgnoreList.push(sourceIndex);
    
  49.         }
    
  50.       }
    
  51. 
    
  52.       expect(x_google_ignoreList).toEqual(expectedIgnoreList);
    
  53.     });
    
  54.   });
    
  55. 
    
  56.   describe('for production builds', function () {
    
  57.     it('should include every source', async () => {
    
  58.       await exec('yarn build:chrome', {cwd: pathToExtensionsPackage});
    
  59. 
    
  60.       const sourceMapJSON = readFileSync(pathToSourceMap);
    
  61.       const sourceMap = JSON.parse(sourceMapJSON);
    
  62. 
    
  63.       const {sources, x_google_ignoreList} = sourceMap;
    
  64. 
    
  65.       expect(sources.length).toBe(x_google_ignoreList.length);
    
  66.     });
    
  67.   });
    
  68. });