Leveraging the power of the wildcard feature to execute a variety of scripts when running

Inside my package.json file, I currently have the following scripts block:

"scripts": {
    "test": "node tests/*-test.js"
}

In the tests folder, I have files named a-test.js and b-test.js. This can be confirmed by using the command ls tests/*-test.js.

However, when I run npm run test, only a-test.js is being executed. Is there a way for me to run all *-test.js scripts without explicitly listing them? Keep in mind that I may have more than just 2 scripts to run in the future.

Answer №1

If you're looking to streamline your tasks, consider implementing a task manager like grunt or gulp, or a basic script to run your tasks smoothly:

test.js:

require('./test/a-test.js')
require('./test/b-test.js')

package.json

"scripts": {
   "test": "node test.js"
}

Another option is to automate these tasks using the include-all module, which can handle the process for you https://www.npmjs.com/package/include-all

Here's an example using includeAll:

    const path = require('path');
    const includeAll = require('include-all');

    const controller = includeAll({
        dirname: path.join(__dirname, 'test'),
        filter: /(.+test)\.js$/,
    });

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

How to style the first dropdown value in AngularJS to appear bold?

Is there a way to style only the first value in a dropdown list as bold without using jQuery? Here is the code for the dropdown: <div class="col-xs-3"> <select-box id="ad-version-select" options="curItem.stats.version" model="state.version" i ...

Facing an ENOENT error while attempting to upgrade AWS CDK

I previously installed cdk and it was working fine. However, when attempting to update it by using the command: sudo npm install -g aws-cdk@latest I encountered an error stating ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/a ...

THREE.JS ensures that the face normal is perpendicular to the face and facing outward

When using THREE.JS to generate a custom geometry, I define vertices and faces. However, when creating a face without specifying the normal direction like new THREE.Face3(a,b,c), some faces end up pointing inward instead of outward. Is there a way to ens ...

The format for a DateTime field in a JSON string array is as follows: yyyy-MM-dd hh:mm:ss

I am working with a JSON array string pulled from a database and I need to format the DateAndTime field into yyyy-MM-dd hh:mm:ss. This formatting needs to be flexible as the data passed through will vary, except for the DateAndTime. Here is my current att ...

Expanding the functionality of express.Router

Can someone help me with how to extend the functionality of express.Router? I attempted the following: class Test extends express.Router() { }; However, I encountered an error when trying this in Express. Does anyone have a solution for this issue? ...

"UIWebView experiences a crash when a long press gesture is performed on a textarea element

Looking to implement a custom keyboard for UIWebView that is entirely based on HTML/JS/CSS for compatibility across multiple devices. To achieve this, I included a notification as shown below: [[NSNotificationCenter defaultCenter] addObserver:self selecto ...

What are the steps to setting up SystemJS with Auth0?

I am having trouble configuring SystemJS for Auth0 (angular2-jwt) and Angular 2.0.0-beta.6 as I keep encountering the following error message: GET http://localhost:3000/angular2/http 404 (Not Found)fetchTextFromURL @ system.src.js:1068(anonymous function) ...

Ways to align div elements

I am currently in the process of developing my own custom animation player. Utilizing Three.js for object rendering has been successful so far. However, the challenge lies in incorporating control options at the bottom of the player interface (such as play ...

Utilizing visual elements to change the options of a dropdown menu

I am currently working on creating a form for a client who has requested a map of the city to allow visitors to visually select their location. They want this feature to link to the City Dropdown/Select area of the form. Here is a link to the client' ...

Choose the child nodes upon selecting the root node

I am trying to implement a 2-level material-ui treeview where selecting the root node should automatically select all child nodes as well. Does anyone have suggestions on how to achieve this with material-ui treeview? For more information, please visit ma ...

Conceal HTML elements from the bottom as new content is being added dynamically

I am currently working on a comments feed feature. By default, only the first four comments are displayed, with an option to show more when clicking the "show more" anchor. The issue I'm facing is that if new comments are dynamically added, the CSS hi ...

Selenium webdriver cannot find the element within the JavaScript code

await driver.findElement(By.id('closeBtn')).click(); or await driver.findElement(By.xpath('//*[@id="closeBtn"]')).click(); When attempting to use the above conditions for a pop-up, it does not work as expected. An error is ...

Create buttons to increase or decrease values using Bootstrap and JavaScript

What is the proper way to make this button function properly? I tested adding this line of javascript code, however it prompts an alert without clicking on the buttons as well. document.querySelector(".btnminus").addEventListener(onclick,ale ...

There was an issue encountered while attempting to utilize orgchart: The property '_aZ' of null could not be read

I've been exploring the use of an organization chart library from Everything goes smoothly with a few nodes, but when I attempt to load the entire organization (approximately 1100 subjects with multiple nested levels), I encounter this console error: ...

Issue with tensorflow.js multiple regression stochastic gradient descent optimization

Greetings, everyone! I have recently encountered a perplexing issue while attempting to fit a curve in tensorflow.js. Despite spending a considerable amount of time on it over the past couple of days, I haven't been able to resolve it yet. Given that ...

Applying jQuery to deactivate blank categories within a sorted directory

I'm in the early stages of learning Javascript/jQuery. I have a list of items (specifically, course offerings) arranged in a UL. Each "course" is represented by an LI element. The list is filtered by categories using jQuery, which controls the visibil ...

The error message "ECONNRESET" occurred while attempting to send a post request using Axios to

Attempting to send a post request to my webserver using axios, I have a client that collects user input to populate an array of strings. This data is then sent via a post request using axios for processing by the server: if (parsedInput > 0 &&am ...

Error: The function Task.find is not recognized in Node.js

I've been encountering an issue with my model while connected to MongoDB and having a running server. The problem seems to be related to routing through the TaskController, but I'm not sure if it's due to the model or the find() function. I ...

How come my total isn't zero after I get a 1 on the dice roll?

I've been working on a dice game where if either of the dice rolls a 1, the score is set to 1. However, I'm having trouble getting that part of my code to work properly. I'm confident that everything else is functioning correctly. v ...

What is the process of converting the timing from my stopwatch to a standard time format?

I am currently working on a stopwatch project where I log the time into an array. However, when I try to use Math.min(array) or Math.max(array), it returns NaN (not a number). The time format for the stopwatch is like 00:00:15.91 which is not recognized as ...