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

test: fix slowdown of JS SDK unit tests #2475

Merged
merged 5 commits into from
Feb 20, 2025

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Feb 19, 2025

Issue being fixed or feature implemented

Starting JS SDK tests take >10 mins.

What was done?

  • Removed ts-mocha and compile / run tests directly using tsc and mocha

How Has This Been Tested?

  • Running locally

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Chores
    • Updated system dependencies and removed outdated testing tools to enhance overall stability.
  • Tests
    • Modified the test script to compile TypeScript before execution, ensuring smoother test runs.
    • Added extra debug logging in the test suite for improved troubleshooting.
  • Refactor
    • Optimized test configuration settings for a more streamlined TypeScript compilation process.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

The changes update testing and runtime configurations by removing the ts-mocha package and associated entries from configuration files, updating the ts-node version and link type, and removing the diff package entry in .pnp.cjs. Additionally, the js-dash-sdk package's testing script has been modified to compile TypeScript before running tests with Mocha, and the corresponding dependency has been removed. The test suite now logs setup details in its hooks, and the TypeScript configuration has been refined with new compiler options and selective file inclusion.

Changes

File(s) Change Summary
.pnp.cjs
packages/js-dash-sdk/package.json
Removed the ts-mocha dependency and associated metadata (including removal of diff version 3.5.0 in .pnp.cjs); updated ts-node version from 10.9.1 → 10.9.2 and changed its link type from HARD to SOFT; updated the test:unit script to compile TS then execute Mocha tests.
packages/js-dash-sdk/tests/functional/sdk.js Added logging statements in the before hook to output "before" and in the beforeEach hook to log the clientOpts object and the clientInstance.
packages/js-dash-sdk/tsconfig.mocha.json Introduced new compiler options (skipLibCheck, esModuleInterop, outDir set to ./build); modified the include pattern to select only src/**/*.spec.ts files; removed the exclude property.

Possibly Related PRs

Suggested Reviewers

  • QuantumExplorer
  • lklimek
  • pshenmic

Poem

I'm a rabbit, coding with delight,
Hopping through changes both day and night,
Ts-mocha has scampered off the scene,
While ts-node and tests now gleam so clean,
Logging magic in every little line—
Carrots and code, all simply divine!
🥕🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/js-dash-sdk/tests/functional/sdk.js (2)

21-23: Enhance logging message to be more descriptive.

The current log message is too generic. Since this is a functional test suite, consider adding more meaningful information about the test environment setup.

 before(async () => {
-  console.log('before');
+  console.log('Setting up SDK functional test suite...');
+  console.log(`Test environment: ${process.env.NETWORK}`);
 });

21-42: Consider using a test logger with log levels.

Since the PR's objective is to fix test slowdown, consider using a proper test logger (like debug or winston) with configurable log levels. This would allow:

  1. Enabling detailed logs only when needed
  2. Better performance in CI/CD pipelines by setting appropriate log levels
  3. Structured logging format for better debugging

Example implementation:

const debug = require('debug')('sdk:functional-tests');

// In before hook
debug('Setting up SDK functional test suite...');

// In beforeEach hook
debug('Initializing client with configuration: %o', sanitizedOpts);
debug('Client instance ready: %o', {
  network: clientInstance.network,
  apps: Array.from(clientInstance.getApps().keys()),
});

This approach allows:

  • Enabling logs with DEBUG=sdk:functional-tests npm test
  • Disabling logs in CI/CD for better performance
  • Structured and readable output
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91a9766 and 29a0eb7.

⛔ Files ignored due to path filters (6)
  • .yarn/cache/diff-npm-3.5.0-a321a0df19-cfbc2df98d.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/ts-mocha-npm-10.0.0-1ee8693e11-b11f2a8cee.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/ts-node-npm-10.9.2-3f3890b9ac-a91a15b3c9.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/ts-node-npm-7.0.1-dfa4b9e69b-c1e0f15828.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/yn-npm-2.0.0-3ad11617c1-9d49527cb3.zip is excluded by !**/.yarn/**, !**/*.zip
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • .pnp.cjs (2 hunks)
  • packages/js-dash-sdk/package.json (1 hunks)
  • packages/js-dash-sdk/tests/functional/sdk.js (2 hunks)
  • packages/js-dash-sdk/tsconfig.mocha.json (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/js-dash-sdk/tsconfig.mocha.json

[error] 5-5: Expected a property but instead found '// speeds up type checking'.

Expected a property here.

(parse)


[error] 6-6: expected , but instead found "esModuleInterop"

Remove "esModuleInterop"

(parse)


[error] 8-8: Expected a property but instead found '}'.

Expected a property here.

(parse)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (4)
.pnp.cjs (2)

8577-8584: Dependency Update and Package Removal Confirmation

This hunk updates the dependency entry for ts-node by bumping its version from an earlier version to 10.9.2 and ensuring that its resolution now uses the updated virtual reference. It also implicitly confirms the removal of the ts-mocha (and likely the diff) package entries as outlined in the PR objectives. Please verify that downstream tooling and scripts reference the new ts-node version consistently.


18724-18740: Consistent Virtual Resolution for ts-node

The update in this hunk correctly introduces two new entries referencing ts-node version 10.9.2 with a "linkType": "SOFT". Both entries (one direct and one with a virtual tag) now consistently point to the same version and packaging location. This change is aligned with the objective to remove legacy testing dependencies and ensure efficient module resolution. Ensure that any consumers expecting the old references are updated accordingly.

packages/js-dash-sdk/tsconfig.mocha.json (1)

1-10: Refined inclusion of test files is clear.

The updated "include": ["src/**/*.spec.ts"] setting now correctly restricts the compilation to the test specification files, aligning with the new testing approach. Just ensure that all JSON formatting issues are addressed (see comment above) so that the configuration is parsed correctly.

🧰 Tools
🪛 Biome (1.9.4)

[error] 5-5: Expected a property but instead found '// speeds up type checking'.

Expected a property here.

(parse)


[error] 6-6: expected , but instead found "esModuleInterop"

Remove "esModuleInterop"

(parse)


[error] 8-8: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 9-10: Expected a property but instead found '}'.

Expected a property here.

(parse)

packages/js-dash-sdk/package.json (1)

18-20: Update test:unit script aligns with the new testing workflow.

The modified test:unit script now compiles TypeScript using tsc -p tsconfig.build.json and runs tests with Mocha on the resulting JavaScript files found in the build directory. This change removes the dependency on ts-mocha and should help reduce the startup time of the test suite. Please verify that the tsconfig.build.json configuration is kept in sync with these changes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29a0eb7 and eb3dd9b.

📒 Files selected for processing (3)
  • packages/js-dash-sdk/package.json (1 hunks)
  • packages/js-dash-sdk/tests/functional/sdk.js (0 hunks)
  • packages/js-dash-sdk/tsconfig.mocha.json (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/js-dash-sdk/tests/functional/sdk.js
🧰 Additional context used
🪛 Biome (1.9.4)
packages/js-dash-sdk/tsconfig.mocha.json

[error] 8-8: Expected a property but instead found '}'.

Expected a property here.

(parse)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (3)
packages/js-dash-sdk/package.json (2)

19-19: Updated "test:unit" Script for Improved Test Startup

The "test:unit" script has been updated to compile the TypeScript test files via tsc -p tsconfig.mocha.json before running Mocha on the compiled output (build/**/*.spec.js). This eliminates the overhead of using ts-mocha and directly addresses the slow startup issue documented in the PR objectives. Please ensure by convention that the build directory is correctly cleaned or rebuilt so that outdated files do not affect the test run.


1-113: Removal of ts-mocha Dependency

The PR objectives mention that the ts-mocha dependency was removed. Although this change is not explicitly annotated on a specific line within this file, please confirm that it has been completely removed from the devDependencies section (and any related configuration files) to avoid potential conflicts or unnecessary package installations.

packages/js-dash-sdk/tsconfig.mocha.json (1)

9-9: Refined Test File Inclusion.

The updated "include" property explicitly targets test files (i.e. "src/**/*.spec.ts", "src/test/**/*.ts"), which should help speed up the test compilation process by excluding unnecessary files. This change aligns well with the PR objective of reducing test startup time.

🧰 Tools
🪛 Biome (1.9.4)

[error] 9-10: Expected a property but instead found '}'.

Expected a property here.

(parse)

Comment on lines +5 to +7
"skipLibCheck": true,
"esModuleInterop": true,
"outDir": "./build",
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 19, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

JSON Formatting: Remove Trailing Comma in compilerOptions.

The additions of "skipLibCheck", "esModuleInterop", and "outDir" are beneficial for optimizing type-checking and module interoperability, and for directing output during compilation. However, please note that valid JSON does not allow a trailing comma in an object. The comma after "outDir": "./build" (line 7) should be removed to avoid JSON parsing errors.

-    "outDir": "./build",
+    "outDir": "./build"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"skipLibCheck": true,
"esModuleInterop": true,
"outDir": "./build",
"skipLibCheck": true,
"esModuleInterop": true,
"outDir": "./build"

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 think it's a JSON 5 because tsc parses it successfully.

Copy link
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

@shumkov You're absolutely right! TypeScript's configuration files (tsconfig.json) support JSON5 format, which allows trailing commas, comments, and other convenient features. The current syntax is perfectly valid.


🌐 Web query:

Does TypeScript support JSON5 in tsconfig.json files?

💡 Result:

TypeScript's tsconfig.json files do not natively support full JSON5 syntax, but they do support a subset of JSON5 features through JSON with Comments (JSONC)[1][5][8]. Here's a breakdown:

Key Details

  1. Supported Syntax:

    • Comments (// and /* */)[2][8]
    • Trailing commas[3][8]
    • Single-quoted strings are not supported[10]
  2. Limitations:

    • Unquoted object keys and other advanced JSON5 features won't work[4][9]
    • TypeScript explicitly treats tsconfig.json as JSONC (JSON with Comments), not full JSON5[5]

Implementation Notes

  • The TypeScript compiler (tsc) uses a parser that allows:

    {
      // This comment works
      "compilerOptions": {
        "target": "ES2022",  // Trailing comma allowed
      },                      // Another trailing comma
    }

    [2][3][8]

  • Attempting to use unsupported JSON5 features like unquoted keys:

    {
      unquotedKey: "value" // Syntax error
    }

    will fail compilation[4][9].

Workarounds

For full JSON5 support in configs:

  1. Use tools like json5 to parse .json5 files[1][4]
  2. Configure build tools to transform JSON5 → JSON during compilation[1]

Why This Matters

While tsconfig.json allows limited JSON5-like syntax for readability[2][8], developers needing advanced features must use external tooling or alternative config formats[1][4]. The distinction between JSONC and JSON5 is subtle but impacts compatibility[4][9].

Citations:


@shumkov I need to correct my previous statement. TypeScript actually uses JSONC (JSON with Comments) format for tsconfig files, not full JSON5. JSONC supports a subset of JSON5-like features, specifically comments and trailing commas, which explains why the trailing comma works in your configuration. The current syntax is indeed valid with JSONC.


✏️ Learnings added
Learnt from: shumkov
PR: dashpay/platform#2475
File: packages/js-dash-sdk/tsconfig.mocha.json:5-7
Timestamp: 2025-02-19T14:58:40.145Z
Learning: TypeScript configuration files (tsconfig.json) support JSON5 format, which allows trailing commas and comments. The TypeScript compiler (tsc) successfully parses these JSON5 features.

Learnt from: shumkov
PR: dashpay/platform#2475
File: packages/js-dash-sdk/tsconfig.mocha.json:5-7
Timestamp: 2025-02-19T14:58:40.145Z
Learning: TypeScript configuration files (tsconfig.json) use JSONC (JSON with Comments) format, which supports comments and trailing commas, but not full JSON5 features. The TypeScript compiler (tsc) successfully parses these JSONC features.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@shumkov shumkov merged commit 374a036 into v2.0-dev Feb 20, 2025
23 checks passed
@shumkov shumkov deleted the test/js-sdk/tests-are-super-slow branch February 20, 2025 10:47
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.

2 participants