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

Figure out a way to unit test collections #51

Closed
ailisp opened this issue May 20, 2022 · 3 comments
Closed

Figure out a way to unit test collections #51

ailisp opened this issue May 20, 2022 · 3 comments
Assignees

Comments

@ailisp
Copy link
Member

ailisp commented May 20, 2022

quickjs doesn't support require, so cannot conditionally require mocked host functions to test collections

We don’t have to have this before the first release, but certain collections' functionality need at least being tested indirectly by examples

@ailisp ailisp mentioned this issue May 23, 2022
@ailisp
Copy link
Member Author

ailisp commented May 23, 2022

The other attempts I made or thought of:

  • Find how to let the js know about whether it is running on nodejs or quickjs. Haven't found a way
  • Tried to let the js file directly run in quickjs for test. We'll need to write raw tests since most test framework would not in quickjs environment
  • Tried to use require to import different file at runtime. However quickjs doesn't support it.
  • Tried to use import as nodejs import syntax, error.
  • Tried to use import as function in quickjs, doesn't give error, but it always return empty object
  • Tried to mutate a module after import, but it is frozen

Some ways that might work:

  • Config babel in a smart way or write a babel plugin, so that it compiled using mocked host functions for test and resulting module can be tested with quickjs binary
  • Make a script to copy the source, prepend import * as env from 'mock-env.js to source and test
  • Modify quickjs.c, add runtime conditional import support
  • Modify jsvm.c, make it conditional compiled. For test version, all host functions are mocked

Please feel free to suggest other ways with least efforts to allow us tests!

@volovyks
Copy link
Collaborator

If all the above options will fail - we can use workspaces for that.

@ailisp
Copy link
Member Author

ailisp commented May 24, 2022

Yes, workspace is a good approach. We can write contract to test specific APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants