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 file for Synthutils.js added #4199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

justin212407
Copy link
Contributor

@justin212407 justin212407 commented Dec 28, 2024

Description:

This pull request addresses issue #4124 for including test files.

Changes Made:

The test file for synthutils.js has been added through this pull request. It addresses all the functions present in the synthutils.js file.

Screenshots:

Screenshot 2024-12-28 204056

Screenshot 2024-12-28 204110

Checklist:

  • My changes adhere to the project's contribution guidelines.
  • Code changes are implemented.
  • The test written passes all the checks.

@justin212407
Copy link
Contributor Author

@walterbender please review this as the babel.config.js will be needed to write some other tests too.

@walterbender
Copy link
Member

I am seeing:
` FAIL js/utils/tests/synthutils.test.js
● Test suite failed to run

Cannot find module 'tone' from 'js/utils/__tests__/synthutils.test.js'

  4 | import Synth from '../synthutils';
  5 |
> 6 | jest.mock('tone', () => ({
    |      ^
  7 |   Transport: {
  8 |     start: jest.fn(),
  9 |     stop: jest.fn()

  at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
  at Object.mock (js/utils/__tests__/synthutils.test.js:6:6)

(node:505714) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
`

@justin212407
Copy link
Contributor Author

@walterbender you need to install tone.js locally for it to run. That's probably why you are facing those errors as the synthutilsjs file uses tone.js for testing.

@justin212407
Copy link
Contributor Author

justin212407 commented Dec 29, 2024

Just checked it again by running the test locally, it runs successfully when i run it that way
Screenshot 2024-12-30 021922

@walterbender
Copy link
Member

Isn't tone.js already installed as part of MB? Or does it need to be installed as an NPM package as well?

@justin212407
Copy link
Contributor Author

@walterbender it needs to be installed as an NPM package using npm install tone.js

@walterbender
Copy link
Member

FAIL js/utils/tests/synthutils.test.js
● Test suite failed to run

ReferenceError: regeneratorRuntime is not defined

  86 |   });
  87 |
> 88 |   test('startRecording should start recording and resolve correctly', async () => {
     |                                                                     ^
  89 |     await expect(synth.startRecording()).resolves.toBeUndefined();
  90 |     expect(synth.startRecording).toHaveBeenCalled();
  91 |   });

  at regeneratorRuntime (js/utils/__tests__/synthutils.test.js:88:69)
  at Object.<anonymous> (js/utils/__tests__/synthutils.test.js:51:9)

Test Suites: 1 failed, 5 passed, 6 total

@justin212407
Copy link
Contributor Author

@walterbender this error is arising because you don't have babel dependencies installed as an npm package
use these commands to install them then the tests will run perfectly
npm install --save-dev jest babel-jest @babel/core @babel/preset-env @babel/plugin-transform-runtime jest-environment-jsdom regenerator-runtime
npm install --save @babel/runtime
this completely installs all the packages
i checked whether the tests were running on my laptop again it is
image

@walterbender
Copy link
Member

I guess my question is, how is one to know what npm dependencies are missing?

@walterbender
Copy link
Member

I installed babel and still got the same error.

@justin212407
Copy link
Contributor Author

justin212407 commented Dec 31, 2024

@walterbender The error ReferenceError: regeneratorRuntime is not defined occurs because the async/await syntax requires the regeneratorRuntime, which is missing in your current environment. This typically happens when Babel isn't correctly set up to inject the required runtime or when dependencies like @babel/runtime are missing.
Using this command will fix that - npm install --save @babel/runtime
If Babel doesn’t automatically inject the regeneratorRuntime, this plugin is essential - npm install --save-dev @babel/plugin-transform-runtime

@justin212407
Copy link
Contributor Author

I guess to identify necessary dependencies, reviewing the source code for advanced syntax (e.g., async/await, JSX) or library-specific imports and analyzing configuration files like Jest and Babel for required plugins (e.g., @babel/plugin-transform-runtime) and presets (e.g., @babel/preset-env) could be the answer or what we could do is create a section in the readme which would address all the dependencies that would be needed to install in the environment for the tests to work, this might help as there are going to be various tests written on various files.

@walterbender
Copy link
Member

still doesn't work for me.

@justin212407
Copy link
Contributor Author

@walterbender should I close this pr and create a new one with all the dependencies to be installed listed down together?

@walterbender
Copy link
Member

worth a try

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