Giter Site home page Giter Site logo

Comments (2)

sgwilym avatar sgwilym commented on May 21, 2024

I did a little bit of looking into this as earthstar-graphql also needs tests that run in a node-like environment and a browser-like one. In that repo I'm using jest, which lets you configure the environment used for testing: you can use jsdom to test how code would run in a browser. I'm going to try configuring it so that the same test suites run in both environments.

But that's not very useful here, is it? 😅 It seems like tap is made specifically for testing in node environments? I couldn't find docs about configuring it otherwise.

I will see how this shakes out in earthstar-graphql, and if there is ever any appetite to migrate tests to jest in this repo, I'm more than happy to help.

from earthstar.

cinnamon-bun avatar cinnamon-bun commented on May 21, 2024

Yeah, turns out tap only works in node. But tape is almost identical and it can be browserified! So I kinda got this working but it's awkward.

(jsdom doesn't help here since it just emulates browser APIs and we need to test the actual browser javascript engine.)

Commit: 8a2bd98

Docs are in karma.conf.js, also pasted below.

Unfortunately this didn't detect #48 "detChoice problems in browser", it just worked. :/ In headless chrome, anyway.


How this works

Run npm run test-in-browser to do all these steps at once:

  1. npm run clean
  2. npm run build // typescript build
  3. npm run browserify-for-karma // make a bundle from one test file
  4. npm run karma // run karma headless browser test on the bundle

The browserify step currently can only process one of the *.test.js files.
It's hardcoded in package.json in the "browserify-for-karma" step.
Change it there to run different tests.
To fix this, I think browserify would need to make a separate bundle
for each of our *.test.js files.

ALSO

The tap module is not browserifiable. We tell browserify to
swap it for tape (see the browser section of package.json).
tape's API is almost identical except it doesn't have t.done(), it has t.end().
So write all the tests using t.end(), which works in both.

FUTURE IMPROVEMENTS

The npm packages karma-browserify and karma-typescript look promising
but I was not able to get them working.

from earthstar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.