Skip to content

Commit af5bf75

Browse files
Configure Babel with Browserslist
1 parent df6b6da commit af5bf75

File tree

7 files changed

+1516
-85
lines changed

7 files changed

+1516
-85
lines changed

.browserslistrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[javascripts]
2+
supports es6-module
3+
4+
[node]
5+
node 22

babel.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { NODE_ENV } = process.env;
2+
3+
/**
4+
* Babel config
5+
*
6+
* @type {TransformOptions}
7+
*/
8+
module.exports = {
9+
browserslistEnv: 'javascripts',
10+
presets: [
11+
[
12+
'@babel/preset-env',
13+
{
14+
// Apply bug fixes to avoid transforms
15+
bugfixes: true,
16+
17+
// Apply smaller "loose" transforms for browsers
18+
loose: true,
19+
20+
// Apply ES module transforms for Jest
21+
// https://jestjs.io/docs/ecmascript-modules
22+
modules: NODE_ENV === 'test' ? 'auto' : false,
23+
},
24+
],
25+
[
26+
'@babel/preset-react',
27+
{
28+
development: NODE_ENV === 'development',
29+
useBuiltIns: true,
30+
},
31+
],
32+
'@babel/preset-typescript',
33+
],
34+
env: {
35+
test: {
36+
browserslistEnv: 'node',
37+
},
38+
},
39+
};
40+
41+
/**
42+
* @import { TransformOptions } from '@babel/core'
43+
*/

jest.config.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
const { pathsToModuleNameMapper } = require('ts-jest');
2-
const { compilerOptions } = require('./tsconfig.base.json');
3-
4-
const jestConfig = {
5-
testEnvironment: 'jsdom',
6-
rootDir: './',
1+
/**
2+
* Jest config
3+
*
4+
* @type {Config}
5+
*/
6+
module.exports = {
7+
collectCoverageFrom: ['<rootDir>/src/**/*.{js,mjs,ts,tsx}'],
8+
extensionsToTreatAsEsm: ['.jsx', '.ts', '.tsx'],
79
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
8-
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,tsx}'],
9-
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
10-
prefix: '<rootDir>',
11-
}),
10+
testEnvironment: 'jsdom',
1211
transform: {
13-
'^.+\\.(t|j)sx?$': [
14-
'ts-jest',
15-
{
16-
babelConfig: {
17-
plugins: ['@babel/plugin-transform-modules-commonjs'],
18-
},
19-
},
20-
],
12+
'^.+\\.(js|mjs|ts|tsx)$': ['babel-jest', { rootMode: 'upward' }],
2113
},
2214
};
2315

24-
module.exports = jestConfig;
16+
/**
17+
* @import { Config } from 'jest'
18+
*/

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"types": "dist/esm/index.d.ts",
2929
"scripts": {
3030
"cleanup": "rm -rf dist/ > /dev/null && rm -rf lib/ > /dev/null",
31-
"storybook": "storybook dev -p 6006",
31+
"storybook": "NODE_ENV=development storybook dev -p 6006",
3232
"build": "yarn cleanup && rollup -c",
3333
"test": "jest",
3434
"test:watch": "jest --watch",
@@ -41,8 +41,10 @@
4141
},
4242
"license": "MIT",
4343
"devDependencies": {
44-
"@babel/core": "^7.24.1",
45-
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
44+
"@babel/core": "^7.28.4",
45+
"@babel/preset-env": "^7.28.3",
46+
"@babel/preset-react": "^7.27.1",
47+
"@babel/preset-typescript": "^7.27.1",
4648
"@rollup/plugin-commonjs": "^28.0.6",
4749
"@rollup/plugin-node-resolve": "^16.0.1",
4850
"@rollup/plugin-typescript": "^12.1.4",
@@ -88,7 +90,6 @@
8890
"rollup": "^4.52.4",
8991
"sass": "^1.53.0",
9092
"storybook": "^8.0.5",
91-
"ts-jest": "^29.1.2",
9293
"typescript": "5.3.3",
9394
"vite": "^4.5.3",
9495
"vite-tsconfig-paths": "^4.3.2"

src/__tests__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('Index', () => {
55
const sortedIndex = Object.keys(index).sort((a, b) => a.localeCompare(b));
66

77
expect(sortedIndex).toEqual([
8+
'__esModule', // Synthetic default export
89
'ActionLink',
910
'ArrowLeftIcon',
1011
'ArrowRightCircleIcon',

src/components/content-presentation/icons/__tests__/Icons.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import * as Icons from '../';
44

55
describe('Icons', () => {
66
it('all icons match snapshots', () => {
7-
for (const [name, Icon] of Object.entries(Icons)) {
7+
for (const [name, Icon] of Object.entries(Icons).filter(
8+
([, Icon]) => Icon instanceof Function,
9+
)) {
810
const { container } = render(<Icon />);
911
expect(container).toMatchSnapshot(name);
1012
}

0 commit comments

Comments
 (0)