Middleware for serving es modules. Karma doesn't serve any files not specified
beforehand. This is extremely inconvenient when working with es modules, as many
files are requested on the fly.
function getCode(filePath) {
  // take code from cache if available
  const cachedCode = esm.compiler.getCached(filePath);
  if (cachedCode) {
    return cachedCode;
  }

  if (!fs.existsSync(filePath)) {
    throw new Error(`File does not exist: ${filePath}`);
  }

  // otherwise read code from file and compile it
  const code = fs.readFileSync(filePath, 'utf-8');
  return esm.compiler.compile(filePath, code);
}