Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fail-fast option #226

Merged
merged 2 commits into from
May 11, 2024

Conversation

rodrigo-militao
Copy link
Collaborator

@rodrigo-militao rodrigo-militao commented May 4, 2024

Fail Fast

poku(targetPaths: string | string[], configs?: Configs)

failFast: boolean

By setting failFast to true, Poku will stop the tests at the first failure.

API (in-code)

poku(['...'], {
  failFast: true,
});

CLI

npx poku --fail-fast ./test

Copy link

codecov bot commented May 4, 2024

Codecov Report

Attention: Patch coverage is 95.65217% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 92.53%. Comparing base (5f80fa3) to head (9addbee).

Files Patch % Lines
src/services/run-tests.ts 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
+ Coverage   92.49%   92.53%   +0.04%     
==========================================
  Files          27       27              
  Lines        1998     2010      +12     
  Branches      214      212       -2     
==========================================
+ Hits         1848     1860      +12     
  Misses        143      143              
  Partials        7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wellwelwel
Copy link
Owner

wellwelwel commented May 5, 2024

Muito obrigado, @rodrigo-militao 🚀

Estou pensando se tem uma forma simples de aplicar essa feature na execução paralela:

export const runTestsParallel = async (
dir: string,
configs?: Configs
): Promise<boolean> => {
const cwd = process.cwd();
const testDir = path.join(cwd, dir);
const files = IS_FILE(dir) ? [dir] : listFiles(testDir, undefined, configs);
const promises = files.map(async (filePath) => {
const testPassed = await runTestFile(filePath, configs);
if (!testPassed) {
++results.fail;
return false;
}
++results.success;
return true;
});
const concurrency = await Promise.all(promises);
return concurrency.every((result) => result);
};

Onde a execução dos testes ocorrem aqui:

const concurrency = await Promise.all(promises);

@rodrigo-militao
Copy link
Collaborator Author

Mestre, depois de algumas tentativas .. só obtive sucesso utilizando um Throw ali no meio da execução. Não sei se existe alguma forma mais "elegante" de se fazer.

Assim ficaria:

export const runTestsParallel = async (
  dir: string,
  configs?: Configs
): Promise<boolean> => {
  const cwd = process.cwd();
  const testDir = path.join(cwd, dir);
  const files = IS_FILE(dir) ? [dir] : listFiles(testDir, undefined, configs);

  try {
    const promises = files.map(async (filePath) => {
      const testPassed = await runTestFile(filePath, configs);

      if (!testPassed) {
        ++results.fail;
        if (configs?.fastFail)
          throw new Error('Test failed with fastFail enabled');
        return false;
      }

      ++results.success;

      return true;
    });

    const concurrency = await Promise.all(promises);

    return concurrency.every((result) => result);
  } catch (error) {
    return false;
  }
};

@wellwelwel
Copy link
Owner

wellwelwel commented May 11, 2024

Mestre, depois de algumas tentativas .. só obtive sucesso utilizando um Throw ali no meio da execução. Não sei se existe alguma forma mais "elegante" de se fazer.

@rodrigo-militao, parece uma boa abordagem (e bem simples, inclusive) 🌞

@wellwelwel wellwelwel changed the title feat: add fast-fail option feat: add fail-fast option May 11, 2024
@wellwelwel wellwelwel merged commit c204c5d into wellwelwel:main May 11, 2024
27 checks passed
@wellwelwel
Copy link
Owner

@rodrigo-militao, muito obrigado pela contribuição 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants