Exploring ways to run tests on a server REST API using testem

When using Testem, I have a config option called serve_files that handles serving the client-side code for me. However, I also need to run my server because it includes a REST API that the client side relies on.

Is there a way to configure Testem to launch my server before running the tests? Or is this not allowed by Testem's guidelines?

The issue arises because Testem runs on a different port than my REST API, which causes problems with API references in the client side. Therefore, I'm looking to instruct Testem to ignore serve_files and instead start my actual server to test the files from there.

PS: Another possibility could be to stub the API using sinonjs or similar tools. However, doing so would mean I'm not truly testing my API with the Ember generated templates that interact with it.

Answer №1

If you need to forward http requests to an external endpoint, consider utilizing the API Proxy setting:

To achieve this, simply include a proxies section in the testem.json configuration file.


{
  "proxies": {
    "/api": {
      "port": 4200,
      "host": "localhost"
    },
    "/xmlapi": {
      "port": 8000,
      "host": "localhost"
    }
  }
}

This feature is set up as a transparent proxy, meaning that a request like

http://localhost:7357/api/posts.json
will be forwarded to
http://localhost:4200/api/posts.json
while retaining the /api prefix.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vue.js and the hidden input value that remains unseen

I am currently developing a shopping list application using Vue.js and I was wondering if there is a conventional method to achieve my requirements. My app consists of a list of items with add and delete buttons: https://i.stack.imgur.com/yQfcz.png const ...

Addressing memory leaks in React server-side rendering and Node.js with setInterval

Currently in my all-encompassing react application, there's a react element that has setInterval within componentWillMount and clearInterval inside componentWillUnmount. Luckily, componentWillUnmount is not invoked on the server. componentWillMount( ...

Guide to deploying a Next JS App with Mongoose for MongoDB connectivity on Vercel

I am experiencing issues when trying to deploy my Next.js app on Vercel with a MongoDB connection. I have added environment variables on the Vercel site where we deploy the Next.js app. Is there anything wrong in the following file? next.config.js module. ...

Avoiding unnecessary re-renders of a parent component caused by a child component

I'm facing rendering problems and would greatly appreciate any assistance. I attempted to use useMemo and useCallback, but it resulted in the checkbox breaking. Within a component, I am displaying information from an object. Let's consider the fo ...

Is it possible to render a web page in C++ that includes JavaScript, dynamic html, and retrieve the generated DOM string?

Is there a way to fetch and extract the rendered DOM of a web page using C++? I'm not just talking about the basic HTTP response, but the actual DOM structure that is generated after JavaScript has executed (possibly after allowing it some time to run ...

Utilizing AngularJS filter in JavaScript without AngularJS Framework

This is a test to experiment and learn. Currently, I have a JSON object called obj. My goal is to utilize the angular Json filter to format this JSON object and display it in the chrome console. This should be achieved without the need for any button click ...

Generating HTML content from XML data with the help of JavaScript

Challenge: Attempting to display one question and its four corresponding answers at a time from an XML file. JavaScript code: var xmlDoc, quest, ans, i, n; xmlDoc = loadXMLDoc("questions.xml"); quest = xmlDoc.getElementsByTagName('main'); do ...

Tips for transferring data to an entry component in Angular 2 using ng-bootstrap modal

I've been grappling with sending data to a custom modal content component in Angular 2. My objective is to have the flexibility of calling this modal from any other component without duplicating code. Despite my efforts, including referencing the "Com ...

My router-outlet is malfunctioning when trying to display my component

I am currently diving into learning Angular 2 in order to revamp my personal website. However, I've encountered an issue where my application fails to load the component when I navigate to the appropriate route by clicking on the navigation bar. Insi ...

Altering the download directory for Chrome/Chromium with the help of Puppeteer

Currently, I am using Ubuntu 16.04 LTS to work on a web scraping project where I am attempting to download a file using Puppeteer. However, I am facing issues with changing the download location in both Chromium and Chrome browsers. Despite trying the foll ...

The "keydown" event in React will not alter the state

I am currently developing an application that requires me to track the keys pressed by the user. I am utilizing keydown and keyup events for this purpose. However, I am facing a challenge where I do not want the same key to be registered multiple times whe ...

What steps should I follow to set JSONP as the dataType for a request in an Angular $http service?

I have a good understanding of how to use jQuery's $.ajax: $.ajax({ url: //twitter endpoint, method:"GET", dataType:"jsonp", success:function() { //stuff } }); Is there a way to set the JSONP datatype for an angular $http service reque ...

Every time I open my browser, my Node.js web app creates a fresh session

Whenever I close all browser windows and reopen the web app, a new session is initiated, forcing me to re-authenticate each time. To give you an idea, my web application framework is <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfema ...

React fails to display image on the server

One issue I'm facing with my React project on the server is that some images are not being displayed. Click here to view image description The console error message reads: ASGimagen.png:1 GET https://[url of my server]/autodiagnostico/cuadroanimado ...

When filtering an array in JavaScript, ensure to display a notification if no items match the criteria

In React/Next, I have an array that is being filtered and sorted before mapping through it. If nothing is found after the filters run, I want to display a simple message in JSX format. The message should be contained within a span element. Here is the str ...

What is the alternative method to adjust the npm prefix without using configuration?

After mistakenly setting the npm prefix to a non-existent location, I'm wondering if there's a configuration file that can be modified to revert this change. Currently, my options seem limited to: Fully uninstalling Node (npm not responding af ...

Can you explain the distinction between querying a database and making a request to an endpoint?

Recently, I've been diving into learning mongoose but came across a code that left me puzzled. I'm curious as to why we include the async keyword at the beginning of the callback function when querying a database. Isn't it already asynchron ...

Combining Arrays in AngularJS with an owl-carousel Setting

My goal is to implement an endless scrolling carousel in AngularJS using owl-carousel. The idea is to load new items every time the carousel is fully scrolled and seamlessly merge queried elements with the existing list. However, I've encountered a pr ...

Activating Unsplash API to initiate download

I am currently following the triggering guidelines found in the Unsplash documentation. The endpoint I am focusing on is: GET /photos/:id/download This is an example response for the photo: { "id": "LBI7cgq3pbM", "width": ...

Issue encountered while logging into mobile application built with Ionic 3, Angular 4, and Firebase: Error message received - Unable to sign in using provided email. Email must be a valid string

I am currently working on developing a chat application using Firebase. The user registration process in Firebase is functioning properly. However, I encounter an error message when attempting to log in with a registered username (email address): Error: R ...