theintern / intern-examples

A collection of examples for the Intern testing library
theintern.io
85 stars 83 forks source link

Add example for React + Enzyme #29

Open dylans opened 8 years ago

dylans commented 8 years ago

Investigate https://github.com/airbnb/enzyme and consider adding an example.

crazyscience commented 8 years ago

Any progress on this @dylans?

dylans commented 8 years ago

@crazyscience not yet, it's on my list to look at, just hasn't made it to the top yet. If you're interested in it and wanted to help out, that would be great (if not, no worries).

brettdewoody commented 8 years ago

+1 - I'm happy to pair with others if anyone wants to focus on a working example/setup. After a day+ of attempts I switched to Mocha/Enzyme and had unit tests running in 30 minutes. Love the idea of using Intern for both unit/functional so it'd be great to get it working.

dylans commented 8 years ago

ok, happy to collaborate @brettdewoody ... I have zero time this week, but maybe next week?

brettdewoody commented 8 years ago

Great, let me know when you have some time.

dylans commented 8 years ago

Ok, I've had some time to think about this. I think the main thing actually needed for the example is to either offer a loader plugin to transpile Enzyme to ESM, or the example needs to be authored as ES6/ESM, with it being clear how to transpile it before testing and then hooking into remap-istanbul to preserve code coverage.

brettdewoody commented 8 years ago

Agreed. In our case we're dealing with the latter. My gut is this is the more common case as many React examples are authored in ES6/ESM.

dylans commented 8 years ago

We agree that ESM is a good syntax, but there are some challenges.

So really the challenge we face in moving from AMD to ESM for Intern is that we have some difficult work ahead to provide the features we currently offer. It's possible (and in fact easier with TypeScript than ES6).

Anyway, back to the problem at hand. :)

dylans commented 7 years ago

Note that we're pretty close with Intern 4 and its support for ESM, which will make this easier, so my plan is to complete this to coincide with Intern 4 when it's ready sometime this year.

brettdewoody commented 7 years ago

Great, thanks for the update.

draperd commented 7 years ago

@dylans I'm really interested in the ESM support you've mentioned and I'm pleased to hear you say that Intern 4 is very close. In our case we need ESM support to be able to import the CSS classnames that are exported by each React component that we want to test. Do you have any more information on when Intern 4 will be ready - the current milestone says June 30th, but nothing is marked as complete yet! ... is that a realistic date to work to? and would you expect to be able to mix and match ESM imports with the current style of authoring functional tests in AMD (i.e. having an import statement at the top of the test say?)

dylans commented 7 years ago

@draperd that's still our goal, though of course it depends on things going smoothly. One of the main changes with ESM over AMD is the lack of loader plugins, so we are generally moving away from AMD as the test authoring format, though you could still author tests with AMD if you prefer. I would not suggest a mix and match of ESM and AMD in the same file as I think that would lead to significant confusion.

draperd commented 7 years ago

@dylans OK... that's fine, at the moment we're just getting started on a new project so I'm happy to wait for ESM support (and if we write any tests now with duplicated variables we'll port them back over later).

Thanks for the update on this. I'm really looking forward to this next release. I've been using Intern with great success for the last few years and although I took a look around at some other options that are now available I've decided to stick with Intern because it does what we need so well. The update to ESM support should hopefully also help with further adoption for those who aren't familiar with or prepared to learn AMD.

dylans commented 7 years ago

Thanks @draperd!

fwiw, the current work in progress on the React+Enzyme example and Intern 4 is at https://github.com/jason0x43/intern-examples/tree/intern-4/react-enzyme-example . I wouldn't start writing your tests following this example yet as some details may change, but it at least shows the direction we're going with things.