From 4da4f671de4b10d28cd0a4f0bae939ffbc244cc0 Mon Sep 17 00:00:00 2001 From: Hypnosphi Date: Sat, 17 Feb 2018 19:45:07 +0300 Subject: [PATCH] Use node-logger in addon-storyshots --- addons/storyshots/package.json | 1 + addons/storyshots/src/test-body-image-snapshot.js | 7 ++++--- .../image-snapshots/storyshots-image.runner.js | 5 +++-- examples/official-storybook/package.json | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/storyshots/package.json b/addons/storyshots/package.json index 9d212b1c389..46bac025781 100644 --- a/addons/storyshots/package.json +++ b/addons/storyshots/package.json @@ -17,6 +17,7 @@ }, "dependencies": { "@storybook/channels": "^3.4.0-alpha.8", + "@storybook/node-logger": "^3.4.0-alpha.8", "babel-runtime": "^6.26.0", "glob": "^7.1.2", "global": "^4.3.2", diff --git a/addons/storyshots/src/test-body-image-snapshot.js b/addons/storyshots/src/test-body-image-snapshot.js index f05b83464b0..9ea2a373167 100644 --- a/addons/storyshots/src/test-body-image-snapshot.js +++ b/addons/storyshots/src/test-body-image-snapshot.js @@ -1,5 +1,6 @@ import puppeteer from 'puppeteer'; import { toMatchImageSnapshot } from 'jest-image-snapshot'; +import { logger } from '@storybook/node-logger'; expect.extend({ toMatchImageSnapshot }); @@ -13,7 +14,7 @@ export const imageSnapshot = ({ const testFn = ({ context }) => { if (context.framework === 'rn') { // Skip tests since we de not support RN image snapshots. - console.error( + logger.error( "It seems you are running imageSnapshot on RN app and it's not supported. Skipping test." ); return Promise.resolve(); @@ -24,7 +25,7 @@ export const imageSnapshot = ({ const storyUrl = `/iframe.html?selectedKind=${encodedKind}&selectedStory=${encodedStoryName}`; const url = storybookUrl + storyUrl; if (!browser || !page) { - console.error( + logger.error( `Error when generating image snapshot for test ${context.kind} - ${ context.story } : It seems the headless browser is not running.` @@ -36,7 +37,7 @@ export const imageSnapshot = ({ return page .goto(url) .catch(e => { - console.error( + logger.error( `ERROR WHILE CONNECTING TO ${url}, did you start or build the storybook first ? A storybook instance should be running or a static version should be built when using image snapshot feature.`, e ); diff --git a/examples/official-storybook/image-snapshots/storyshots-image.runner.js b/examples/official-storybook/image-snapshots/storyshots-image.runner.js index 19e82c2a50f..6c2eae5a849 100644 --- a/examples/official-storybook/image-snapshots/storyshots-image.runner.js +++ b/examples/official-storybook/image-snapshots/storyshots-image.runner.js @@ -4,7 +4,8 @@ * */ import path from 'path'; import fs from 'fs'; -import initStoryshots, { imageSnapshot } from '../../../addons/storyshots/src/index'; +import initStoryshots, { imageSnapshot } from '@storybook/addon-storyshots'; +import { logger } from '@storybook/node-logger'; // Image snapshots // We do screenshots against the static build of the storybook. @@ -12,7 +13,7 @@ import initStoryshots, { imageSnapshot } from '../../../addons/storyshots/src/in const pathToStorybookStatic = path.join(__dirname, '../', 'storybook-static'); if (!fs.existsSync(pathToStorybookStatic)) { - console.error( + logger.error( 'You are running image snapshots without having the static build of storybook. Please run "yarn run build-storybook" before running tests.' ); } else { diff --git a/examples/official-storybook/package.json b/examples/official-storybook/package.json index 223cde370d8..334679c5239 100644 --- a/examples/official-storybook/package.json +++ b/examples/official-storybook/package.json @@ -25,6 +25,7 @@ "@storybook/addon-viewport": "^3.4.0-alpha.8", "@storybook/addons": "^3.4.0-alpha.8", "@storybook/components": "^3.4.0-alpha.8", + "@storybook/node-logger": "^3.4.0-alpha.8", "@storybook/react": "^3.4.0-alpha.8", "babel-jest": "^22.1.0", "enzyme": "^3.3.0",