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

[backend] extend our vitest config for easier dev process #5796

Merged
merged 4 commits into from
Mar 11, 2024

Conversation

labo-flg
Copy link
Member

@labo-flg labo-flg commented Feb 2, 2024

Improved our tooling to be able to run dev tests locally quickly.

the globalSetup for vitest has been refactored and can be piloted by 2 env variables, INIT_TEST_PLATFORM and SKIP_CLEANUP_PLATFORM. We make use of these variables in new yarn scripts:

  • run yarn test:dev:init to cleanup your test DB, start a platform, run the loader tests that populates the database. This command won't run any other test.
  • once initialized this way, run yarn test:dev:resume <name-of-a-test-file.js> to run the specified test file only, the DB won't be cleaned up after run
  • ... or run yarn test:watch:resume <name-of-a-test-file.js> to run in watch mode

This makes developing integration tests much quicker and without having to tweak some config files locally.

As for unit tests, I would still advise to use the vitest integration in the IDE. Nothing beats that as it just won't start a platform, useless for unit tests.

The previous commands still exists ;

  • yarn test:dev for 1 complete run (cleanup/setup/all tests suites)
  • yarn test:watch for a complete execution in watch mode
  • yarn test unchanged, used by CI to run once in silent with coverage

Copy link

codecov bot commented Feb 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.68%. Comparing base (f0c79df) to head (cdad59d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5796      +/-   ##
==========================================
- Coverage   66.68%   66.68%   -0.01%     
==========================================
  Files         540      540              
  Lines       64349    64349              
  Branches     5251     5251              
==========================================
- Hits        42912    42909       -3     
- Misses      21437    21440       +3     

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

Copy link
Member

@aHenryJard aHenryJard left a comment

Choose a reason for hiding this comment

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

Thanks for making tests easier :)

opencti-platform/opencti-graphql/package.json Outdated Show resolved Hide resolved
Copy link
Member

@aHenryJard aHenryJard left a comment

Choose a reason for hiding this comment

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

Could you move globalSetup to ts or is it too complex ?
And maybe also tests/02-integration/00-inject/loader-test.js file.

If you have time, this comment is not a blocker at all.

@SarahBocognano SarahBocognano added the filigran team use to identify PR from the Filigran team label Feb 20, 2024
@labo-flg labo-flg self-assigned this Feb 29, 2024
@labo-flg labo-flg marked this pull request as ready for review February 29, 2024 09:15
@@ -19,7 +19,11 @@
"start-cluster": "NODE_ENV=cluster node build/back.js",
"serv": "node build/back.js",
"insert:dev": "node build/script-insert-dataset.js",
"test:dev": "vitest watch --config vitest.config.dev.ts",
"test:dev:init": "INIT_TEST_PLATFORM=true vitest run --config vitest.config.dev.ts --testNamePattern=\"Should import creation succeed\" tests/02-integration/00-inject/loader-test.ts",
Copy link
Member

Choose a reason for hiding this comment

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

This step is not working on my computer, "test:dev:init" is not working on my computer, I have a error at "Should import creation succeed" step,

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose you do not have more details ?
Are you sure it's not related to a python client version mismatch on your local setup?

Copy link
Member

Choose a reason for hiding this comment

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

I just managed to run this step without any issue

Copy link
Member

Choose a reason for hiding this comment

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

ok testing again now

Copy link
Member

@aHenryJard aHenryJard left a comment

Choose a reason for hiding this comment

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

As a side note, it might be a good time to improve the developper documentation as follow up PR https://docs.opencti.io/latest/development/platform/#for-testing

@labo-flg labo-flg merged commit c8dd164 into master Mar 11, 2024
8 checks passed
@labo-flg labo-flg deleted the tests/better-dev-tooling branch March 11, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filigran team use to identify PR from the Filigran team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants