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

WIP - Run all tests using Jest #1306

Conversation

lindapaiste
Copy link
Contributor

@lindapaiste lindapaiste commented Feb 24, 2022

Completed:

Settings:

  • Add "_test\\.js" alongside the deafult Jest testRegex to match all index_test.js files.
  • Add testEnvironmentOptions: { resources: "usable" } to Jest config so that images will call the onload function.
  • Set env: { jest: true } in .eslint.js to fix es-lint errors re: undefined variable jest.
  • Install node polyfill for canvas.

Rewrites:

  • Import the functions to test from local files instead of a global ml5 variable.
    • Rewrite test imports from const { charRNN } = ml5; to import charRNN from './index';.
    • import tf directly from @tensorflow/tfjs in NeuralNetwork instead of using ml5.tf alias.
  • Replace all instances of jasmine.DEFAULT_TIMEOUT_INTERVAL = n; with jest.setTimeout(n);.
  • Replace spyOn with jest.spyOn (which internally calls the jasmine spyOn function).
    • Modify chained function calls, eg. .and.callFake to .mockImplementation, .and.returnValue to .mockReturnValue, etc.

General Clean-up:

  • Move common logic re: image creation into testUtils.

TODO:

  • Prevent errors from empty test files.
    • I put an empty describe in each file and added passWithNoTests: true to Jest config, but this doesn't work.
  • Fix fetch calls which are executed internally in the face-api.js package.
    • Adding "cross-fetch/polyfill" to setupFiles in Jest config prevents the fetch errors, but then the test just hangs.
  • Guard references to ImageData to avoid error ImageData is not defined in the node environment and/or install polyfill.
  • Use @tensorflow/tfjs-node in tests.

amirfeqhi and others added 30 commits April 6, 2020 18:45
Word2vec.nearestFromSet() is giving always null output.

Reason:
!miniModel.length is always true because miniModel is object and length attribute is undefined.
added a line break
you had to manually add 'model.json' to the url and its confusing for beginners
Fix typo in examples/CONTRIBUTING.md
accidentally added wrong contribution type, now fixed
joeyklee and others added 16 commits February 22, 2022 21:56
DBSCAN Clustering Algorithm
docs: add asvsfs as a contributor for code, example
…all `index_test.js` files.

* Set `env: { jest: true }` in .eslint.js to fix es-lint errors re: undefined variable `jest`.
* Import the functions to test from local files instead of a global `ml5` variable.
    * Rewrite test imports from `const { charRNN } = ml5;` to `import charRNN from './index';`.
    * import `tf` directly from `@tensorflow/tfjs` in NeuralNetwork instead of using `ml5.tf` alias.
* Replace all instances of `jasmine.DEFAULT_TIMEOUT_INTERVAL = n;` with `jest.setTimeout(n);`.
* Replace `spyOn` with `jest.spyOn` (which internally calls the jasmine `spyOn` function).
    * Modify chained function calls, eg. `.and.callFake` to `.mockImplementation`, `.and.returnValue` to `.mockReturnValue`, etc.
* Install node polyfill for `canvas`.
…ests.

* Utility `randomImageData` creates an `ImageData` object of any size with random pixels. (TODO: needs node polyfill)
* Add `typeof HTMLVideoElement !== 'undefined'` check to prevent errors in Node.js environments.
* Reject `loadVideo` promise if there is no video.
* Check that `this.size` is a non-zero number before using it.
* Set `this.videoReady` to `true` from the base class.
…iste

docs: add lindapaiste as a contributor for code, ideas, bug
@joeyklee joeyklee deleted the branch ml5js:joeyklee.637-rm-other-testing-libs April 5, 2022 21:45
@joeyklee joeyklee closed this Apr 5, 2022
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.

10 participants