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

239
Visualizações
Testing of npm scripts

How can I write a test that npm scripts run successfully?

I have npm scripts in package.json as follows.

  "scripts": {
    "start": "node server.js",
    "dev": "webpack serve --mode development",
    "lint": "eslint src",
    ...

I'd like to test these npm scripts launch successfully.

For example, how do I test the command npm run dev (webpack serve) launches successfully?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You test them like you test a computer process - independent of JavaScript. You treat the fact webpack/eslint are JavaScript programs as an implementation detail.

Basically - they should only be tested in really really big projects and have a few tests.

A test can look something like:

const util = require('util');
const { exec } = util.promisify(require('child_process').exec);

describe('your run scripts', () => {
  it('starts a dev server', () => {
     // create a way to stop the server
     const ac = new AbortController(); 
     // start the dev server
     const devServerPromise = exec('npm run dev', { signal: ac.signal });
     // validate the server launched (retry comes from any promise retry package, fetch can be unidici or axios just the same)
     // localhost:4200 is an example for where the dev server is running
     await retry(() => fetch('http://localhost:4200/'));
     ac.abort(); // close the dev erver
  });
});

Note that like I started with there is very little return on investment on writing these sort of tests if your project isn't thousands of developers since the issues with stuff like npm run dev are noticed very very quickly by developers and the cost of having another call-site for them that needs to be aware of certain implementation details is high.

about 4 years ago · Juan Pablo Isaza Relatório
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