From 9c3a433b3176e895a23cf0f4b87411b44e264397 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 25 Sep 2023 09:11:06 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- storybook/config/addons/gitlab_api_access/manager.js | 20 +++++++++++++------- storybook/config/webpack.config.js | 19 ++++++++++++++++++- storybook/fixture_stub.js | 12 ++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 storybook/fixture_stub.js (limited to 'storybook') diff --git a/storybook/config/addons/gitlab_api_access/manager.js b/storybook/config/addons/gitlab_api_access/manager.js index 77d97c76ee2..55e7bcb9c4c 100644 --- a/storybook/config/addons/gitlab_api_access/manager.js +++ b/storybook/config/addons/gitlab_api_access/manager.js @@ -41,29 +41,35 @@ const GitLabAPIParametersPanel = () => { channel.emit(GITLAB_API_ACCESS_UPDATE_EVENT, state); - return h('div', {}, [ - h(Form.Field, { label: 'GitLab URL' }, [ + return h( + 'div', + {}, + h( + Form.Field, + { label: 'GitLab URL' }, h(Form.Input, { type: 'text', value: state.gitlabURL, placeholder: 'https://gitlab.com', onChange: (e) => updateGitLabURL(e), }), - ]), - h(Form.Field, { label: 'GitLab access token' }, [ + ), + h( + Form.Field, + { label: 'GitLab access token' }, h(Form.Input, { type: 'password', value: state.accessToken, onChange: (e) => updateAccessToken(e), }), - ]), - ]); + ), + ); }; addons.register(ADDON_ID, () => { addons.add(PANEL_ID, { type: types.PANEL, title: 'GitLab API Access', - render: ({ active, key }) => h(AddonPanel, { active, key }, [h(GitLabAPIParametersPanel)]), + render: ({ active, key }) => h(AddonPanel, { active, key }, h(GitLabAPIParametersPanel)), }); }); diff --git a/storybook/config/webpack.config.js b/storybook/config/webpack.config.js index d447211cbd8..cd2e4889300 100644 --- a/storybook/config/webpack.config.js +++ b/storybook/config/webpack.config.js @@ -1,10 +1,11 @@ /* eslint-disable no-param-reassign */ -const { statSync } = require('fs'); +const { statSync, existsSync } = require('fs'); const path = require('path'); const glob = require('glob'); const sass = require('sass'); const webpack = require('webpack'); +const { red } = require('chalk'); const IS_EE = require('../../config/helpers/is_ee_env'); const IS_JH = require('../../config/helpers/is_jh_env'); const gitlabWebpackConfig = require('../../config/webpack.config'); @@ -183,5 +184,21 @@ module.exports = function storybookWebpackConfig({ config }) { // By deleting the alias, imports of this path will resolve as expected. delete config.resolve.alias['@gitlab/svgs/dist/icons.svg']; + // Fail soft if a story requires a fixture, and the fixture file is absent. + // Without this, webpack fails at build phase, with a hard to read error. + // This rewrite rule pushes the error to be runtime. + config.plugins.push( + new webpack.NormalModuleReplacementPlugin(/^test_fixtures/, (resource) => { + const filename = resource.request.replace( + /^test_fixtures/, + config.resolve.alias.test_fixtures, + ); + if (!existsSync(filename)) { + console.error(red(`\nFixture '${filename}' wasn't found.\n`)); + resource.request = path.join(ROOT, 'storybook', 'fixture_stub.js'); + } + }), + ); + return config; }; diff --git a/storybook/fixture_stub.js b/storybook/fixture_stub.js new file mode 100644 index 00000000000..cd23e038e35 --- /dev/null +++ b/storybook/fixture_stub.js @@ -0,0 +1,12 @@ +/** + * This file is used as a substitute for absent fixture files. See fixture docs + * for how to generate or download them: + * https://docs.gitlab.com/ee/development/testing_guide/frontend_testing.html#frontend-test-fixtures + */ + +console.error( + // eslint-disable-next-line no-restricted-syntax + 'Some fixture files could not be found. Generate fixtures or download them. See docs for more: https://docs.gitlab.com/ee/development/testing_guide/frontend_testing.html#frontend-test-fixtures', +); + +export default null; -- cgit v1.2.3