Skip to content

chore: add test-services scripts per package #2932

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

Merged

Conversation

david-luna
Copy link
Contributor

@david-luna david-luna commented Jul 9, 2025

Which problem is this PR solving?

This PR is a follow-up of #2886 which aims to provide all the necessary tools/scripts in each package to work independently from others. As described in CONTRIBUTING.md with the added scripts a developer could start and stop the necessary services to test an instrumentation.

Supersedes: #2214

Short description of the changes

  • add test-services:start and test-services:stop script in each package that requires services to run the tests. These scripts start/stop only the necessary services instead of all the ones defined in /test/docker-compose.yml.
  • add test:with-services-env where applies. The script sets the necessary environment variables for testing and runs the tests
  • add test-all-versions:with-services-env script where applies. The script does like tes:with-services-env but runs tav instead.
  • intr-mongodb test script changes to test current version installed (v5-v6 tests). Other versions will be tests using test-all-versions script and the coverage will be collected and reported in chore: add new PR workflow #2866

Other changes

The scripts section of each package has been reordered to be grouped by topic: compilation, linting, test, ...

All packages now have a structure similar to this

{
    // compile topic
    "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
    "compile": "tsc -p .",
    "compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/sampler-aws-xray",
    // linting topic
    "lint": "eslint . --ext .ts",
    "lint:fix": "eslint . --ext .ts --fix",
    // publish topic
    "prepublishOnly": "npm run compile",
    // test topic
    "tdd": "npm run test -- --watch-extensions ts --watch",
    "test": "nyc mocha 'test/**/*.test.ts'",
    // others topic
    "version:update": "node ../../scripts/version-update.js",
    "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json"
}

npm run test:with-services-config # runs 'npm test' with envvars from test/test-services.env
npm run test-services:stop # stops services in Docker
npm run test-services:start # starts services in Docker
npm run test:with-services-env # runs 'npm test' with envvars from test/test-services.env
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note to reviewer: this was a typo from #2886

@@ -117,7 +117,7 @@ The required steps to start development on a pacakge are:

- `npm ci` from root folder to install dependencies ([see npm-ci docs](https://docs.npmjs.com/cli/v10/commands/npm-ci))
- `cd` into the pacakge you want to apply changes.
- `npm run setup:dev` compiles the TypeScript files for this package and its dependencies within the repository.
- `npm run compile:with-dependencies` compiles the TypeScript files for this package and its dependencies within the repository.
Copy link
Contributor Author

@david-luna david-luna Jul 9, 2025

Choose a reason for hiding this comment

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

note for reviewer: script name has changed to be more explicit about what it does. you will see this change on each package.json that has it

"version:update": "node ../../scripts/version-update.js",
"watch": "tsc -w",
"test:docker:run": "docker run -d --hostname demo-amqplib-rabbit --name amqplib-unittests -p 22221:5672 --env RABBITMQ_DEFAULT_USER=username --env RABBITMQ_DEFAULT_PASS=password rabbitmq:3"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note for reviewer: scripts with docker commands have been deleted because now the service is controlled via test-services:start and test-services:stop

Copy link

codecov bot commented Jul 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.79%. Comparing base (952abc7) to head (8c2783d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2932      +/-   ##
==========================================
- Coverage   89.89%   89.79%   -0.10%     
==========================================
  Files         188      188              
  Lines        9222     9222              
  Branches     1900     1900              
==========================================
- Hits         8290     8281       -9     
- Misses        932      941       +9     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -33,62 +32,6 @@ import * as path from 'path';
import * as fs from 'fs';
import { InstrumentationBase } from '@opentelemetry/instrumentation';

const dockerRunCmds = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note for reviewer: not needed anymore

"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc mocha 'test/**/*.test.ts'",
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
"//todo": "echo \"add test-all-versions\"",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note for reviewer: this is a reminder to configure test all versions in order to get the coverage reports. There is a follow up PR which will take care of it

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we necessarily want to add TAV testing for the packages that don't currently have it? For example, memcached hasn't had a release since 2016.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say is a nice to have.

@david-luna david-luna changed the title chore: add test-services scripts chore: add test-services scripts per package Jul 9, 2025
Copy link
Contributor

This package does not have an assigned component owner and is considered unmaintained. As such this package is in feature-freeze and this PR will be closed with 14 days unless a new owner or a sponsor (a member of @open-telemetry/javascript-approvers) for the feature is found. It is the responsibility of the author to find a sponsor for this feature.
Are you familiar with this package? Consider becoming a component owner.

@trentm trentm added the has:sponsor This package or feature has a sponsor that has volunteered to review PRs and respond to questions label Jul 23, 2025
Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

I'm tearing up. This is beautiful.

"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc mocha 'test/**/*.test.ts'",
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
"//todo": "echo \"add test-all-versions\"",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we necessarily want to add TAV testing for the packages that don't currently have it? For example, memcached hasn't had a release since 2016.

@@ -10,24 +10,24 @@
"directory": "packages/instrumentation-mongodb"
},
"scripts": {
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
"test": "npm run test-v4 && npm run test-v5-v6",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should perhaps mention in the description that this PR is chaning the instr-mongodb tests to just test v5-v6, and leaving testing of the old versions to TAV.

Comment on lines 21 to 23
"test": "npm run test-v1-v2 && npm run test-v3 && nyc merge .nyc_output ./coverage/coverage-final.json",
"test-v1-v2": "tav winston 2.4.7 npm run test-run",
"test-v3": "npm run test-run",
Copy link
Contributor

Choose a reason for hiding this comment

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

Will need to deal with a merge conflict from my recent instr-winston testing change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commit bb454f5

@@ -1,5 +1,5 @@
RUN_CASSANDRA_TESTS=1
CASSANDRA_HOST=localhostç
CASSANDRA_HOST=localhost
Copy link
Contributor

Choose a reason for hiding this comment

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

!

Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Perhaps also git rm packages/instrumentation-mysql2/env. I only just noticed this file exists. It is (almost) a subset of test/test-services.env. "Almost" because the port is different.

@david-luna
Copy link
Contributor Author

Perhaps also git rm packages/instrumentation-mysql2/env. I only just noticed this file exists. It is (almost) a subset of test/test-services.env. "Almost" because the port is different.

commit 8c2783d

@david-luna david-luna merged commit 9d90781 into open-telemetry:main Jul 31, 2025
23 checks passed
@david-luna david-luna deleted the add-services-scripts-per-package branch July 31, 2025 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has:sponsor This package or feature has a sponsor that has volunteered to review PRs and respond to questions pkg:auto-configuration-propagators pkg:auto-instrumentations-node pkg:auto-instrumentations-web pkg:host-metrics pkg:id-generator-aws-xray pkg:instrumentation-amqplib pkg:instrumentation-aws-lambda pkg:instrumentation-aws-sdk pkg:instrumentation-bunyan pkg:instrumentation-cassandra-driver pkg:instrumentation-connect pkg:instrumentation-cucumber pkg:instrumentation-dataloader pkg:instrumentation-dns pkg:instrumentation-document-load pkg:instrumentation-express pkg:instrumentation-fastify pkg:instrumentation-fs pkg:instrumentation-generic-pool pkg:instrumentation-graphql pkg:instrumentation-hapi pkg:instrumentation-ioredis pkg:instrumentation-kafkajs pkg:instrumentation-knex pkg:instrumentation-koa pkg:instrumentation-long-task pkg:instrumentation-lru-memoizer pkg:instrumentation-memcached pkg:instrumentation-mongodb pkg:instrumentation-mongoose pkg:instrumentation-mysql pkg:instrumentation-mysql2 pkg:instrumentation-nestjs-core pkg:instrumentation-net pkg:instrumentation-oracledb pkg:instrumentation-pg pkg:instrumentation-pino pkg:instrumentation-redis pkg:instrumentation-restify pkg:instrumentation-router pkg:instrumentation-runtime-node pkg:instrumentation-socket.io pkg:instrumentation-tedious pkg:instrumentation-undici pkg:instrumentation-user-interaction pkg:instrumentation-winston pkg:plugin-react-load pkg:propagation-utils pkg:propagator-aws-xray pkg:propagator-aws-xray-lambda pkg:propagator-instana pkg:propagator-ot-trace pkg:redis-common pkg:resource-detector-alibaba-cloud pkg:resource-detector-aws pkg:resource-detector-azure pkg:resource-detector-container pkg:resource-detector-gcp pkg:resource-detector-github pkg:resource-detector-instana pkg:sampler-aws-xray pkg:sql-common pkg:test-utils pkg-status:unmaintained:autoclose-scheduled pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found.
Projects
None yet
Development

Successfully merging this pull request may close these issues.