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

93
Visualizações
express api for test with jest

How to write rest api with express for checking js code with jest?

import shell from 'shelljs'
import path from 'path'

export const checkTask = (req, res) => {
    shell.touch('./task.test.js')
    shell.ShellString(`const getSum = (a, b) => a + b\ntest('sum of 4 and 5 expected to be 9', () => { const data = getSum(4, 5); expect(data).toBe(9); })`).to('./task.test.js')
    shell.exec('npm run test')

    res.status(200).json({
        'ok': true
    })
}

It doesn't return anything, it just creates test file but doesn't run jest so i can't get results. No error messages in terminal

if i run separately like below it works

export const checkTask = (req, res) => {
    shell.touch('./task.test.js')
    shell.ShellString(`const getSum = (a, b) => a + b\ntest('sum of 4 and 5 expected to be 9', () => { const data = getSum(4, 5); expect(data).toBe(9); })`).to('./task.test.js')

    res.status(200).json({
        'ok': true
    })
}

or like this with already created test file it also works

export const checkTask = (req, res) => {
    shell.exec('npm run test')

    res.status(200).json({
        'ok': true
    })
}
about 4 years ago · Juan Pablo Isaza
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