diff --git a/scripts/bench/index.ts b/scripts/bench/index.ts deleted file mode 100644 index 95cd92527aae..000000000000 --- a/scripts/bench/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './types'; -export * from './utils'; -export { browse } from './browse'; diff --git a/scripts/bench/types.ts b/scripts/bench/types.ts index fc857f910490..2f2e0277fe9b 100644 --- a/scripts/bench/types.ts +++ b/scripts/bench/types.ts @@ -1,17 +1,61 @@ -export interface Config { - install?: string; - dev?: string; - devUrl?: string; - build?: string; - serve?: string; - serveUrl?: number; - managerLoaded?: string; - previewFrameLocator?: string; - previewLoadedText?: string; - /** - * If set, wait this amount of time (ms) after the dev server - * starts before starting the browser. Used for Histoire, which - * is incompatible with `wait-on` for some reason. - */ - waitOnTimeout?: number; +// NOTE: this must be kept in sync with ./bench.schema, which defines +// the table schema in BigQuery +export interface BenchResults { + branch: string; + commit: string; + timestamp: string; + label: string; + + /** The time it takes to create the base sandbox without storybook */ + createTime: number; + /** The time it takes to install the base sandbox after it has been initialized */ + generateTime: number; + /** The time it takes to run `sb init` on the base sandbox */ + initTime: number; + /** Size of base sandbox node_modules without storybook pre-install */ + createSize: number; + /** Size of base sandbox node_modules without storybook post-install */ + generateSize: number; + /** Size of the sandbox node_modules post `sb init` */ + initSize: number; + /** Difference bewtween `initSize` and `generateSize` */ + diffSize: number; + /** Full `sb build` time */ + buildTime: number; + /** Size of the storybook-static directory in total */ + buildSize: number; + /** Size of the storybook-static/sb-addons in total */ + buildSbAddonsSize: number; + /** Size of the storybook-static/sb-common-assets */ + buildSbCommonSize: number; + /** Size of the storybook-static/sb-manager */ + buildSbManagerSize: number; + /** Size of storybook-static/sb-preview */ + buildSbPreviewSize: number; + /** Size of the `static` directory if it exists */ + buildStaticSize: number; + /** Total size of `sb-x` above */ + buildPrebuildSize: number; + /** Total size of everything else (user's stories & components & CSS & assets etc.) */ + buildPreviewSize: number; + /** Time to wait-on iframe.html */ + devPreviewResponsive: number; + /** Time to wait-on index.html */ + devManagerResponsive: number; + /** Time to browse to index.html and view the SB logo */ + devManagerHeaderVisible: number; + /** Time to browse to index.html and load the story index */ + devManagerIndexVisible: number; + /** Time to browse to index.html and load iframe content and the story is rendered */ + devStoryVisible: number; + /** Time to browse to index.html and load iframe content and the docs page is rendered */ + devDocsVisible: number; + /** Time to browse to index.html and view the SB logo */ + buildManagerHeaderVisible: number; + /** Time to browse to index.html and load the story index */ + buildManagerIndexVisible: number; + /** Time to browse to index.html and load iframe content and the story is rendered */ + buildStoryVisible: number; + /** Time to browse to index.html and load iframe content and the docs page is rendered */ + buildDocsVisible: number; } diff --git a/scripts/bench/utils.ts b/scripts/bench/utils.ts index 6de60d7cc86a..7467a8d6dc73 100644 --- a/scripts/bench/utils.ts +++ b/scripts/bench/utils.ts @@ -1,5 +1,6 @@ import { join } from 'path'; import { ensureDir, writeJSON, readJSON } from 'fs-extra'; +import type { BenchResults } from './types'; export const now = () => new Date().getTime(); @@ -7,7 +8,7 @@ export interface SaveBenchOptions { rootDir?: string; } -export const saveBench = async (data: any, options: SaveBenchOptions) => { +export const saveBench = async (data: Partial, options: SaveBenchOptions) => { const dirname = options.rootDir || process.cwd(); const existing = await ensureDir(dirname).then(() => { return loadBench(options).catch(() => ({})); @@ -15,7 +16,7 @@ export const saveBench = async (data: any, options: SaveBenchOptions) => { await writeJSON(join(dirname, `bench.json`), { ...existing, ...data }, { spaces: 2 }); }; -export const loadBench = async (options: SaveBenchOptions) => { +export const loadBench = async (options: SaveBenchOptions): Promise> => { const dirname = options.rootDir || process.cwd(); return readJSON(join(dirname, `bench.json`)); }; diff --git a/scripts/tasks/bench.ts b/scripts/tasks/bench.ts index 96051464228c..1a0503427f9f 100644 --- a/scripts/tasks/bench.ts +++ b/scripts/tasks/bench.ts @@ -16,7 +16,8 @@ export const bench: Task = { async run(details, options) { const controllers: AbortController[] = []; try { - const { browse, saveBench, loadBench } = await import('../bench'); + const { browse } = await import('../bench/browse'); + const { saveBench, loadBench } = await import('../bench/utils'); const { default: prettyBytes } = await dynamicImport('pretty-bytes'); const { default: prettyTime } = await dynamicImport('pretty-ms'); @@ -49,7 +50,7 @@ export const bench: Task = { buildManagerHeaderVisible: buildBrowseResult.managerHeaderVisible, buildManagerIndexVisible: buildBrowseResult.managerIndexVisible, - buildPreviewVisible: buildBrowseResult.storyVisible, + buildStoryVisible: buildBrowseResult.storyVisible, buildDocsVisible: buildBrowseResult.docsVisible, }, { @@ -59,6 +60,10 @@ export const bench: Task = { const data = await loadBench({ rootDir: details.sandboxDir }); Object.entries(data).forEach(([key, value]) => { + if (typeof value !== 'number') { + return; + } + if (key.includes('Size')) { console.log(`${key}: ${prettyBytes(value)}`); } else { diff --git a/scripts/upload-bench.ts b/scripts/upload-bench.ts index d47c1ed5dd18..44bf2e2700f2 100644 --- a/scripts/upload-bench.ts +++ b/scripts/upload-bench.ts @@ -2,7 +2,8 @@ import { copy } from 'fs-extra'; import { join } from 'path'; import { BigQuery } from '@google-cloud/bigquery'; -import { loadBench } from './bench'; +import type { BenchResults } from './bench/types'; +import { loadBench } from './bench/utils'; import { SANDBOX_DIRECTORY, CODE_DIRECTORY } from './utils/constants'; import { execaCommand } from './utils/exec'; @@ -12,68 +13,6 @@ const GCP_CREDENTIALS = JSON.parse(process.env.GCP_CREDENTIALS || '{}'); const sandboxDir = process.env.SANDBOX_ROOT || SANDBOX_DIRECTORY; const templateSandboxDir = templateKey && join(sandboxDir, templateKey.replace('/', '-')); -// NOTE: this must be kept in sync with ./bench/bench.schema, which defines -// the table schema in BigQuery -export interface BenchResults { - branch: string; - commit: string; - timestamp: string; - label: string; - - /** The time it takes to create the base sandbox without storybook */ - createTime: number; - /** The time it takes to install the base sandbox after it has been initialized */ - generateTime: number; - /** The time it takes to run `sb init` on the base sandbox */ - initTime: number; - /** Size of base sandbox node_modules without storybook pre-install */ - createSize: number; - /** Size of base sandbox node_modules without storybook post-install */ - generateSize: number; - /** Size of the sandbox node_modules post `sb init` */ - initSize: number; - /** Difference bewtween `initSize` and `generateSize` */ - diffSize: number; - /** Full `sb build` time */ - buildTime: number; - /** Size of the storybook-static directory in total */ - buildSize: number; - /** Size of the storybook-static/sb-addons in total */ - buildSbAddonsSize: number; - /** Size of the storybook-static/sb-common-assets */ - buildSbCommonSize: number; - /** Size of the storybook-static/sb-manager */ - buildSbManagerSize: number; - /** Size of storybook-static/sb-preview */ - buildSbPreviewSize: number; - /** Size of the `static` directory if it exists */ - buildStaticSize: number; - /** Total size of `sb-x` above */ - buildPrebuildSize: number; - /** Total size of everything else (user's stories & components & CSS & assets etc.) */ - buildPreviewSize: number; - /** Time to wait-on iframe.html */ - devPreviewResponsive: number; - /** Time to wait-on index.html */ - devManagerResponsive: number; - /** Time to browse to index.html and view the SB logo */ - devManagerHeaderVisible: number; - /** Time to browse to index.html and load the story index */ - devManagerIndexVisible: number; - /** Time to browse to index.html and load iframe content and the story is rendered */ - devStoryVisible: number; - /** Time to browse to index.html and load iframe content and the docs page is rendered */ - devDocsVisible: number; - /** Time to browse to index.html and view the SB logo */ - buildManagerHeaderVisible: number; - /** Time to browse to index.html and load the story index */ - buildManagerIndexVisible: number; - /** Time to browse to index.html and load iframe content and the story is rendered */ - buildStoryVisible: number; - /** Time to browse to index.html and load iframe content and the docs page is rendered */ - buildDocsVisible: number; -} - const defaults: Record = { branch: null, commit: null, @@ -98,10 +37,14 @@ const defaults: Record = { buildPreviewSize: null, devPreviewResponsive: null, devManagerResponsive: null, - devManagerLoaded: null, - devPreviewLoaded: null, - buildManagerLoaded: null, - buildPreviewLoaded: null, + devManagerHeaderVisible: null, + devManagerIndexVisible: null, + devStoryVisible: null, + devDocsVisible: null, + buildManagerHeaderVisible: null, + buildManagerIndexVisible: null, + buildDocsVisible: null, + buildStoryVisible: null, }; const uploadBench = async () => {