Skip to content

Conversation

@MiroDojkic
Copy link
Member

@MiroDojkic MiroDojkic commented Jan 18, 2025

Test setup

This PR adds a test setup that deploys infrastructure stacks using Pulumi Automation API and then runs tests using the NodeJS native test runner.

Changes

  • Added a test runner command that runs all tests (tests/**/*.test.*): npm test.
  • Added stack deploy and destroy automation that can be performed before and after all tests in a test suite.
  • Added a test suite for the WebServer component that deploys it with minimal configuration. Test asserts that healthcheck endpoint returns 200

Disclaimers

  • If multiple tests try to deploy VPC to the same AWS account, using the Project component, deployment will throw an exception due to trying to take more than the maximum number of elastic IP addresses (eips).

@MiroDojkic MiroDojkic force-pushed the feature/test-setup branch 8 times, most recently from f7bd875 to e171637 Compare January 19, 2025 22:03
@MiroDojkic MiroDojkic force-pushed the feature/multiple-efs-volumes-and-mount-points branch 2 times, most recently from e82f3fc to b2702bc Compare January 19, 2025 23:00
Base automatically changed from feature/multiple-efs-volumes-and-mount-points to master January 20, 2025 22:50
@MiroDojkic MiroDojkic force-pushed the feature/test-setup branch 3 times, most recently from fe902f2 to 69a7c0b Compare January 25, 2025 22:12
@MiroDojkic MiroDojkic changed the title Chore: Test setup chore: test setup Mar 17, 2025
@@ -0,0 +1,62 @@
import { describe, it, before, after } from 'node:test';
Copy link
Member Author

Choose a reason for hiding this comment

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

@droguljic to simplify maintenance, we could move examples to tests, since we'd like to test each component, and integration between components anyway.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, examples serve the different purpose and having them is definitely valuable. I agree that we should test each component and integration between them.
In current state I'm not sure that examples could be just copied and run as is, if I remember correctly there was some issue when I tried to do so.
My suggestion would be to reference examples in tests and in that way we ensure that they are reproducible and on the other hand we test component and integration, while leaving them to serve their purpose.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense, but it might also become complex to maintain. If we're looking to match examples with tests, we'll either introduce noise to examples by having redundant examples, or to tests by trying to make use of a single example to test many properties and assumptions.

We could also have examples only serve as examples, and rely on test setup to provide deployable stacks. It definitely doesn't make sense to have deployable stacks in both tests and examples, as that's a lot of surface to maintain (upgrades, testing that it works, updating API...).

Copy link
Contributor

Choose a reason for hiding this comment

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

Continuing on the offline conversation, the current idea is to keep complex uses cases that test integration between many components as part of examples, and more simpler ones as part of tests.

@MiroDojkic
Copy link
Member Author

@droguljic can you review the high-level approach to testing and test setup?

@MiroDojkic MiroDojkic force-pushed the feature/test-setup branch 3 times, most recently from d05a23d to 3ef2ff2 Compare March 19, 2025 10:32
@MiroDojkic MiroDojkic requested a review from droguljic March 19, 2025 16:08
@MiroDojkic MiroDojkic marked this pull request as ready for review March 19, 2025 16:08
@MiroDojkic MiroDojkic force-pushed the feature/test-setup branch 2 times, most recently from bf538a6 to cac1f87 Compare March 25, 2025 22:48
package.json Outdated
"format": "prettier -w .",
"release": "npm run build && release-it",
"test": ""
"test": "node --test -r ts-node/register ./tests/**/*.test.ts"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there any advantages of using node test vs jest? Maybe we'd want to set default test runners across the company and show by example. This is a question, I don't know which is better or better-suited.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are differences. One big preference that I have is using test runners that use native execution environments such as node's native test runner, ava, or tape.

Generally speaking, jest pulls a lot of unnecessary dependencies and is slower. Depending on the use case, extra features can be helpful or not.

Where do you find value in standardizing a test runner for unit and integration tests?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The intent was to standardize the test runners across projects. But if native runners will perform better, then we should stick with those.
My idea was to use test runners which we would be able to recommend to people as a part of the CoP.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah, I got that part, but I'm not actively developing for some time so I was genuinely curious to hear your thoughts. Might be worth exploring.
Let's bring it up during some future CoP thread or sync.

@MiroDojkic MiroDojkic force-pushed the feature/test-setup branch 3 times, most recently from 44b352e to 97b44ca Compare March 27, 2025 12:12
@MiroDojkic MiroDojkic requested review from droguljic and mbareta March 27, 2025 12:41
@MiroDojkic
Copy link
Member Author

@mbareta @droguljic I addressed your comments.
I also edited commit messages to switch to conventional commits.

@droguljic droguljic merged commit 75f4848 into master Mar 28, 2025
1 check passed
@droguljic droguljic deleted the feature/test-setup branch April 10, 2025 15:04
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.

4 participants