Skip to content

Commit

Permalink
support react 19 (#153)
Browse files Browse the repository at this point in the history
* ci: add react 19 to the matrix

* pkg: add react 19 to supported range

* Full on testing framework ugh

* drop react 17
  • Loading branch information
goto-bus-stop authored Dec 12, 2024
1 parent 3aee960 commit f268079
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
name: Tests
strategy:
matrix:
node-version: [18.x, 20.x]
react-version: [17.x, 18.x]
node-version: [18.x, 20.x, 22.x]
react-version: [18.x, 19.x]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
"@rollup/plugin-babel": "^6.0.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.1.0",
"@u-wave/react-translate-example": "file:example",
"@u-wave/translate": "^1.1.0",
"@vitest/coverage-v8": "^2.0.2",
Expand All @@ -24,6 +26,7 @@
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^4.0.4",
"jsdom": "^25.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-test-renderer": "^18.0.0",
Expand All @@ -41,7 +44,7 @@
"main": "dist/react-translate.js",
"module": "dist/react-translate.es.js",
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0"
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
},
"repository": {
"type": "git",
Expand Down
45 changes: 20 additions & 25 deletions src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from 'vitest';
import React from 'react';
import PropTypes from 'prop-types';
import TestRenderer from 'react-test-renderer';
import { render, screen } from '@testing-library/react';
import Translator from '@u-wave/translate';
import {
TranslateProvider,
Expand All @@ -21,18 +21,18 @@ describe('translate', () => {

it('should inject a `t` prop', () => {
const Component = translate()(({ t }) => (
<p>
<p data-testid="t">
{t('test')}
</p>
));

const renderer = TestRenderer.create((
render((
<TranslateProvider translator={translator}>
<Component />
</TranslateProvider>
));

expect(renderer.toJSON().children).toEqual(['key']);
expect(screen.getByTestId('t').textContent).toEqual('key');
});
});

Expand All @@ -44,31 +44,30 @@ describe('Interpolate', () => {
it('should accept React elements as interpolation data', () => {
function Welcome({ name }) {
return (
<Interpolate
i18nKey="welcome"
name={(
<strong>
{name}
</strong>
)}
/>
<p data-testid="interpolate">
<Interpolate
i18nKey="welcome"
name={(
<strong>
{name}
</strong>
)}
/>
</p>
);
}
Welcome.propTypes = {
name: PropTypes.string.isRequired,
};

const renderer = TestRenderer.create((
render((
<TranslateProvider translator={translator}>
<Welcome name="World" />
</TranslateProvider>
));

expect(renderer.toJSON()).toEqual([
'Welcome ',
{ type: 'strong', props: {}, children: ['World'] },
'!',
]);
expect(screen.getByTestId('interpolate').textContent).toEqual('Welcome World!');
expect(screen.getByTestId('interpolate').innerHTML).toEqual('Welcome <strong>World</strong>!');
});
});

Expand All @@ -82,22 +81,18 @@ describe('useTranslator', () => {
function Component({ name }) {
const { t } = useTranslator();
return (
<p>
<p data-testid="use">
{t('welcome', { name })}
</p>
);
}

const renderer = TestRenderer.create((
render((
<TranslateProvider translator={translator}>
<Component name="nobody" />
</TranslateProvider>
));

expect(renderer.toJSON()).toEqual({
type: 'p',
props: {},
children: ['Welcome nobody!'],
});
expect(screen.getByTestId('use').textContent).toEqual('Welcome nobody!');
});
});
5 changes: 5 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
test: {
environment: 'jsdom',
},
};

0 comments on commit f268079

Please sign in to comment.