Setting up Intern to configure my server mock before and after testing

Currently, I am in the process of creating a test suite for a JavaScript widget with Intern.

While I have successfully crafted some pure-JavaScript tests as well as some DOM tests within the page, I've hit a roadblock when it comes to writing functional tests for the Ajax functionality. This part of testing involves communicating with my simple Node.js mock server which has been effective for manual testing purposes.

My specific goals include:

  1. Launching the Node.js mock server during the setup phase of the test suite
  2. Shutting down the mock server upon completion of the test
  3. (Extra credit) Having the capability to analyze the mock server from within my Intern tests, such as verifying the contents of a POST request made to the mock

I'm facing challenges on all three fronts - there is a lack of documentation or example code from Intern on handling the setup and teardown of an external process like a Node.js mock server in the test suite.

My current setup involves using Intern alongside Sauce Labs (which utilizes hosted Selenium). I'm unsure if this issue needs to be resolved solely within Intern or also requires intervention from Sauce Labs. Hopefully, someone who has experience with this can provide guidance.

Answer №1

In order to have a server start and stop for each suite, you can utilize the setup and teardown methods as shown below:

let server;

registerSuite({
    name: 'testingSuite',

    setup: function () {
        server = initiateServer();
    },

    teardown: function () {
        server.shutdown();
    },

    ...
});

The initiateServer function should be used to kickstart your test server. This function will likely return an object that allows interaction with the server. By implementing this approach, all tests within the suite will have access to the server object.

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

Utilize range slider to refine dataset

I have implemented a jquery datatable along with the range.slider plugin. My goal is to apply the range slider to filter out data in the last column. In my attempt, I am using search.push to accomplish this filtering process. Below is an example of my i ...

One effective method for updating the parent state via buttons located in child components

I've been attempting to update the parent state using a handler function passed down to the child, but I keep encountering an error: class Parent(){ constructor(props){ super(props); this.state = { answer: "" } }; handleAnswe ...

How can I access specific values from a table generated with a PHP array using jQuery?

Currently, I am working on a page where users can upload documents. Once uploaded, these docs are stored in a folder and their location is updated in a table for reference. Now, when I navigate to an edit page, I use PHP to query the database and display t ...

A step-by-step guide on transforming an array of objects into an array of arrays with the help of Ramda

I want to convert the following data: [ { a: 2000, b: 4000 }, { a: 8000, b: 5000 }, { a: 6000, b: 1000 } ]; Into this format: [ [ 2000, 8000, 6000 ], [ 4000, 5000, 1000 ] ]; Using Ramda library. I am able to achieve this using R.reduce functio ...

Prevent users from viewing or editing profiles of other users

I need to enhance the security of my application by restricting users from accessing profiles of other users. route.js router.get('/currentUser/:username', userAuth, (req, res) => { User.findOne({ username: req.params.username }).the ...

When integrating AngularJS $http with WordPress, the desired response may not always be achieved

I recently implemented a wp_localize_script for ajax in my WordPress project: wp_localize_script('cb_admin_js', 'cbAjax', array('ajax_url' => admin_url( 'admin-ajax.php' ))); As part of testing, I used an $http. ...

The PUT request is experiencing a timeout issue

After struggling with updating a file in my Mongo DB through a form using a PUT request and Mongoose findByIdAndUpdate, I managed to make it work. The only issue now is that the PUT request seems to be stuck in an infinite loop, leading to a timeout error. ...

Unable to access the 'localStorage' property from 'Window': Permission denied

Check out my website www.abc.com Incorporating an iframe in www.abc.com using <iframe src="www.xyz.com"></iframe> An issue has arisen: Error message: "Failed to read the 'localStorage' property from 'Window': A ...

Is there a way to turn off step navigation in bootstrap?

Displayed below is a visual representation of the bootstrap step navigation component. Presently, there is an unseen 'next' button located at the bottom of the page. When this 'next' button is pressed, it transitions from 'step-1 ...

Solving UI routing with AngularFire 0.9

I recently followed a tutorial here and encountered this error: Unknown provider: currentAuthProvider <- currentAuth I made sure to add currentAuth to all my controllers, but I'm still getting the error. Any idea what could be causing it? Fi ...

What could possibly be the reason for this not returning null?

Consider this JavaScript snippet: var value = parseInt(""); console.log(value != Number.NaN ? value : null); Why does the console output Nan instead of null? Is there a way to modify the code so that it actually returns a null value? I attempted to wra ...

HTML not rendering Angular object as expected

Having trouble with my Angular project on LinkedInLearning. Can't seem to display object properties in my component, even though I can see them when logging the object. The boolean value renders fine, but not the object properties. Here is the snippe ...

Why do flex justifyContent and alignItems not have an effect on child <View/> components in React Native?

I am encountering an issue in React Native where a child view inside another view is not centering in the middle of the page. However, if the child view is not nested inside the parent view and stands alone, it does center properly in the middle of the pag ...

The type does not have a property named 'defaultProps'

I have a Typescript React class component structured like this: import React, { Component } from 'react'; interface Props { bar?: boolean; } const defaultProps: Partial<Props> = { bar: false, }; class Foo extends Component<Props& ...

The event "subscriptionRemoved" is not being triggered when a password change is made on the Microsoft Graph API

Utilizing the Microsoft Graph API, I have set up subscriptions to receive notifications for calendar events through Node.js. As per the guidelines outlined in the documentation on Enhancing notification reliability for Outlook resources (preview), it speci ...

JS: Issue with iterating over objects

Within my JavaScript code, there exists an object named box_object with the following structure: ({ id:"3", text:"this is a box object", connection_parent:["1", "2"], connection_child:["5", "6"], connectiondata_child:{ 0:{id:"5", ...

Attempting to streamline the process of verifying the truthfulness of an object key and subsequently adding it to a different

In the process of creating a form to interact with a remote API, I aim to construct a GET request query string depending on which checkboxes the user chooses. Initially, I considered using a series of if/else statements to check whether the model object k ...

Optimal Strategies for managing callbacks in node.js

As I work on developing a JavaScript class, I come across a function that utilizes the crypto module in Node.js. However, I am uncertain about the best approach to handling callbacks. Let's examine an example: Users.prototype.makeSalt = function(call ...

Button to close CSS overlay scrolls to the top of the page

I have managed to create a CSS-only solution where clicking on an anchor displays an overlay image on top of a div. Everything works smoothly except for one issue: when the close button is clicked, it scrolls to the top of the page instead of closing and s ...

The functionality of the Angular directive ngIf is not meeting the desired outcome

We are currently working on transferring data from one component to another using the approach outlined below. We want to display an error message when there is no data available. <div *ngIf="showGlobalError"> <h6>The reporting project d ...