testing-library/preact-testing-library

Setup automatic releases

kentcdodds opened this issue · 14 comments

In the project, run:

npm i -g semantic-release-cli
semantic-release-cli setup

Follow the prompts and you'll have automatic releases set up. See http://kcd.im/write-oss for more info.

@antsmartian I'm happy to make a PR for this - bunch of features that are here on Github but aren't published to NPM.

@larrybotha Welcome. But almost all the latest codebase and its features are published to NPM.

@antsmartian ye, there are a couple things missing like rerender and debug.

Will get on this in the coming days.

awwww bup bup... I can't do this without being a collaborator on the repo owner, and access on npm :/

jseto commented

Looks like still not fixed

@jseto Yes, feel free to raise a PR. (sorry I'm not finding enough time for this)

jseto commented

To my understanding, it is not a matter of a PR since the GIT repository is correct. It is on the NPM side as @larrybotha said

I've just replaced preact-testing-library with @testing-library/react in a Preact 8.x project with +-120 test suites containing +-1000 individual tests - I had no major issues. Only thing was having to add a few await wait()s here and there for rendering

Looks like we can safely use @testing-library going forward

@larrybotha what do you mean with "safely use @testing-libray going forward"?

@fondberg there seems to be no need to rely on preact-testing-library anymore - you may be able to replace your imports with @testing-library/react without any major changes to your tests.

@fondberg Kent's using fireEventAsync there - React updates state synchronously, while Preact updates state asynchronously (as far as I learnt from testingjavascript.com); Kent's awaiting the re-render in the component once the button is clicked.

fireEventAsync essentially wraps await wait() with the event

Check out my notes here:
https://github.com/larrybotha/testing-javascript/tree/master/07-use-dom-testing-library-to-test-any-js-framework#2-use-dom-testing-library-with-preact
and annotations for fireEventAsync here: https://github.com/larrybotha/testing-javascript/blob/99b74fd77bf112882734c4e4bc266b22dc9988b4/07-use-dom-testing-library-to-test-any-js-framework/__tests__/helpers/fire-event-async.js

In React they're unnecessary, but in Preact they seem necessary for now :)

I haven't yet tinkered with Preact X, however.

A note to anyone coming across this and having trouble with @testing-library/react; v8.0.6 introduced detection of React's act from react-dom/test-utils which you likely won't have in a Preact project.

Because @testing-library/react detects act one needs to point Jest somewhere to handle the react-dom/test-utils import, otherwise Jest will throw on file not found.

Preact X solution

preact/test-utils was added to Preact X in Feb 2019, so one could map react-dom/test-utils to Preact's test utils if using a version of Preact X released since then, and benefit from Preact's implementation of act:

// jest.config

// ...

	moduleNameMapper: {
		// ...
		'^react-dom/test-utils$': 'preact/test-utils',
		// ...
	},

// ...

Note: This is untested

Preact 8.x.x solution

One can add a configuration to moduleNameMapper in their Jest config pointing to a file exporting an empty module:

// config/tests/react-dom-test-utils.js
/**
 * export an empty object, i.e. `act` is undefined
 */
module.exports = {};
// jest.config

// ...

	moduleNameMapper: {
		// ...
		'^react-dom/test-utils$': 'path/to/custom/react-dom-test-utils.js'),
		// ...
	},

// ...

Confirmed this works with Preact 8.4.2.

Closing issue since we migrated to the testing-library, releases are now automated via semantic-release.