From 7f98fa7cb7ebe8492d1901fc43c3ad3027bc41ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jenifer=20L=C3=B3pez?= Date: Thu, 6 Jun 2024 09:57:11 +0200 Subject: [PATCH 1/3] feat(packages/sui-studio): Add jest compatibility with test path on studio-dev --- packages/sui-studio/bin/sui-studio-dev.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/sui-studio/bin/sui-studio-dev.js b/packages/sui-studio/bin/sui-studio-dev.js index 77707b047..e055c524d 100755 --- a/packages/sui-studio/bin/sui-studio-dev.js +++ b/packages/sui-studio/bin/sui-studio-dev.js @@ -45,8 +45,10 @@ if (!category || !component) { const componentPath = path.join(PWD, 'components', category, component) const legacyTestPath = path.join(PWD, 'test', category, component) +const jestPath = path.join(componentPath, '__tests__') const testPath = fs.existsSync(legacyTestPath) ? legacyTestPath : path.join(componentPath, 'test') +const isJestTest = fs.existsSync(jestPath) const {cache, ...others} = config @@ -59,7 +61,7 @@ const studioDevConfig = { alias: { ...config.resolve.alias, component: path.join(componentPath, 'src'), - test: testPath, + test: isJestTest ? jestPath : testPath, package: path.join(componentPath, 'package.json'), demo: path.join(componentPath, 'demo') } From 04ba88f6b2fb44eda407f6db6ee39314bbb15a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jenifer=20L=C3=B3pez?= Date: Fri, 7 Jun 2024 13:21:55 +0200 Subject: [PATCH 2/3] feat(packages/sui-studio): Disable Test component if detect jest folder --- packages/sui-studio/bin/sui-studio-dev.js | 5 +++- .../workbench/src/components/Root/index.js | 28 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/sui-studio/bin/sui-studio-dev.js b/packages/sui-studio/bin/sui-studio-dev.js index e055c524d..2f2dfc6fd 100755 --- a/packages/sui-studio/bin/sui-studio-dev.js +++ b/packages/sui-studio/bin/sui-studio-dev.js @@ -55,7 +55,10 @@ const {cache, ...others} = config const studioDevConfig = { ...others, context: path.join(__dirname, '..', 'workbench', 'src'), - plugins: [...config.plugins, new webpack.DefinePlugin({__COMPONENT_ID__: JSON.stringify(componentID)})], + plugins: [ + ...config.plugins, + new webpack.DefinePlugin({__COMPONENT_ID__: JSON.stringify(componentID), __DISABLE_TESTS__: isJestTest}) + ], resolve: { ...config.resolve, alias: { diff --git a/packages/sui-studio/workbench/src/components/Root/index.js b/packages/sui-studio/workbench/src/components/Root/index.js index e2b09aea6..e2397341b 100644 --- a/packages/sui-studio/workbench/src/components/Root/index.js +++ b/packages/sui-studio/workbench/src/components/Root/index.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ import {useState} from 'react' import PropTypes from 'prop-types' @@ -7,7 +8,10 @@ import Select from '../Select/index' import Test from '../Suite/index' const importComponent = () => import('component/index') -const importTest = () => import('test/index.test') +let importTest = null +if (!__DISABLE_TESTS__) { + importTest = () => import('test/index.test') +} const getFromStorage = (key, defaultValue) => window.sessionStorage[key] || defaultValue @@ -38,19 +42,23 @@ export default function Root({componentID, contexts = {}, themes}) { initValue={actualStyle} onChange={updateOnChange(setActualStyle, 'actualStyle')} /> - + {importTest ? ( + + ) : null}