Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!