haptic icon indicating copy to clipboard operation
haptic copied to clipboard

Tests

Open tsugabloom opened this issue 4 years ago • 3 comments
trafficstars

The reactive state library has a lot of new features/fixes over previous versions. These should be tested. Here are some initial tests to have:

  • Errors during creation shouldn't impact global state, ID counters, or run counts
  • Mismatched sig($)/sig() should throw "Mixed" error
  • Mismatched sig()/sig($) should throw "Mixed" error
  • Transactions should only commit last value and defer calling wires
  • Adoption should impact consistency checks for sigRS/sigRP lists
  • Run count should be 0 on start even for computed-signals
  • Using a computed-signal in a wire shouldn't change sigRS/sigRP lists
  • Wire unsubscribe should reset all lists and disconnect signals
  • Running in a loop causes the "Loop ${wire.name}" error
  • Pausing then writing to a signal shouldn't run a wire
  • Pausing then writing to a signal and unpausing should run a wire
  • Pause/Unpause/Pause/Unpause shouldn't do any work
  • Tree of parent/children reactors should execute in the right sorted order by pruning children
  • Error recovery. Throwing an error shouldn't hurt other wires/signals
  • Patching of a single wire works via chaining
  • Patching works

tsugabloom avatar Apr 26 '21 06:04 tsugabloom

If I may, I'd like to suggest zora - a very modern little test-framework with great performance and familiar surface ergonomics. For one, it does async tests way more reliably than pretty much any test-framework I've come across, which is why I found it and started using it in the first place. (It's very not "batteries included", which I like, but YMMV... tap-diff is my go-to tap reporter.)

For my own DOM integration tests, I've been using undom - it's extremely simple and probably just enough for testing things that don't depend on much more than Document and Node. I find for most of my DOM projects, I don't really need to roll out the whole jsdom kit'n'kaboodle, much less a headless browser. Worth a try maybe.

mindplay-dk avatar Apr 26 '21 19:04 mindplay-dk

Thanks for the tips! I'll checkout zora. I had been using ospec back when I was whiteboarding the reactive library here https://github.com/heyheyhello/haptic-reactivity/blob/work/test/sGlobalTests.js. I picked ospec at the time for the same reasons zora is preaching - be simple and light - but didn't love it.

Yeah I love undom! I actually forked it to https://github.com/heyheyhello/softdom/ when I was doing Sinuous SSR+SSG a few months back.

tsugabloom avatar Apr 26 '21 19:04 tsugabloom

Read subscribe is...complicated. Especially with the lazy computed signals. Current implementation:

    // Case: Read-Subscribe. Marks the core registered in `$` as a reader
    // This could be different than the actively running core, but shouldn't be
    else if ((read = args[0] && (args[0] as { $$?: 1 }).$$ && args[0].core)) {
      if ((read as C).sigRP.has(signal)) {
        throw new Error(`${(read as C).name} mixes sig($) & sig()`);
      }
      // Two-way link. Signal writes will now call/update core C
      (read as C).sigRS.add(signal);
      signal.cores.add((read as C));

      // Computed-signals (signals holding a core; signal.cc) can't only run C
      // when written to, they also need to run C when cc is marked stale. How
      // do we know when that happens? It'll be when one of cc.sigRS signals
      // calls cc. So, link this `read` core to each cc.sigRS call list; it'll
      // be called as collateral.
      if (signal.cc) {
        signal.cc.sigRS.forEach((_signal) => {
          // Linking _must_ be two-way. From signal.cores to core.sigXYZ. Until
          // now it's always either sigRP or sigRP, but if we use those we'll
          // break the mix error checking (above). So use a new list, sigIC.
          (read as C).sigIC.add(_signal);
          _signal.cores.add((read as C));
        });
      }
    }

I'll want to have some specific tests for this, addressing these from Sinuous:

  • https://github.com/luwes/sinuous/issues/139
  • https://github.com/luwes/sinuous/issues/162
  • https://github.com/luwes/sinuous/issues/164

tsugabloom avatar Jul 20 '21 03:07 tsugabloom