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

119
Views
Pruebas que fallan aleatoriamente con broma y nodo

Necesitaba ejecutar comandos de shell y mantener vivo el proceso para mantener los cambios realizados en las variables env, así que hice una función que se ve así:

 import { spawn } from 'child_process'; function exec(command) { const bash = spawn('/bin/bash', { detached: true }); bash.stdout.setEncoding('utf-8'); bash.stderr.setEncoding('utf-8'); return new Promise(resolve => { const result = { stdout: '', stderr: '', code: 0 }; bash.stdout.on('data', data => { // Removes the last line break (ie \n) from the data. result.stdout += data.substring(0, data.length - 1); // Gets the code by getting the number before the `:` on the last line result.code = Number(result.stdout.split('\n').pop().split(':')[0]); resolve(result); }); bash.stderr.on('data', err => { result.stderr += err; resolve(result); }); // Writes the passed command and another to check the code of the command bash.stdin.write(command + `; echo "$?:${ command }"\n`); }); }

La prueba es sencilla:

 it('should run a command that outputs an error', async () => { // Notice the typo in `echoo` const res = await exec('echoo test'); expect(res.code).toBe(127); });

Al ejecutar esta prueba, a veces falla y el res.code es 0 en lugar de 127 .

Cuando se prueba sin bromas, funciona perfectamente el 100% del tiempo.

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!