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

Testing: recommend “testharness.js” instead of “mocha”? #4

Open
tripu opened this issue Sep 18, 2018 · 4 comments
Open

Testing: recommend “testharness.js” instead of “mocha”? #4

tripu opened this issue Sep 18, 2018 · 4 comments
Labels
documentation About best practices and recommended tools question Further information is requested

Comments

@tripu
Copy link
Member

tripu commented Sep 18, 2018

As I wrote on the document, imho testharness.js needs at the very least to be a project maintained independently, and a package available via npm. Then, we will need good reasons to abandon the very popular mocha in favour of this other (less powerful?) tool.

ping @plehegar

@tripu tripu added question Further information is requested documentation About best practices and recommended tools labels Sep 18, 2018
@ericprud
Copy link
Member

ericprud commented Sep 19, 2018

Jest

AFAIKT, web-platform testing isn't aiming for general use while Jest is. Here's my experience with using Jest on a couple projects:

  • ⊖ ~2s slower to start than mocha so had to increase timeouts
  • ⊕ despite warm-up time, almost twice as fast on large-ish test suite (tests, harness)
  • ⊕ embeds coverage (Istanbul)
  • ⊘ describe/test structure similar to mocha:
mocha jest
describe(desc, () => { this.timeout(T1); ... }) describe(desc, () => { ... }, T1)
it(desc, () => {}).timeout(T2) it(desc, () => {}, T2) (or test(...))
before(done => {...done();}) beforeAll(done => {...done();}, T2)
beforeEach beforeEach
  • ⊕ assertion framework requires less ceremony than chai:
chai expect jest expect
expect(res).to.match(ref) expect(res).toMatch(ref)
expect(res).to.equal(ref) expect(res).toBe(ref)
expect(res).to.deep.equal(ref) expect(res).toEqual(ref)
res.should.exist expect(res).toBeDefined()
res.to.be.undefined expect(res).toBeUndefined()
res.should.be.a('object') expect(res).toBe('object')
expect(f).to.throw(Error, /pattern/) expect(f).toThrowError(Error)
toThrowError takes one argument
(see jestjs/jest#7000)
... ...

I've not used Jest in the browser (supposed to be good with Angular).

Hopefully, this will save some folks some aggravation.

@tripu
Copy link
Member Author

tripu commented Sep 19, 2018

Thank you, @ericprud, for contributing — and for doing so with concrete ideas and details!

I haven't used Jest, but I know it's an alternative that's popular with the community. So I'm not opposed in principle. Let's see what others have to say…

Broader question: how to decide when it's time we recommend (or at least we “accept”) a new package? I'd say we can consider alternatives or additions when there is at least one W3C project using it, and its maintainers have that experience and can defend its usage with specific arguments.

I see there is not one public W3C project using Jest yet. I'll be happy for a dissenter to break with the orthodoxy and adopt it themselves on a public W3C software project, then report back here on advantages (as @ericprud did).

@SimenB
Copy link

SimenB commented Sep 19, 2018

I've not used Jest in the browser (supposed to be good with Angular).

Note that Jest cannot run in a real browser (yet: jestjs/jest#848), it runs "browser tests" in JSDOM.

You can use its assertions standalone though, instead of e.g. chai in mocha: https://www.npmjs.com/package/expect. Those support the browser

@ericprud
Copy link
Member

ericprud commented Sep 25, 2018

In jsdom with nodes earlier than 8(?), you can't let element names collide with function names, c.f. jsdom/jsdom#2259 .

What's the typical workflow for such in-browser tests, does it use headless-browser? (I've only managed to automate browser tests using jsdom so far.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation About best practices and recommended tools question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants