Skip to content

Conversation

@DanTup
Copy link
Member

@DanTup DanTup commented Jul 25, 2025

and some tidying up of the test output to make it less noisy.

Fixes #5604

@DanTup DanTup added this to the v3.116.0 milestone Jul 25, 2025
@DanTup DanTup added is enhancement is testing Relates to the testing (either manual or automated) of Dart Code labels Jul 25, 2025
@DanTup DanTup requested a review from Copilot July 25, 2025 15:11
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @DanTup, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the developer experience for running tests by introducing the ability to specify individual test files or globs from the command line. It also includes various improvements to reduce noise in the test output and refactors the underlying test execution scripts for better maintainability and clarity.

Highlights

  • Test Filtering via CLI: I've added support for running specific test suites directly from the command line using npm run test <...test-file-globs>. This allows developers to quickly run a subset of tests relevant to their current work, significantly speeding up the development cycle.
  • Improved Test Output & Experience: The test output has been tidied up to be less noisy. This includes suppressing verbose download logs for VS Code test environments and removing redundant console messages during test execution. Additionally, the npm scripts for testing have been modularized into pretest, test, and posttest phases for better organization and clarity.
  • Refactored Test Runner Logic: The core test runner logic in src/test/test_all.ts and src/test/test_runner.ts has been updated to handle test filtering. A new getTestSuites utility function was introduced to discover and filter test files based on the provided command-line arguments, ensuring only relevant tests are executed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for running specific test suites from the CLI using npm run test with optional test file filters, while also tidying up test output to reduce noise.

  • Introduces test filtering capability through command-line arguments and environment variables
  • Refactors test runner to extract file discovery logic into a reusable function
  • Modifies package.json scripts to improve test workflow and reduce build output verbosity

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/test/test_runner.ts Adds getTestSuites function with filtering logic and integrates filter support into the main test runner
src/test/test_all.ts Updates to use new filtering functionality and reduces console output noise
package.json Restructures test scripts to support filtered testing and quieter build output
AGENTS.md Updates documentation to reflect new test command usage patterns
Comments suppressed due to low confidence (1)

src/test/test_all.ts:41

  • [nitpick] The empty arrow function should have a more descriptive name or comment explaining why it's intentionally empty.
		report: () => { },

// If there are filters, return those that match any of them.
const files = new Set<string>();
for (let filter of filters.map(normalizeTestFilter)) {
filter = `**/*${filter}*`;
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

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

The filter pattern construction could be more robust. Consider handling edge cases where the filter might already contain wildcards or be an absolute path.

Suggested change
filter = `**/*${filter}*`;
// Check if the filter contains wildcards or is an absolute path.
const hasWildcards = /[*?]/.test(filter);
const isAbsolutePath = path.isAbsolute(filter);
// Construct the filter pattern based on its type.
if (!hasWildcards && !isAbsolutePath) {
filter = `**/*${filter}*`;
}
// Apply the filter to the list of files.

Copilot uses AI. Check for mistakes.
try {
console.log(`Attempting to download VS Code attempt #${currentAttempt}`);
await vstest.downloadAndUnzipVSCode(codeVersion);
// console.log(`Attempting to download VS Code attempt #${currentAttempt}`);
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

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

Consider removing commented-out code rather than leaving it in place. If this logging might be needed for debugging, consider using a debug flag or logger level instead.

Suggested change
// console.log(`Attempting to download VS Code attempt #${currentAttempt}`);
if (process.env.DEBUG) {
console.log(`Attempting to download VS Code attempt #${currentAttempt}`);
}

Copilot uses AI. Check for mistakes.
AGENTS.md Outdated
- `npm run build`: Builds the extension.
- `npm test`: Runs all automatic tests. This should first be run with the `BOT` env variable set to `"dart"` to run only a subset of basic Dart tests. If all of those tests, the whole test suite should be run.
- `npm run test <...test-file-globs>`: Runs tests for the given glob (or file path). This should be used while working on an individual feature because it is faster than running all tests.
- `npm run test`: Runs _all_ automatic tests for _all_ bots. This can be run with the `BOT` env variable set to (as defined in `test_all.ts`, for example to `"dart"`) to run only a single bots tests. The test suite is larged and this can be slow.
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

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

There's a typo: 'larged' should be 'large'. Also consider adding 'is' before 'large': 'The test suite is large and this can be slow.'

Suggested change
- `npm run test`: Runs _all_ automatic tests for _all_ bots. This can be run with the `BOT` env variable set to (as defined in `test_all.ts`, for example to `"dart"`) to run only a single bots tests. The test suite is larged and this can be slow.
- `npm run test`: Runs _all_ automatic tests for _all_ bots. This can be run with the `BOT` env variable set to (as defined in `test_all.ts`, for example to `"dart"`) to run only a single bots tests. The test suite is large and this can be slow.

Copilot uses AI. Check for mistakes.
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a feature for running specific test suites from the CLI, improving developer workflow. The changes to the npm scripts using pretest and posttest are a good improvement. The efforts to reduce noise in the test output are also appreciated. I've left suggestions to improve the documentation in AGENTS.md and add robustness to the test runner by handling potential JSON parsing errors.

AGENTS.md Outdated
Comment on lines 66 to 67
- `npm run test <...test-file-globs>`: Runs tests for the given glob (or file path). This should be used while working on an individual feature because it is faster than running all tests.
- `npm run test`: Runs _all_ automatic tests for _all_ bots. This can be run with the `BOT` env variable set to (as defined in `test_all.ts`, for example to `"dart"`) to run only a single bots tests. The test suite is larged and this can be slow.

Choose a reason for hiding this comment

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

medium

The documentation for npm run test is updated, but the term glob might be misleading[^1]. The implementation performs a substring match, not a full glob match. Also, there's a typo: larged should be large. Consider the following suggestion.

Suggested change
- `npm run test <...test-file-globs>`: Runs tests for the given glob (or file path). This should be used while working on an individual feature because it is faster than running all tests.
- `npm run test`: Runs _all_ automatic tests for _all_ bots. This can be run with the `BOT` env variable set to (as defined in `test_all.ts`, for example to `"dart"`) to run only a single bots tests. The test suite is larged and this can be slow.
- `npm run test <...test-filters>`: Runs tests for file paths containing any of the given filter strings. This should be used while working on an individual feature because it is faster than running all tests.
- `npm run test`: Runs _all_ automatic tests for _all_ bots. This can be run with the `BOT` env variable set to (as defined in `test_all.ts`, for example to `"dart"`) to run only a single bots tests. The test suite is large and this can be slow.

Comment on lines +62 to +63
const testFilter = process.env.DART_CODE_TEST_FILTER;
const filters: string[] | undefined = testFilter ? JSON.parse(testFilter) : undefined;

Choose a reason for hiding this comment

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

medium

The JSON.parse call on testFilter could throw an exception if the environment variable contains malformed JSON. Add a try...catch block to handle potential parsing errors[^1].

				const testFilter = process.env.DART_CODE_TEST_FILTER;
				let filters: string[] | undefined;
				if (testFilter) {
					try {
						filters = JSON.parse(testFilter);
					} catch (e) {
						return reject(new Error(`Failed to parse DART_CODE_TEST_FILTER environment variable: ${e}`));
					}
				}

…un test"

+ some tidying up of the test output to make it less noisy.
@DanTup DanTup force-pushed the better-test-running branch from 665faf7 to b1011fe Compare July 25, 2025 15:39
@DanTup DanTup merged commit 00483ee into master Jul 27, 2025
21 checks passed
@DanTup DanTup deleted the better-test-running branch July 27, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

is testing Relates to the testing (either manual or automated) of Dart Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support running individual test files from Dart-Code's test suite

2 participants