Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor: Update isCI usage to function calls across multiple files
- Changed instances of `isCI` to `isCI()` in various files to ensure consistent function usage.
- Updated related logic in `postinstall-logger.ts`, `postinstall.ts`, `withTelemetry.ts`, and others to reflect this change.
- Enhanced test coverage for `isCI` behavior in `storybook-metadata.test.ts`.
  • Loading branch information
yannbf committed Jul 31, 2025
commit e642f4e458e5fa4800c8ad3fc20e781d36809cf5
2 changes: 1 addition & 1 deletion code/addons/vitest/src/postinstall-logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isCI } from 'storybook/internal/common';
import { colors, logger } from 'storybook/internal/node-logger';

const fancy = process.platform !== 'win32' || isCI || process.env.TERM === 'xterm-256color';
const fancy = process.platform !== 'win32' || isCI() || process.env.TERM === 'xterm-256color';

export const step = colors.gray('›');
export const info = colors.blue(fancy ? 'ℹ' : 'i');
Expand Down
2 changes: 1 addition & 1 deletion code/addons/vitest/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default async function postInstall(options: PostinstallOptions) {

const hasCustomWebpackConfig = !!config.getFieldNode(['webpackFinal']);

const isInteractive = process.stdout.isTTY && !isCI;
const isInteractive = process.stdout.isTTY && !isCI();

if (info.frameworkPackageName === '@storybook/nextjs' && !hasCustomWebpackConfig) {
const out =
Expand Down
4 changes: 3 additions & 1 deletion code/core/src/common/utils/envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ export const optionalEnvToBoolean = (input: string | undefined): boolean | undef
* Doing Boolean(process.env.CI) or !process.env.CI is not enough, because users might set CI=false
* or CI=0, which would be truthy, and thus return true in those cases.
*/
export const isCI = optionalEnvToBoolean(process.env.CI);
export function isCI(): boolean | undefined {
return optionalEnvToBoolean(process.env.CI);
}
1 change: 1 addition & 0 deletions code/core/src/core-server/utils/server-address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getServerAddresses, getServerChannelUrl, getServerPort } from './server

vi.mock('node:os', () => ({
default: { release: () => '' },
platform: 'darwin',
constants: {
signals: {},
},
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/core-server/withTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type TelemetryOptions = {
};

const promptCrashReports = async () => {
if (isCI || !process.stdout.isTTY) {
if (isCI() || !process.stdout.isTTY) {
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion code/core/src/node-logger/logger/log-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LogTracker {
await fs.writeFile(filePath, logContent, 'utf-8');
this.#logs = [];

return isCI ? filePath : path.relative(process.cwd(), filePath);
return isCI() ? filePath : path.relative(process.cwd(), filePath);
}
}

Expand Down
30 changes: 28 additions & 2 deletions code/core/src/telemetry/storybook-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import path from 'node:path';
import type { MockInstance } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getStorybookInfo } from 'storybook/internal/common';
import { getStorybookInfo, isCI } from 'storybook/internal/common';
import type { PackageJson, StorybookConfig } from 'storybook/internal/types';

import { detect } from 'package-manager-detector';

import { type Settings, globalSettings } from '../cli/globalSettings';
import { getMonorepoType } from '../telemetry/get-monorepo-type';
import {
getActualPackageJson,
Expand All @@ -16,6 +17,7 @@ import {
} from './package-json';
import { computeStorybookMetadata, metaFrameworks, sanitizeAddonName } from './storybook-metadata';

vi.mock(import('../cli/globalSettings'), { spy: true });
vi.mock(import('./package-json'), { spy: true });
vi.mock(import('./get-monorepo-type'), { spy: true });
vi.mock(import('package-manager-detector'), { spy: true });
Expand Down Expand Up @@ -442,14 +444,38 @@ describe('storybook-metadata', () => {
);

it('should detect userSince info', async () => {
vi.mocked(isCI).mockImplementation(() => false);
vi.mocked(globalSettings).mockResolvedValue({
value: {
userSince: 1717334400000,
},
} as Settings);

const res = await computeStorybookMetadata({
configDir: '.storybook',
packageJson: packageJsonMock,
packageJsonPath,
mainConfig: mainJsMock,
});

expect(globalSettings).toHaveBeenCalled();

expect(res.userSince).toEqual(1717334400000);
});

it('should not detect userSince info in CI', async () => {
vi.mocked(isCI).mockImplementation(() => true);
vi.mocked(globalSettings).mockResolvedValue({} as Settings);

const res = await computeStorybookMetadata({
configDir: '.storybook',
packageJson: packageJsonMock,
packageJsonPath,
mainConfig: mainJsMock,
});

expect(res.userSince).toBeDefined();
expect(globalSettings).not.toHaveBeenCalled();
expect(res.userSince).not.toBeDefined();
});
});
});
2 changes: 1 addition & 1 deletion code/core/src/telemetry/storybook-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const computeStorybookMetadata = async ({
mainConfig?: StorybookConfig & Record<string, any>;
configDir: string;
}): Promise<StorybookMetadata> => {
const settings = isCI ? undefined : await globalSettings();
const settings = isCI() ? undefined : await globalSettings();
const metadata: Partial<StorybookMetadata> = {
generatedAt: new Date().getTime(),
userSince: settings?.value.userSince,
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getOperatingSystem = (): 'Windows' | 'macOS' | 'Linux' | `Other: ${string}
// by the app. currently:
// - cliVersion
const globalContext = {
inCI: isCI,
inCI: isCI(),
isTTY: process.stdout.isTTY,
platform: getOperatingSystem(),
nodeVersion: process.versions.node,
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli-storybook/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ command('init')
.option(
'--dev',
'Launch the development server after completing initialization. Enabled by default (default: true)',
!isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX)
!isCI() && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX)
)
.option(
'--no-dev',
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli-storybook/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const sandbox = async ({
// @ts-ignore-error (no types for this)
const { initiate } = await import('create-storybook');
await initiate({
dev: isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX),
dev: isCI() && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX),
...options,
features: ['docs', 'test'],
});
Expand Down
4 changes: 3 additions & 1 deletion code/lib/create-storybook/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ const createStorybookProgram = program

createStorybookProgram
.action(async (options) => {
const isNeitherCiNorSandbox =
!isCI() && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX);
options.debug = options.debug ?? false;
options.dev = options.dev ?? (isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX));
options.dev = options.dev ?? isNeitherCiNorSandbox;

await initiate(options as CommandOptions).catch(() => process.exit(1));
})
Expand Down
2 changes: 1 addition & 1 deletion code/lib/create-storybook/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export async function baseGenerator(
}).start();

try {
if (!isCI) {
if (!isCI()) {
const { hasEslint, isStorybookPluginInstalled, isFlatConfig, eslintConfigFile } =
// TODO: Investigate why packageManager type does not match on CI
await extractEslintInfo(packageManager as any);
Comment on lines 358 to 360
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Type casting can hide potential issues. Consider fixing the packageManager type mismatch instead

Expand Down
2 changes: 1 addition & 1 deletion code/lib/create-storybook/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export async function doInitiate(options: CommandOptions): Promise<
)
);

const isInteractive = process.stdout.isTTY && !isCI;
const isInteractive = process.stdout.isTTY && !isCI();

const settings = await globalSettings();
const promptOptions = {
Expand Down
Loading