diff --git a/change/@fluentui-react-conformance-90ba2958-fc3c-4b00-9180-740ecb0fb58e.json b/change/@fluentui-react-conformance-90ba2958-fc3c-4b00-9180-740ecb0fb58e.json new file mode 100644 index 0000000000000..e699599b11d6e --- /dev/null +++ b/change/@fluentui-react-conformance-90ba2958-fc3c-4b00-9180-740ecb0fb58e.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix paths generated in defaultErrorMessages", + "packageName": "@fluentui/react-conformance", + "email": "olfedias@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-conformance/src/defaultErrorMessages.tsx b/packages/react-conformance/src/defaultErrorMessages.tsx index 2db6cae26fced..115016b0c3940 100644 --- a/packages/react-conformance/src/defaultErrorMessages.tsx +++ b/packages/react-conformance/src/defaultErrorMessages.tsx @@ -4,6 +4,7 @@ import { EOL } from 'os'; import * as path from 'path'; import { errorMessageColors, formatArray, getErrorMessage, formatErrors } from './utils/errorMessages'; +import { getPackagePath } from './defaultTests'; /* eslint-disable @typescript-eslint/naming-convention */ @@ -362,8 +363,7 @@ export const defaultErrorMessages = { 'exported-top-level': (testInfo: IsConformantOptions, error: Error) => { const { displayName, componentPath } = testInfo; const { testErrorPath, resolveInfo } = errorMessageColors; - const rootPath = componentPath.replace(/[\\/]src[\\/].*/, ''); - const indexFile = path.join(rootPath, 'src', 'index'); + const indexFile = path.join(getPackagePath(componentPath), 'src', 'index'); const exportInfo = testInfo.useDefaultExport ? `export { default as ${displayName} } from './${displayName};` @@ -391,8 +391,7 @@ export const defaultErrorMessages = { 'has-top-level-file': (testInfo: IsConformantOptions, error: Error) => { const { displayName, componentPath } = testInfo; const { testErrorPath, resolveInfo } = errorMessageColors; - const rootPath = componentPath.replace(/[\\/]src[\\/].*/, ''); - const topLevelFile = path.join(rootPath, 'src', displayName); + const topLevelFile = path.join(getPackagePath(componentPath), 'src', displayName); // Message Description: Handles scenario where the displayName doesn't match the component's filename. // @@ -614,9 +613,7 @@ export const defaultErrorMessages = { ) => { const { componentPath, displayName } = testInfo; const { testErrorInfo, resolveInfo, testErrorPath } = errorMessageColors; - - const rootPath = componentPath.replace(/[\\/]src[\\/].*/, ''); - const indexFile = path.join(rootPath, 'src', 'index.ts'); + const indexFile = path.join(getPackagePath(componentPath), 'src', 'index.ts'); const constantValue = `export const ${exportName} = "${componentClassName}";`; diff --git a/packages/react-conformance/src/defaultTests.tsx b/packages/react-conformance/src/defaultTests.tsx index dc7606fb8094d..0a4bc81a27ee5 100644 --- a/packages/react-conformance/src/defaultTests.tsx +++ b/packages/react-conformance/src/defaultTests.tsx @@ -567,7 +567,7 @@ export const defaultTests: TestObject = { }, }; -function getPackagePath(componentPath: string) { +export function getPackagePath(componentPath: string) { // Use lastIndexOf in case anyone has all their repos under a folder called "src" (it happens) const srcIndex = componentPath.replace(/\\/g, '/').lastIndexOf('/src/'); return componentPath.slice(0, srcIndex);