diff --git a/packages/api-docs-builder/utils/parseTest.ts b/packages/api-docs-builder/utils/parseTest.ts index 14d2c70c9939cb..082eb0df2d12fe 100644 --- a/packages/api-docs-builder/utils/parseTest.ts +++ b/packages/api-docs-builder/utils/parseTest.ts @@ -3,9 +3,6 @@ import * as babel from '@babel/core'; import { readFile } from 'fs-extra'; import glob from 'fast-glob'; -const workspaceRoot = path.join(__dirname, '../../../'); -const babelConfigPath = path.join(workspaceRoot, 'babel.config.js'); - function getTestFilesNames(filepath: string) { return glob.sync( path @@ -18,15 +15,14 @@ function getTestFilesNames(filepath: string) { ); } -async function parseWithConfig(filename: string, configFilePath: string) { +async function parseWithConfig(filename: string) { const source = await readFile(filename, { encoding: 'utf8' }); const partialConfig = babel.loadPartialConfig({ - configFile: configFilePath, filename, }); if (partialConfig === null) { - throw new Error(`Could not load a babel config for ${filename} located at ${configFilePath}.`); + throw new Error(`Could not load a babel config for ${filename}.`); } return babel.parseAsync(source, partialConfig.options); @@ -139,15 +135,19 @@ export default async function parseTest(componentFilename: string): Promise = null; - // eslint-disable-next-line no-restricted-syntax - for await (const testFilename of testFilenames) { - if (descriptor === null) { - const babelParseResult = await parseWithConfig(testFilename, babelConfigPath); - if (babelParseResult === null) { - throw new Error(`Could not parse ${testFilename}.`); + try { + // eslint-disable-next-line no-restricted-syntax + for await (const testFilename of testFilenames) { + if (descriptor === null) { + const babelParseResult = await parseWithConfig(testFilename); + if (babelParseResult === null) { + throw new Error(`Could not parse ${testFilename}.`); + } + descriptor = findConformanceDescriptor(babelParseResult); } - descriptor = findConformanceDescriptor(babelParseResult); } + } catch (error) { + console.error(error); } const result: ParseResult = {