Skip to content

Commit 65981b3

Browse files
Configure Babel with Browserslist
1 parent 7ba85fb commit 65981b3

File tree

7 files changed

+1495
-89
lines changed

7 files changed

+1495
-89
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { NODE_ENV } = process.env;
2+
3+
module.exports = {
4+
browserslistEnv: 'javascripts',
5+
presets: [
6+
[
7+
'@babel/preset-env',
8+
{
9+
// Apply bug fixes to avoid transforms
10+
bugfixes: true,
11+
12+
// Apply smaller "loose" transforms for browsers
13+
loose: true,
14+
15+
// Apply ES module transforms for Jest
16+
// https://jestjs.io/docs/ecmascript-modules
17+
modules: NODE_ENV === 'test' ? 'auto' : false,
18+
},
19+
],
20+
[
21+
'@babel/preset-react',
22+
{
23+
development: NODE_ENV === 'development',
24+
useBuiltIns: true,
25+
},
26+
],
27+
'@babel/preset-typescript',
28+
],
29+
env: {
30+
test: {
31+
browserslistEnv: 'node',
32+
},
33+
},
34+
};

jest.config.js

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

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",
@@ -89,7 +91,6 @@
8991
"rollup-plugin-preserve-directives": "^0.4.0",
9092
"sass": "^1.53.0",
9193
"storybook": "^8.0.5",
92-
"ts-jest": "^29.1.2",
9394
"typescript": "5.3.3",
9495
"vite": "^4.5.3",
9596
"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)