Skip to content

Commit 8ddf3ee

Browse files
committed
prebundle dependencies
1 parent a3c9fb6 commit 8ddf3ee

File tree

10 files changed

+137
-59
lines changed

10 files changed

+137
-59
lines changed

.storybook/test-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { toMatchImageSnapshot } from 'jest-image-snapshot';
2-
import { getStoryContext, waitForPageReady } from '../dist/playwright/hooks';
2+
import { getStoryContext, waitForPageReady } from '../dist';
33
import type { TestRunnerConfig } from '../dist';
44

55
const snapshotsDir = process.env.SNAPSHOTS_DIR || '__snapshots__';

package.json

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"type": "git",
1515
"url": "https://github.com/storybookjs/test-runner"
1616
},
17-
"author": "shilman",
1817
"license": "MIT",
18+
"author": "shilman",
1919
"main": "dist/index.js",
2020
"module": "dist/index.mjs",
2121
"types": "dist/index.d.ts",
@@ -30,22 +30,48 @@
3030
],
3131
"scripts": {
3232
"build": "tsup",
33-
"build:watch": "tsup --watch",
34-
"test": "jest",
35-
"storybook": "storybook dev -p 6006",
36-
"start": "concurrently \"yarn build:watch\" \"yarn storybook -- --quiet\"",
3733
"build-storybook": "storybook build",
34+
"build:watch": "tsup --watch",
35+
"generate-dynamic-stories": "node scripts/generate-dynamic-stories.js",
36+
"prepare": "husky install",
3837
"release": "yarn build && auto shipit",
38+
"start": "concurrently \"yarn build:watch\" \"yarn storybook -- --quiet\"",
39+
"storybook": "storybook dev -p 6006",
40+
"test": "jest",
3941
"test-storybook": "node dist/test-storybook",
40-
"test-storybook:failures": "SKIP_SNAPSHOTS=true TEST_FAILURES=1 yarn test-storybook --json --failOnConsole --outputFile test-results.json",
41-
"test-storybook:no-cache": "yarn test-storybook --no-cache",
42-
"test-storybook:json": "yarn test-storybook --stories-json",
4342
"test-storybook:ci": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn build-storybook --quiet && npx serve storybook-static -l 6006\" \"wait-on tcp:6006 && yarn test-storybook\"",
44-
"test-storybook:ci-failures": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"TEST_FAILURES=1 yarn build-storybook --quiet && npx serve storybook-static -l 6006\" \"wait-on tcp:6006 && yarn test-storybook:failures\"",
4543
"test-storybook:ci-coverage": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn build-storybook --quiet && npx serve storybook-static -l 6006\" \"wait-on tcp:6006 && yarn test-storybook --coverage\"",
44+
"test-storybook:ci-failures": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"TEST_FAILURES=1 yarn build-storybook --quiet && npx serve storybook-static -l 6006\" \"wait-on tcp:6006 && yarn test-storybook:failures\"",
4645
"test-storybook:ci-json": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn build-storybook --quiet && npx serve storybook-static -l 6006\" \"wait-on tcp:6006 && SKIP_SNAPSHOTS=true yarn test-storybook:json\"",
47-
"generate-dynamic-stories": "node scripts/generate-dynamic-stories.js",
48-
"prepare": "husky install"
46+
"test-storybook:failures": "SKIP_SNAPSHOTS=true TEST_FAILURES=1 yarn test-storybook --json --failOnConsole --outputFile test-results.json",
47+
"test-storybook:json": "yarn test-storybook --stories-json",
48+
"test-storybook:no-cache": "yarn test-storybook --no-cache"
49+
},
50+
"lint-staged": {
51+
"*.{ts,js,tsx,jsx,css,md}": "prettier --write"
52+
},
53+
"dependencies": {
54+
"@babel/core": "^7.22.5",
55+
"@babel/generator": "^7.22.5",
56+
"@babel/template": "^7.22.5",
57+
"@babel/types": "^7.22.5",
58+
"@jest/types": "^29.6.3",
59+
"@storybook/core-common": "next",
60+
"@storybook/csf": "^0.1.2",
61+
"@storybook/csf-tools": "next",
62+
"@storybook/preview-api": "next",
63+
"@swc/core": "^1.3.18",
64+
"@swc/jest": "^0.2.23",
65+
"expect-playwright": "^0.8.0",
66+
"jest": "^29.6.4",
67+
"jest-circus": "^29.6.4",
68+
"jest-environment-node": "^29.6.4",
69+
"jest-junit": "^16.0.0",
70+
"jest-playwright-preset": "^4.0.0",
71+
"jest-runner": "^29.6.4",
72+
"jest-serializer-html": "^7.1.0",
73+
"jest-watch-typeahead": "^2.0.0",
74+
"playwright": "^1.14.0"
4975
},
5076
"devDependencies": {
5177
"@auto-it/released": "^11.0.1",
@@ -66,62 +92,37 @@
6692
"babel-jest": "^29.0.0",
6793
"babel-loader": "^8.1.0",
6894
"babel-plugin-istanbul": "^6.1.1",
95+
"can-bind-to-host": "^1.1.1",
96+
"commander": "^9.0.0",
6997
"concurrently": "^7.0.0",
7098
"detect-package-manager": "^3.0.1",
99+
"glob": "^10.2.2",
71100
"husky": "^8.0.0",
72101
"jest-image-snapshot": "^6.2.0",
73102
"lint-staged": "^13.0.3",
103+
"node-fetch": "^2",
104+
"pkg-up": "^5.0.0",
74105
"prettier": "^2.8.1",
75106
"react": "^17.0.1",
76107
"react-dom": "^17.0.1",
108+
"read-pkg-up": "^7.0.1",
77109
"rimraf": "^3.0.2",
78110
"semver": "^7.5.4",
79111
"storybook": "next",
112+
"tempy": "^1.0.1",
113+
"ts-dedent": "^2.0.0",
80114
"ts-jest": "^29.0.0",
81115
"tsup": "^6.5.0",
82116
"typescript": "~4.9.4",
83117
"vite": "^4.4.5",
84118
"wait-on": "^7.2.0"
85119
},
86-
"lint-staged": {
87-
"*.{ts,js,tsx,jsx,css,md}": "prettier --write"
120+
"engines": {
121+
"node": "^16.10.0 || ^18.0.0 || >=20.0.0"
88122
},
89123
"publishConfig": {
90124
"access": "public"
91125
},
92-
"dependencies": {
93-
"@babel/core": "^7.22.5",
94-
"@babel/generator": "^7.22.5",
95-
"@babel/template": "^7.22.5",
96-
"@babel/types": "^7.22.5",
97-
"@jest/types": "^29.6.3",
98-
"@storybook/core-common": "next",
99-
"@storybook/csf": "^0.1.2",
100-
"@storybook/csf-tools": "next",
101-
"@storybook/preview-api": "next",
102-
"@swc/core": "^1.3.18",
103-
"@swc/jest": "^0.2.23",
104-
"can-bind-to-host": "^1.1.1",
105-
"commander": "^9.0.0",
106-
"expect-playwright": "^0.8.0",
107-
"glob": "^10.2.2",
108-
"jest": "^29.6.4",
109-
"jest-circus": "^29.6.4",
110-
"jest-environment-node": "^29.6.4",
111-
"jest-junit": "^16.0.0",
112-
"jest-playwright-preset": "^4.0.0",
113-
"jest-runner": "^29.6.4",
114-
"jest-serializer-html": "^7.1.0",
115-
"jest-watch-typeahead": "^2.0.0",
116-
"node-fetch": "^2",
117-
"playwright": "^1.14.0",
118-
"read-pkg-up": "^7.0.1",
119-
"tempy": "^1.0.1",
120-
"ts-dedent": "^2.0.0"
121-
},
122-
"engines": {
123-
"node": "^16.10.0 || ^18.0.0 || >=20.0.0"
124-
},
125126
"auto": {
126127
"prereleaseBranches": [
127128
"next",

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/setup-page');
1+
const { setupPage } = require('../dist');
22

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

playwright/test-runner-jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { getJestConfig } = require('@storybook/test-runner');
1+
const { getJestConfig } = require('../dist');
22

33
// The default Jest configuration comes from @storybook/test-runner
44
const testRunnerConfig = getJestConfig();

playwright/transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { transformSync: swcTransform } = require('@swc/core');
2-
const { transformPlaywright } = require('../dist/playwright/transformPlaywright');
2+
const { transformPlaywright } = require('../dist');
33

44
module.exports = {
55
process(src, filename) {

src/config/jest-playwright.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path';
22
import { getProjectRoot } from '@storybook/core-common';
33
import type { Config } from '@jest/types';
44

5-
const TEST_RUNNER_PATH = process.env.STORYBOOK_TEST_RUNNER_PATH ?? '@storybook/test-runner';
5+
const getTestRunnerPath = () => process.env.STORYBOOK_TEST_RUNNER_PATH ?? '@storybook/test-runner';
66

77
/**
88
* IMPORTANT NOTE:
@@ -17,6 +17,7 @@ const TEST_RUNNER_PATH = process.env.STORYBOOK_TEST_RUNNER_PATH ?? '@storybook/t
1717
* necessary moving parts are all required within the correct path.
1818
* */
1919
const getJestPlaywrightConfig = (): Config.InitialOptions => {
20+
const TEST_RUNNER_PATH = getTestRunnerPath();
2021
const presetBasePath = path.dirname(
2122
require.resolve('jest-playwright-preset', {
2223
paths: [path.join(__dirname, '../node_modules')],
@@ -71,6 +72,7 @@ export const getJestConfig = (): Config.InitialOptions => {
7172
const reporters = STORYBOOK_JUNIT ? ['default', jestJunitPath] : ['default'];
7273

7374
const testMatch = STORYBOOK_STORIES_PATTERN?.split(';') ?? [];
75+
const TEST_RUNNER_PATH = getTestRunnerPath();
7476

7577
const config: Config.InitialOptions = {
7678
rootDir: getProjectRoot(),

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './playwright/hooks';
22
export * from './config/jest-playwright';
33
export * from './setup-page';
44
export * from './util/getTestRunnerConfig';
5+
export * from './playwright/transformPlaywright';

src/setup-page.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Page, BrowserContext } from 'playwright';
22
import readPackageUp, { NormalizedReadResult } from 'read-pkg-up';
3+
import { pkgUp } from 'pkg-up';
34
import { PrepareContext } from './playwright/hooks';
45
import { getTestRunnerConfig } from './util/getTestRunnerConfig';
56
import { readFile } from 'node:fs/promises';
@@ -61,7 +62,13 @@ export const setupPage = async (page: Page, browserContext: BrowserContext) => {
6162
await page.exposeBinding('logToPage', (_, message) => console.log(message));
6263

6364
const finalStorybookUrl = referenceURL ?? targetURL ?? '';
64-
const scriptLocation = require.resolve(path.join(__dirname, 'setup-page-script.mjs'));
65+
const testRunnerPackageLocation = await pkgUp({ cwd: __dirname });
66+
if (!testRunnerPackageLocation) throw new Error('Could not find test-runner package location');
67+
const scriptLocation = path.join(
68+
path.dirname(testRunnerPackageLocation),
69+
'dist',
70+
'setup-page-script.mjs'
71+
);
6572

6673
// read the content of setup-page-script.mjs and replace the placeholders with the actual values
6774
const content = (await readFile(scriptLocation, 'utf-8'))

tsup.config.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@ import { defineConfig } from 'tsup';
33
export default defineConfig([
44
{
55
clean: true,
6-
entry: [
7-
'./src/**/*.{js,jsx,ts,tsx}',
8-
'!./src/**/*.d.{js,jsx,ts,tsx}',
9-
'!./src/**/*test.{js,jsx,ts,tsx}',
10-
],
6+
entry: ['./src/index.ts', './src/test-storybook.ts'],
117
format: ['cjs', 'esm'],
128
splitting: false,
139
dts: true,
1410
minify: false,
1511
treeshake: false,
16-
bundle: false,
17-
esbuildOptions(options, context) {
12+
bundle: true,
13+
platform: 'node',
14+
external: ['@storybook/test-runner'],
15+
esbuildOptions(options) {
1816
options.platform = 'node';
1917
},
2018
},
19+
{
20+
entry: ['./src/setup-page-script.ts'],
21+
format: ['esm'],
22+
dts: false,
23+
bundle: false,
24+
treeshake: false,
25+
platform: 'browser',
26+
},
2127
]);

yarn.lock

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,6 +3666,7 @@ __metadata:
36663666
jest-watch-typeahead: ^2.0.0
36673667
lint-staged: ^13.0.3
36683668
node-fetch: ^2
3669+
pkg-up: ^5.0.0
36693670
playwright: ^1.14.0
36703671
prettier: ^2.8.1
36713672
react: ^17.0.1
@@ -7133,6 +7134,16 @@ __metadata:
71337134
languageName: node
71347135
linkType: hard
71357136

7137+
"find-up@npm:^6.2.0":
7138+
version: 6.3.0
7139+
resolution: "find-up@npm:6.3.0"
7140+
dependencies:
7141+
locate-path: ^7.1.0
7142+
path-exists: ^5.0.0
7143+
checksum: 9a21b7f9244a420e54c6df95b4f6fc3941efd3c3e5476f8274eb452f6a85706e7a6a90de71353ee4f091fcb4593271a6f92810a324ec542650398f928783c280
7144+
languageName: node
7145+
linkType: hard
7146+
71367147
"flow-parser@npm:0.*":
71377148
version: 0.221.0
71387149
resolution: "flow-parser@npm:0.221.0"
@@ -9340,6 +9351,15 @@ __metadata:
93409351
languageName: node
93419352
linkType: hard
93429353

9354+
"locate-path@npm:^7.1.0":
9355+
version: 7.2.0
9356+
resolution: "locate-path@npm:7.2.0"
9357+
dependencies:
9358+
p-locate: ^6.0.0
9359+
checksum: c1b653bdf29beaecb3d307dfb7c44d98a2a98a02ebe353c9ad055d1ac45d6ed4e1142563d222df9b9efebc2bcb7d4c792b507fad9e7150a04c29530b7db570f8
9360+
languageName: node
9361+
linkType: hard
9362+
93439363
"lodash.camelcase@npm:^4.3.0":
93449364
version: 4.3.0
93459365
resolution: "lodash.camelcase@npm:4.3.0"
@@ -10223,6 +10243,15 @@ __metadata:
1022310243
languageName: node
1022410244
linkType: hard
1022510245

10246+
"p-limit@npm:^4.0.0":
10247+
version: 4.0.0
10248+
resolution: "p-limit@npm:4.0.0"
10249+
dependencies:
10250+
yocto-queue: ^1.0.0
10251+
checksum: 01d9d70695187788f984226e16c903475ec6a947ee7b21948d6f597bed788e3112cc7ec2e171c1d37125057a5f45f3da21d8653e04a3a793589e12e9e80e756b
10252+
languageName: node
10253+
linkType: hard
10254+
1022610255
"p-locate@npm:^2.0.0":
1022710256
version: 2.0.0
1022810257
resolution: "p-locate@npm:2.0.0"
@@ -10259,6 +10288,15 @@ __metadata:
1025910288
languageName: node
1026010289
linkType: hard
1026110290

10291+
"p-locate@npm:^6.0.0":
10292+
version: 6.0.0
10293+
resolution: "p-locate@npm:6.0.0"
10294+
dependencies:
10295+
p-limit: ^4.0.0
10296+
checksum: 2bfe5234efa5e7a4e74b30a5479a193fdd9236f8f6b4d2f3f69e3d286d9a7d7ab0c118a2a50142efcf4e41625def635bd9332d6cbf9cc65d85eb0718c579ab38
10297+
languageName: node
10298+
linkType: hard
10299+
1026210300
"p-map@npm:^3.0.0":
1026310301
version: 3.0.0
1026410302
resolution: "p-map@npm:3.0.0"
@@ -10394,6 +10432,13 @@ __metadata:
1039410432
languageName: node
1039510433
linkType: hard
1039610434

10435+
"path-exists@npm:^5.0.0":
10436+
version: 5.0.0
10437+
resolution: "path-exists@npm:5.0.0"
10438+
checksum: 8ca842868cab09423994596eb2c5ec2a971c17d1a3cb36dbf060592c730c725cd524b9067d7d2a1e031fef9ba7bd2ac6dc5ec9fb92aa693265f7be3987045254
10439+
languageName: node
10440+
linkType: hard
10441+
1039710442
"path-is-absolute@npm:^1.0.0":
1039810443
version: 1.0.1
1039910444
resolution: "path-is-absolute@npm:1.0.1"
@@ -10572,6 +10617,15 @@ __metadata:
1057210617
languageName: node
1057310618
linkType: hard
1057410619

10620+
"pkg-up@npm:^5.0.0":
10621+
version: 5.0.0
10622+
resolution: "pkg-up@npm:5.0.0"
10623+
dependencies:
10624+
find-up: ^6.2.0
10625+
checksum: dccefcfb96f5d7b976a27038e7c065384d3068b418bcb0626b65cf77e96d9e9afab622cf207b11d79ba37501b6f933b8612edb9f904a5f8daf120f3095f249ac
10626+
languageName: node
10627+
linkType: hard
10628+
1057510629
"playwright-core@npm:1.39.0, playwright-core@npm:>=1.2.0":
1057610630
version: 1.39.0
1057710631
resolution: "playwright-core@npm:1.39.0"
@@ -13369,3 +13423,10 @@ __metadata:
1336913423
checksum: f77b3d8d00310def622123df93d4ee654fc6a0096182af8bd60679ddcdfb3474c56c6c7190817c84a2785648cdee9d721c0154eb45698c62176c322fb46fc700
1337013424
languageName: node
1337113425
linkType: hard
13426+
13427+
"yocto-queue@npm:^1.0.0":
13428+
version: 1.0.0
13429+
resolution: "yocto-queue@npm:1.0.0"
13430+
checksum: 2cac84540f65c64ccc1683c267edce396b26b1e931aa429660aefac8fbe0188167b7aee815a3c22fa59a28a58d898d1a2b1825048f834d8d629f4c2a5d443801
13431+
languageName: node
13432+
linkType: hard

0 commit comments

Comments
 (0)