Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

288
Visualizações
Javascript: How do I fetch all of the resources from an endpoint?

I am using Karma and Mocha for running integration tests on my codebase. For validating the codebase in Node.js, I have a folder of test cases.

repository/
├── test/
│   ├── cases/
│   │   ├── case1.json
│   │   ├── case2.json
│   │   ├── case3.json
│   │   └── case4.json
│   ├── browser/
│   │   └── testFactory.spec.ts
│   └── node/
        └── testFactory.spec.ts

For my Node.js tests, I just use fs.readdirSync(testCaseFolder, "utf-8") to get the filenames of all the test cases, and then loop through them.

for (const filename of filenames) {
  const data = fs.readFileSync(testCaseFolder + filename, "utf-8");
  const testCase: ModelTestCase = JSON.parse(data.toString());
  const testName = getTestName(filename);
  describe(testName, function() {
    it(getTestDescription(filename), async function() {
      /* do some testing here */
    });
  });
}

Now I need to rewrite this testing design to work in the browser for testing via Karma. Karma has a way to specify a path to static files that can be served up during testing in the configuration: Karma - Files. So in this case I added to my Karma Configuration:

files: [
  {pattern: 'test/cases/*.json', watched: false, included: false, served: true, nocache: false}
],

and set up a proxy to serve the test cases endpoint at a convenient URL:

proxies: {
  "/cases/": "http://localhost:8080/base/test/cases/"
},

Now I could theoretically access test case 1 with the following code:

fetch("/cases/case1.json");

How can I write a loop to fetch every test case located in the /cases/ endpoint that is browser compatible JavaScript?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda