hunk.code_window:  * found in the LICENSE file at https://angular.io/license
    */
   /**
    * This uses a dynamic import to load a module which may be ESM.
    * CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
    * will currently, unconditionally downlevel dynamic import into a require call.
  
hunk.labels: keep keep add keep keep keep keep
hunk.after_edit: /**
    * Lazily compiled dynamic import loader function.
    */
   let load: (<T>(modulePath: string | URL) => Promise<T>) | undefined;
  
hunk.file_path: packages/angular_devkit/build_angular/src/utils/load-esm.ts
hunk.type: add
file: import express from 'express';
  import * as http from 'http';
  
  import { writeFile } from '../../utils/fs';
  import { killAllProcesses } from '../../utils/process';
  import { ngServe } from '../../utils/project';
  import { AddressInfo } from 'net';
  import * as assert from 'assert';
  
  export default function () {
    // TODO(architect): Delete this test. It is now in devkit/build-angular.
  
    // Create an express app that serves as a proxy.
    const app = express();
    const server = http.createServer(app);
    server.listen(0);
  
    app.set('port', (server.address() as AddressInfo).port);
    app.get('/api/test', function (req, res) {
      res.send('TEST_API_RETURN');
    });
  
    const backendHost = 'localhost';
    const backendPort = (server.address() as AddressInfo).port;
    const proxyServerUrl = `http://${backendHost}:${backendPort}`;
    const proxyConfigFile = 'proxy.config.json';
    const proxyConfig = {
      '/api/*': {
        target: proxyServerUrl,
      },
    };
  
    return Promise.resolve()
      .then(() => writeFile(proxyConfigFile, JSON.stringify(proxyConfig, null, 2)))
      .then(() => ngServe('--proxy-config', proxyConfigFile))
      .then((port) => fetch(`http://localhost:${port}/api/test`))
      .then(async (response) => {
        assert.strictEqual(response.status, 200);
        assert.match(await response.text(), /TEST_API_RETURN/);
      })
      .finally(async () => {
        await killAllProcesses();
        server.close();
      });
  }
  