Skip to content

Commit

Permalink
Trocando o mock de process.exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelsanchesdasilva committed Feb 11, 2024
1 parent 6e10431 commit a4c0b3d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion fontes/delegua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Delegua implements DeleguaInterface {

return JSON.parse(sistemaArquivos.readFileSync(manifesto, { encoding: 'utf8' })).version || '0.26';
} catch (error: any) {
return '0.24 (desenvolvimento)';
return '0.32 (desenvolvimento)';
}
}

Expand Down
12 changes: 7 additions & 5 deletions testes/nucleo-execucao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ describe('Núcleo de execução', () => {
const nucleoExecucao = new NucleoExecucao('0.1', funcaoDeRetorno);
nucleoExecucao.configurarDialeto();

const processReal = process;
const exitMock = jest.fn();
// const processReal = process;
// const exitMock = jest.fn();

// Mock de `process.exit`.
// Se não for feito, o teste falha.
global.process = { ...processReal, exit: exitMock as any };
// @ts-ignore: `process.exit()` retorna `never`.
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {});
// global.process = { ...processReal, exit: exitMock as any };

// Aqui vamos simular a resposta para duas variáveis de `leia()`.
const respostas = [
Expand All @@ -42,8 +44,8 @@ describe('Núcleo de execução', () => {
};
await nucleoExecucao.carregarEExecutarArquivo('./exemplos/condicionais/escolha-com-enquanto.delegua');

expect(exitMock).toHaveBeenCalledWith(0);
expect(mockExit).toHaveBeenCalledWith(0);
expect(retornoSaida.length).toBeGreaterThan(0);
global.process = processReal;
// global.process = processReal;
});
});
8 changes: 0 additions & 8 deletions testes/nucleo-traducao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@ describe('Núcleo de tradução', () => {
const funcaoDeRetorno = (saida: string) => retornoSaida += saida;
const nucleoTraducao = new NucleoTraducao(funcaoDeRetorno);

const processReal = process;
const exitMock = jest.fn();

// Mock de `process.exit`.
// Se não for feito, o teste falha.
global.process = { ...processReal, exit: exitMock as any };

nucleoTraducao.iniciarTradutor('javascript-para-delegua');
nucleoTraducao.traduzirArquivo('./exemplos/tradutores/javascript-para-delegua.js', false);

expect(retornoSaida).toContain("escreva('JavaScript para Delégua!!!')");
global.process = processReal;
});
});

0 comments on commit a4c0b3d

Please sign in to comment.