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

Express ESM versioned tests #1349

Merged
merged 10 commits into from
Sep 16, 2022
Merged

Express ESM versioned tests #1349

merged 10 commits into from
Sep 16, 2022

Conversation

bizob2828
Copy link
Member

@bizob2828 bizob2828 commented Sep 13, 2022

Proposed Release Notes

  • Added test ESM loader to properly mock out agent in versioned tests.
  • Added express ESM versioned tests.

Links

Closes https://issues.newrelic.com/browse/NEWRELIC-3119

Details

This will fail until we land the test utils pr and publish a new version. In the meantime you can test this locally by checking out the branch in the test utils PR, running npm link in this branch and then just run npm run versioned:major. You will see the express-esm tests pass. It's also worth noting ESM flavored versioned tests will have some limitations. Since the loader only loads at the start of a test file, we cannot setup and teardown a mocked agent in a before/afterEach hook. Going forward if we add more exclusive ESM versioned tests, the test will need to be made atomic to avoid cross-fire between tests. The most notable changes in this PR are:

  • A test loader that swaps out a mock of the agent when the agent ESM loader tries to import the agent API(thanks @michaelgoin 🙏).
  • Refactoring of the test structure to be async in both loading the module under test and executing the test(in this case making a request and asserting info on transaction finished)
  • Saving a reference to the transactionFinished handler and removing after each test. This was the biggest downside of not being able to bootstrap and teardown a new agent between every test.

When we originally scoped these port versioned tests to ESM we thought it'd be as easy as swap a few require statements for import and call it a day but it turned out to be a large effort. That's why I did not port every single test from the cjs express tests. Verifying both transaction and segment naming tests work is a good compromise and gives me enough confidence that the agent ESM loader is properly tested via integration tests.

// TODO: remove this when we decide on how to address
// here: https://issues.newrelic.com/browse/NEWRELIC-3321
'node/no-unsupported-features/es-syntax': 'off',
'node/no-unpublished-import': 'off',
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 will open PR to put this in the shared eslint ruleset. we already do it for the cjs equivalents: https://github.com/newrelic/eslint-config-newrelic/blob/main/index.js#L108

…lso refactored relying on import + assert type as it is not yet supported in eslint parsing. lastly, renamed test .mjs so eslint can be consistent from root of agent and in test/versioned/express-esm folder
package.json to include the 2 suites we will run. finished porting segments tests, abstracted reusable express helpers
jmartin4563
jmartin4563 previously approved these changes Sep 16, 2022
Copy link
Contributor

@jmartin4563 jmartin4563 left a comment

Choose a reason for hiding this comment

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

Just have one question about the test package.json, otherwise looks good!

test/versioned/express-esm/package.json Outdated Show resolved Hide resolved
@bizob2828 bizob2828 merged commit 2123bfa into newrelic:main Sep 16, 2022
@github-actions github-actions bot mentioned this pull request Sep 22, 2022
@bizob2828 bizob2828 mentioned this pull request Sep 22, 2022
@bizob2828 bizob2828 deleted the esm-express branch August 28, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants