Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Don't use prebuilt or cached manager when running smoke test #13266

Merged
merged 2 commits into from Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/core/src/server/build-dev.ts
Expand Up @@ -25,11 +25,9 @@ const cache = Cache({
});

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

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

async function outputStats(previewStats: Stats, managerStats: Stats) {
if (previewStats) {
await writeStats('preview', previewStats);
const filePath = await writeStats('preview', previewStats);
logger.info(`=> preview stats written to ${chalk.cyan(filePath)}`);
}
if (managerStats) {
const filePath = await writeStats('manager', managerStats);
logger.info(`=> manager stats written to ${chalk.cyan(filePath)}`);
}
await writeStats('manager', managerStats);
logger.info(
`stats written to => ${chalk.cyan(resolvePathInStorybookCache('public/[name].json'))}`
);
}

export async function buildDevStandalone(
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/server/dev-server.ts
Expand Up @@ -174,7 +174,7 @@ const useProgressReporting = async (
const progress = { value, message: message.charAt(0).toUpperCase() + message.slice(1) };
if (message === 'building') {
// arg3 undefined in webpack5
const counts = arg3 && arg3.match(/(\d+)\/(\d+)/) || [];
const counts = (arg3 && arg3.match(/(\d+)\/(\d+)/)) || [];
const complete = parseInt(counts[1], 10);
const total = parseInt(counts[2], 10);
if (!Number.isNaN(complete) && !Number.isNaN(total)) {
Expand Down Expand Up @@ -240,7 +240,7 @@ const startManager = async ({
logConfig('Manager webpack config', managerConfig);
}

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

if (!managerConfig) {
return { managerStats: {}, managerTotalTime: [0, 0] } as ManagerResult;
return { managerStats: null, managerTotalTime: [0, 0] } as ManagerResult;
}

const compiler = webpack(managerConfig);
Expand Down Expand Up @@ -311,7 +311,7 @@ const startPreview = async ({
outputDir,
}: any): Promise<PreviewResult> => {
if (options.ignorePreview) {
return { previewStats: {}, previewTotalTime: [0, 0] } as PreviewResult;
return { previewStats: null, previewTotalTime: [0, 0] } as PreviewResult;
}

const previewConfig = await loadConfig({
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/server/utils/prebuilt-manager.ts
Expand Up @@ -22,9 +22,9 @@ export const getPrebuiltDir = async ({
options,
}: {
configDir: string;
options: { managerCache?: boolean };
options: { managerCache?: boolean; smokeTest?: boolean };
}): Promise<string | false> => {
if (options.managerCache === false) return false;
if (options.managerCache === false || options.smokeTest) return false;

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