spiderfire icon indicating copy to clipboard operation
spiderfire copied to clipboard

Multiple Tests in One File

Open Redfire75369 opened this issue 3 years ago • 3 comments

Issue

Currently, there is a limitation to the usage of tests as only 1 test per file can be created to test actions within the runtime. This is due to the following. Hence, only 1 runtime can be initialised per thread. Due to how cargo tests are run serially(with --test-threads=1) and in parallel, this means only 1 runtime can be initialised per executable, which requires 1 file per test.

It is currently not possible to initialize SpiderMonkey multiple times (that is, calling JS_Init/JSAPI methods/JS_ShutDown in that order, then doing so again). This restriction may eventually be lifted.

Finding a solution to this will improve flexibility for future tests with more complex modules, and JSAPI wrappers. Currently, I have a draft of tests for the fs module, but I am not satisfied with them, as putting them all in a singular function partially defeats the purpose of such tests, as they are not targeted. With this improvement, each portion of the fs module can then be tested independently, and properly utilise cargo's test system, with many tests and test cases.

Requirements

  • Advanced Understanding of Rust, static values and cargo tests
  • Intermediate Understanding of JavaScript
  • Understanding of Spidermonkey Runtime and Engine initialisation

Possible Solution

thread_local or Mutex could be used to store the ParentRuntime and Runtime::create_with_parent could be used to create the appropriate runtimes.

Redfire75369 avatar Aug 06 '21 09:08 Redfire75369

cargo-nextest could also be a possible solution. It seems to spawn each test in a separate process. I'll try it later, after completing the http module.

Redfire75369 avatar Sep 15 '22 11:09 Redfire75369