Skip to content

Commit 4b30bf5

Browse files
committed
Bundle with tsup and replace babel-jest
1 parent f2191b7 commit 4b30bf5

File tree

13 files changed

+737
-113
lines changed

13 files changed

+737
-113
lines changed

.storybook/test-runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { toMatchImageSnapshot } from 'jest-image-snapshot';
2-
import { getStoryContext } from '../dist/cjs/playwright/hooks';
3-
import type { TestRunnerConfig } from '../dist/ts';
2+
import { getStoryContext } from '../dist/playwright/hooks';
3+
import type { TestRunnerConfig } from '../dist';
44

55
const snapshotsDir = process.env.SNAPSHOTS_DIR || '__snapshots__';
66
const customSnapshotsDir = `${process.cwd()}/${snapshotsDir}`;

package.json

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
},
1717
"author": "shilman",
1818
"license": "MIT",
19-
"main": "dist/cjs/index.js",
20-
"module": "dist/esm/index.js",
21-
"types": "dist/ts/index.d.ts",
19+
"main": "dist/index.js",
20+
"module": "dist/index.mjs",
21+
"types": "dist/index.d.ts",
2222
"bin": {
23-
"test-storybook": "./bin/test-storybook.js"
23+
"test-storybook": "./dist/test-storybook.js"
2424
},
2525
"files": [
2626
"bin",
@@ -44,7 +44,7 @@
4444
"start": "concurrently \"yarn build:watch\" \"yarn storybook -- --no-manager-cache --quiet\"",
4545
"build-storybook": "storybook build",
4646
"release": "yarn build && auto shipit",
47-
"test-storybook": "node bin/test-storybook.js",
47+
"test-storybook": "node dist/test-storybook.js",
4848
"test-storybook:failures": "SKIP_SNAPSHOTS=true TEST_FAILURES=1 yarn test-storybook --json --outputFile test-results.json",
4949
"test-storybook:no-cache": "yarn test-storybook --no-cache",
5050
"test-storybook:json": "yarn test-storybook --stories-json",
@@ -57,21 +57,31 @@
5757
},
5858
"devDependencies": {
5959
"@auto-it/released": "^10.37.1",
60-
"@babel/cli": "^7.20.7",
60+
"@babel/core": "^7.20.7",
61+
"@babel/cli": "^7.12.1",
62+
"@babel/generator": "^7.18.13",
63+
"@babel/preset-env": "^7.19.4",
64+
"@babel/preset-react": "^7.18.6",
65+
"@babel/preset-typescript": "^7.18.6",
66+
"@babel/types": "^7.14.8",
67+
"@babel/template": "^7.14.5",
6168
"@jest/types": "^28.1.3",
6269
"@storybook/addon-coverage": "^0.0.7",
6370
"@storybook/addon-essentials": "next",
6471
"@storybook/addon-interactions": "next",
6572
"@storybook/jest": "next",
6673
"@storybook/react": "next",
6774
"@storybook/react-webpack5": "next",
75+
"@storybook/store": "next",
6876
"@storybook/testing-library": "next",
6977
"@types/jest": "^27.0.3",
7078
"@types/node": "^16.4.1",
7179
"auto": "^10.3.0",
7280
"babel-jest": "^28.1.3",
7381
"babel-loader": "^8.1.0",
7482
"babel-plugin-istanbul": "^6.1.1",
83+
"can-bind-to-host": "^1.1.1",
84+
"commander": "^9.0.0",
7585
"concurrently": "^7.0.0",
7686
"husky": "^8.0.0",
7787
"jest-image-snapshot": "^5.1.0",
@@ -80,9 +90,14 @@
8090
"prop-types": "^15.7.2",
8191
"react": "^17.0.1",
8292
"react-dom": "^17.0.1",
93+
"read-pkg-up": "^7.0.1",
8394
"rimraf": "^3.0.2",
95+
"semver": "^7.3.7",
8496
"storybook": "next",
97+
"tempy": "^1.0.1",
98+
"ts-dedent": "^2.0.0",
8599
"ts-jest": "^28.0.8",
100+
"tsup": "^6.5.0",
86101
"typescript": "~4.9.4",
87102
"wait-on": "^6.0.0"
88103
},
@@ -100,19 +115,11 @@
100115
"icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
101116
},
102117
"dependencies": {
103-
"@babel/core": "^7.20.7",
104-
"@babel/generator": "^7.20.7",
105-
"@babel/preset-env": "^7.20.2",
106-
"@babel/preset-react": "^7.18.6",
107-
"@babel/preset-typescript": "^7.18.6",
108-
"@babel/template": "^7.20.7",
109-
"@babel/types": "^7.20.7",
110118
"@storybook/core-common": "next",
111119
"@storybook/csf": "next",
112120
"@storybook/csf-tools": "next",
113-
"@storybook/preview-api": "next",
114-
"can-bind-to-host": "^1.1.1",
115-
"commander": "^9.0.0",
121+
"@swc/core": "^1.3.18",
122+
"@swc/jest": "^0.2.23",
116123
"expect-playwright": "^0.8.0",
117124
"glob": "^8.1.0",
118125
"jest": "^28.0.0",
@@ -125,11 +132,7 @@
125132
"jest-watch-typeahead": "^2.0.0",
126133
"node-fetch": "^2",
127134
"playwright": "^1.14.0",
128-
"read-pkg-up": "^7.0.1",
129-
"regenerator-runtime": "^0.13.9",
130-
"semver": "^7.3.7",
131-
"tempy": "^1.0.1",
132-
"ts-dedent": "^2.0.0"
135+
"regenerator-runtime": "^0.13.9"
133136
},
134137
"auto": {
135138
"prereleaseBranches": [

playwright/custom-environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { setupPage } = require('../dist/cjs/setup-page');
1+
const { setupPage } = require('../dist/setup-page');
22

33
require('regenerator-runtime/runtime');
44
const PlaywrightEnvironment = require('jest-playwright-preset/lib/PlaywrightEnvironment').default;

playwright/jest-setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { getTestRunnerConfig, setPreRender, setPostRender, setupPage } = require('../dist/cjs');
1+
const { getTestRunnerConfig, setPreRender, setPostRender, setupPage } = require('../dist');
22

33
const testRunnerConfig = getTestRunnerConfig(process.env.STORYBOOK_CONFIG_DIR);
44
if (testRunnerConfig) {

playwright/transform.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
const { transform: babelTransform } = require('@babel/core');
2-
const { transformPlaywright } = require('../dist/cjs/playwright/transformPlaywright');
1+
const { transformSync: swcTransform } = require('@swc/core');
2+
const { transformPlaywright } = require('../dist/playwright/transformPlaywright');
33

44
module.exports = {
55
process(src, filename) {
66
const csfTest = transformPlaywright(src, filename);
77

8-
const result = babelTransform(csfTest, {
8+
const result = swcTransform(csfTest, {
99
filename,
10-
babelrc: false,
11-
configFile: false,
12-
presets: [
13-
['@babel/preset-env', { targets: { node: 'current' } }],
14-
'@babel/preset-typescript',
15-
'@babel/preset-react',
16-
],
10+
module: {
11+
type: 'commonjs',
12+
},
1713
});
1814

1915
return { code: result ? result.code : src };

src/config/jest-playwright.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import path from 'path';
1515
const getJestPlaywrightConfig = () => {
1616
const presetBasePath = path.dirname(
1717
require.resolve('jest-playwright-preset', {
18-
paths: [path.join(__dirname, '../../node_modules')],
18+
paths: [path.join(__dirname, '../node_modules')],
1919
})
2020
);
2121
const expectPlaywrightPath = path.dirname(
2222
require.resolve('expect-playwright', {
23-
paths: [path.join(__dirname, '../../node_modules')],
23+
paths: [path.join(__dirname, '../node_modules')],
2424
})
2525
);
2626
return {
@@ -55,7 +55,7 @@ export const getJestConfig = () => {
5555
testMatch: STORYBOOK_STORIES_PATTERN && STORYBOOK_STORIES_PATTERN.split(';'),
5656
transform: {
5757
'^.+\\.stories\\.[jt]sx?$': '@storybook/test-runner/playwright/transform',
58-
'^.+\\.[jt]sx?$': 'babel-jest',
58+
'^.+\\.[jt]sx?$': '@swc/jest',
5959
},
6060
snapshotSerializers: ['jest-serializer-html'],
6161
testEnvironmentOptions: {

src/csf/transformCsf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export const transformCsf = (
127127
allTests,
128128
beforeEachPrefixer ? makeBeforeEach(beforeEachPrefixer) : undefined
129129
);
130+
// @ts-ignore
130131
const { code: describeCode } = generate(describe, {});
131132
result = dedent`
132133
${result}

src/playwright/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { transform as babelTransform } from '@babel/core';
1+
import { transformSync as swcTransform } from '@swc/core';
22
import { transformPlaywright } from './transformPlaywright';
33

44
export const process = (src: string, filename: string, config: any) => {
55
const csfTest = transformPlaywright(src, filename);
66

7-
const result = babelTransform(csfTest, {
7+
const result = swcTransform(csfTest, {
88
filename,
9-
babelrc: false,
10-
configFile: false,
11-
presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'],
9+
module: {
10+
type: 'commonjs',
11+
},
1212
});
1313
return result ? result.code : src;
1414
};

src/playwright/transformPlaywrightJson.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const transformPlaywrightJson = (index: Record<string, any>) => {
8686
if (stories.length) {
8787
const storyTests = stories.map((story) => makeDescribe(story.name, [makeTest(story)]));
8888
const program = t.program([makeDescribe(stories[0].title, storyTests)]);
89-
89+
// @ts-ignore
9090
const { code } = generate(program, {});
9191

9292
acc[titleId] = code;

test-runner-jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// !!! This file is used as an override to the test-runner configuration for this repo only !!!
22
// If you want to create your own override for your project, run test-storybook eject instead
33

4-
const { getJestConfig } = require('./dist/cjs');
4+
const { getJestConfig } = require('./dist');
55

66
module.exports = {
77
...getJestConfig(),
88
cacheDirectory: 'node_modules/.cache/storybook/test-runner',
99
transform: {
1010
'^.+\\.stories\\.[jt]sx?$': './playwright/transform',
11-
'^.+\\.[jt]sx?$': 'babel-jest',
11+
'^.+\\.[jt]sx?$': '@swc/jest',
1212
},
1313
globalSetup: './playwright/global-setup.js',
1414
globalTeardown: './playwright/global-teardown.js',
1515
testEnvironment: './playwright/custom-environment.js',
1616
setupFilesAfterEnv: ['./playwright/jest-setup.js'],
1717
// use local build when the package is referred
1818
moduleNameMapper: {
19-
'@storybook/test-runner': '<rootDir>/dist/cjs/index.js',
19+
'@storybook/test-runner': '<rootDir>/dist/index.js',
2020
},
2121
};

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"noImplicitAny": true,
1414
"rootDir": "./src",
1515
"skipLibCheck": true,
16-
"target": "es5",
16+
"target": "es6",
1717
"types": ["jest", "node"],
1818
"moduleResolution": "node"
1919
},

tsup.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig([
4+
{
5+
clean: true,
6+
entry: ['./src/**/!(*.{d,test}).{js,jsx,ts,tsx}'],
7+
format: ['cjs', 'esm'],
8+
dts: true,
9+
esbuildOptions(options, context) {
10+
options.platform = 'node';
11+
},
12+
},
13+
{
14+
clean: true,
15+
entry: ['bin'],
16+
format: 'cjs',
17+
esbuildOptions(options, context) {
18+
options.platform = 'node';
19+
},
20+
},
21+
]);

0 commit comments

Comments
 (0)