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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error logging and ensure non-zero exit #201

Merged
merged 4 commits into from Oct 11, 2022
Merged
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
18 changes: 14 additions & 4 deletions bin/test-storybook.js
Expand Up @@ -9,7 +9,8 @@ const fs = require('fs');
const dedent = require('ts-dedent').default;
const path = require('path');
const tempy = require('tempy');
const { getCliOptions, getStorybookMetadata } = require('../dist/cjs/util');
const { getCliOptions } = require('../dist/cjs/util/getCliOptions');
const { getStorybookMetadata } = require('../dist/cjs/util/getStorybookMetadata');
const { transformPlaywrightJson } = require('../dist/cjs/playwright/transformPlaywrightJson');

// Do this as the first thing so that any code reading it knows the right env.
Expand All @@ -26,7 +27,13 @@ process.on('unhandledRejection', (err) => {
});

const log = (message) => console.log(`[test-storybook] ${message}`);
const error = (message) => console.error(`[test-storybook] ${message}`);
const error = (err) => {
if (err instanceof Error) {
console.error(`\x1b[31m[test-storybook]\x1b[0m ${err.message} \n\n${err.stack}`);
} else {
console.error(`\x1b[31m[test-storybook]\x1b[0m ${err}`);
}
};

// Clean up tmp files globally in case of control-c
let indexTmpDir;
Expand Down Expand Up @@ -122,7 +129,7 @@ async function checkStorybook(url) {
if (res.status !== 200) throw new Error(`Unxpected status: ${res.status}`);
} catch (e) {
console.error(
dedent`[test-storybook] It seems that your Storybook instance is not running at: ${url}. Are you sure it's running?
dedent`\x1b[31m[test-storybook]\x1b[0m It seems that your Storybook instance is not running at: ${url}. Are you sure it's running?

If you're not running Storybook on the default 6006 port or want to run the tests against any custom URL, you can pass the --url flag like so:

Expand Down Expand Up @@ -268,4 +275,7 @@ const main = async () => {
await executeJestPlaywright(jestOptions);
};

main().catch((e) => log(e));
main().catch((e) => {
error(e);
process.exit(1);
});