Skip to content

Commit 97df479

Browse files
fixing jsx checking and adding in test
1 parent a7e5e21 commit 97df479

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

scripts/prebuild/mdx-transforms/build-mdx-transforms.test.mjs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,5 +1396,69 @@ Common documentation.
13961396
expect(output).toContain('Common documentation')
13971397
expect(output).not.toContain('@include')
13981398
})
1399+
1400+
test('should remove TFEnterprise:only block with JSX/MDX element partial (Note component)', async () => {
1401+
// Clear any existing mocks to use real PRODUCT_CONFIG
1402+
vi.restoreAllMocks()
1403+
1404+
// Real terraform-docs-common has versionedDocs: false, so no version directories
1405+
const mockVersionMetadata = {
1406+
'terraform-docs-common': [
1407+
{ version: 'v0.0.x', releaseStage: 'stable', isLatest: true },
1408+
],
1409+
}
1410+
1411+
// Partial containing MDX/JSX element (Note component) - matches beta/explorer.mdx
1412+
const partialContent = `<Note>
1413+
1414+
This feature is in beta. We recommend only using it non-production environments because updates during the beta phase may require you to destroy the explorer database. Running the explorer may increase the load on the Terraform Enterprise server in unexpected ways, resulting in slowdowns or outages.
1415+
1416+
Explorer on Terraform Enterprise only has access to the information available in the runs from Terraform Enterprise 1.0.0 and later.
1417+
You can provide feedback on this feature by selecting **Give Feedback** from the **Actions** menu or by contacting your account team.
1418+
1419+
</Note>
1420+
`
1421+
1422+
const mainContent = `---
1423+
page_title: HCP Terraform explorer for workspace visibility
1424+
description: >-
1425+
Learn how to find data about your resource, module, and provider usage across
1426+
workspaces and projects in HCP Terraform with the explorer for workspace
1427+
visibility.
1428+
---
1429+
# Explorer for workspace visibility
1430+
1431+
<!-- BEGIN: TFEnterprise:only name:explorer -->
1432+
@include 'beta/explorer.mdx'
1433+
<!-- END: TFEnterprise:only name:explorer -->
1434+
1435+
As your organization grows, keeping track of your sprawling infrastructure estate can get increasingly more complicated. The explorer for workspace visibility helps surface a wide range of valuable information from across your organization.
1436+
`
1437+
1438+
vol.fromJSON({
1439+
'/content/terraform-docs-common/docs/cloud-docs/workspaces/explorer.mdx':
1440+
mainContent,
1441+
'/content/terraform-docs-common/docs/partials/beta/explorer.mdx':
1442+
partialContent,
1443+
})
1444+
1445+
await buildMdxTransforms('/content', '/output', mockVersionMetadata)
1446+
1447+
const output = fs.readFileSync(
1448+
'/output/terraform-docs-common/docs/cloud-docs/workspaces/explorer.mdx',
1449+
'utf8',
1450+
)
1451+
1452+
// TFEnterprise:only content should be completely removed in terraform-docs-common
1453+
expect(output).not.toContain('<Note>')
1454+
expect(output).not.toContain('</Note>')
1455+
expect(output).not.toContain('This feature is in beta')
1456+
expect(output).not.toContain('Explorer on Terraform Enterprise')
1457+
expect(output).not.toContain('TFEnterprise:only')
1458+
1459+
// Content after the block should be preserved
1460+
expect(output).toContain('As your organization grows')
1461+
expect(output).toContain('infrastructure estate')
1462+
})
13991463
})
14001464
})

scripts/prebuild/mdx-transforms/exclude-content/ast-utils.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ const END_RE = /^(\s+)?<!--\s+END:\s+(?<block>.*?)\s+-->(\s+)?$/
1212
// Helper to check if a node is a comment node (jsx, html, or code containing HTML comment)
1313
// Remark sometimes parses indented HTML comments as code nodes instead of jsx nodes
1414
function isCommentNode(node) {
15-
if (node.type === 'jsx' || node.type === 'html') {
16-
return true
17-
}
1815
// Check if it's a code node containing an HTML comment
19-
if (node.type === 'code' && node.value) {
16+
if (
17+
(node.type === 'code' && node.value) ||
18+
node.type === 'jsx' ||
19+
node.type === 'html'
20+
) {
2021
return (
2122
node.value.trim().startsWith('<!--') && node.value.trim().endsWith('-->')
2223
)

0 commit comments

Comments
 (0)