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

chore(trustchain): simplify test folders #7262

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

gre
Copy link
Contributor

@gre gre commented Jul 4, 2024

βœ… Checklist

  • npx changeset was attached.
  • Covered by automatic tests.
  • Impact of the changes:
    • tests only

πŸ“ Description

the lib/ output of the library no longer is polluted by test scenarios

Capture d’écran 2024-07-04 aΜ€ 14 29 33

test scenarios and test helpers are in /tests and scenario records are in /mocks outside of the src folder

(NB: it can't be a __tests__ because Jest default's config would still consider these as runnable tests)

a sdkForName helper is given to scenario to simplify the boilerplate you need to do to create a sdk

Capture d’écran 2024-07-04 aΜ€ 16 05 45

no longer need to generate individual jest test for each scenario

We simplify the necessary boilerplate to run the tests by having one test file that run them all:

fs.readdirSync(mockFolder).forEach(file => {
  if (!file.endsWith(".json")) return;
  const slug = file.slice(0, -5);
  const json = require(path.join(mockFolder, file));
  const mod = require(path.join(scenarioFolder, slug + ".ts"));
  test(slug, async () => {
    const scenario = mod.scenario;
    await replayTrustchainSdkTests(json, scenario);
  });
});

❓ Context

  • JIRA or GitHub link:

🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.
  • Performance considerations have been taken into account. (changes have been profiled or benchmarked if necessary)

@gre gre requested a review from a team as a code owner July 4, 2024 12:34
Copy link

vercel bot commented Jul 4, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
web-tools βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jul 11, 2024 11:59am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-docs ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:59am
ledger-live-github-bot ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:59am
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:59am
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2024 11:59am

@@ -1,15 +1,14 @@
import Transport from "@ledgerhq/hw-transport";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the convention we have in most projects for tests and mocks folders, please? By using __tests__ and __mocks__

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok but the problem is it doesn't work for the default jest config that wants to runs the files inside these even if they are outside of src. shouldn't we stay relatively jest standard?
(on top of these, they are not even jest tests)

@@ -13,7 +15,7 @@ const nonMockableScenarios = [
"userRefusesAuth", // can't simulate device interaction at the moment
];

const scenarioFolder = path.join(__dirname, "./test-scenarios");
const scenarioFolder = path.join(__dirname, "../../../tests/scenarios");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add aliases for mocks and tests folder, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not possible with node.js path resolvers. here we will fs.read the files, it's not a require

@gre gre force-pushed the support/simplify-trustchain-test-folders branch from 69b5782 to 2dc2afd Compare July 5, 2024 15:53
@gre gre requested a review from KVNLS July 5, 2024 15:54
@gre
Copy link
Contributor Author

gre commented Jul 5, 2024

conflict solved. pr review answered. πŸ‘

Copy link
Contributor

@mcayuelas-ledger mcayuelas-ledger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO test files should be named as follows :

(whatYouAreTesting|scenario).test.ts(x)

@gre
Copy link
Contributor Author

gre commented Jul 9, 2024

@mcayuelas-ledger which test files?
i'm ok with the idea for all files that need to be run by Jest, which is not the case of scenario files (they are not test files but a script that can indeed by imported by tests, but also can be used standalone with the e2e script)

NB: if we start renaming the scenario files to .test.ts, Jest will start to run them and basically fails, since they are not test files, and then we need specific config to ignore them, which imo is bad (we want to embrace standard config as much as possible)

for the actual Jest files, this convention is now respected :)

Capture d’écran 2024-07-09 aΜ€ 12 30 01

@gre gre force-pushed the support/simplify-trustchain-test-folders branch from 615641d to ccac0f4 Compare July 11, 2024 11:55
@gre gre merged commit 7c481b7 into develop Jul 11, 2024
60 of 66 checks passed
@gre gre deleted the support/simplify-trustchain-test-folders branch July 11, 2024 15:11
KVNLS pushed a commit that referenced this pull request Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants