Skip to content

Commit ba768ff

Browse files
authored
Merge pull request #13266 from storybookjs/13262-smoke-test-manager-cache
Core: Don't use prebuilt or cached manager when running smoke test
2 parents 2f059cb + a3b646f commit ba768ff

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

lib/core/src/server/build-dev.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ const cache = Cache({
2525
});
2626

2727
const writeStats = async (name: string, stats: Stats) => {
28-
await fs.writeFile(
29-
resolvePathInStorybookCache(`public/${name}-stats.json`),
30-
JSON.stringify(stats.toJson(), null, 2),
31-
'utf8'
32-
);
28+
const filePath = resolvePathInStorybookCache(`public/${name}-stats.json`);
29+
await fs.writeFile(filePath, JSON.stringify(stats.toJson(), null, 2), 'utf8');
30+
return filePath;
3331
};
3432

3533
const getFreePort = (port: number) =>
@@ -222,12 +220,13 @@ function outputStartupInformation(options: {
222220

223221
async function outputStats(previewStats: Stats, managerStats: Stats) {
224222
if (previewStats) {
225-
await writeStats('preview', previewStats);
223+
const filePath = await writeStats('preview', previewStats);
224+
logger.info(`=> preview stats written to ${chalk.cyan(filePath)}`);
225+
}
226+
if (managerStats) {
227+
const filePath = await writeStats('manager', managerStats);
228+
logger.info(`=> manager stats written to ${chalk.cyan(filePath)}`);
226229
}
227-
await writeStats('manager', managerStats);
228-
logger.info(
229-
`stats written to => ${chalk.cyan(resolvePathInStorybookCache('public/[name].json'))}`
230-
);
231230
}
232231

233232
export async function buildDevStandalone(

lib/core/src/server/dev-server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const useProgressReporting = async (
174174
const progress = { value, message: message.charAt(0).toUpperCase() + message.slice(1) };
175175
if (message === 'building') {
176176
// arg3 undefined in webpack5
177-
const counts = arg3 && arg3.match(/(\d+)\/(\d+)/) || [];
177+
const counts = (arg3 && arg3.match(/(\d+)\/(\d+)/)) || [];
178178
const complete = parseInt(counts[1], 10);
179179
const total = parseInt(counts[2], 10);
180180
if (!Number.isNaN(complete) && !Number.isNaN(total)) {
@@ -240,7 +240,7 @@ const startManager = async ({
240240
logConfig('Manager webpack config', managerConfig);
241241
}
242242

243-
if (options.cache) {
243+
if (options.cache && !options.smokeTest) {
244244
if (options.managerCache) {
245245
const [useCache, hasOutput] = await Promise.all([
246246
// must run even if outputDir doesn't exist, otherwise the 2nd run won't use cache
@@ -258,7 +258,7 @@ const startManager = async ({
258258
}
259259

260260
if (!managerConfig) {
261-
return { managerStats: {}, managerTotalTime: [0, 0] } as ManagerResult;
261+
return { managerStats: null, managerTotalTime: [0, 0] } as ManagerResult;
262262
}
263263

264264
const compiler = webpack(managerConfig);
@@ -311,7 +311,7 @@ const startPreview = async ({
311311
outputDir,
312312
}: any): Promise<PreviewResult> => {
313313
if (options.ignorePreview) {
314-
return { previewStats: {}, previewTotalTime: [0, 0] } as PreviewResult;
314+
return { previewStats: null, previewTotalTime: [0, 0] } as PreviewResult;
315315
}
316316

317317
const previewConfig = await loadConfig({

lib/core/src/server/utils/prebuilt-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export const getPrebuiltDir = async ({
2222
options,
2323
}: {
2424
configDir: string;
25-
options: { managerCache?: boolean };
25+
options: { managerCache?: boolean; smokeTest?: boolean };
2626
}): Promise<string | false> => {
27-
if (options.managerCache === false) return false;
27+
if (options.managerCache === false || options.smokeTest) return false;
2828

2929
const prebuiltDir = path.join(__dirname, '../../../prebuilt');
3030
const hasPrebuiltManager = await pathExists(path.join(prebuiltDir, 'index.html'));

0 commit comments

Comments
 (0)