Skip to content

Commit 853e628

Browse files
committed
chore(ci): Shortcode tests using example.md. Support test-only files (such as example.md) without abusing draft mode.
- Add a frontmatter test-only attribute for files like example.md. Don't use draft: true for these files. - Add support in index.html for the attribute so that the files are only rendered when running in the testing environment. - e2e smoke test using example.md, ensure it renders without JavaScript errors.
1 parent 03bb872 commit 853e628

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

content/example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ related:
66
- /influxdb/v2/write-data/
77
- /influxdb/v2/write-data/quick-start
88
- https://influxdata.com, This is an external link
9-
draft: true
9+
test_only: true # Custom parameter to indicate test-only content
1010
---
1111

1212
This is a paragraph. Lorem ipsum dolor ({{< icon "trash" "v2" >}}) sit amet, consectetur adipiscing elit. Nunc rutrum, metus id scelerisque euismod, erat ante suscipit nibh, ac congue enim risus id est. Etiam tristique nisi et tristique auctor. Morbi eu bibendum erat. Sed ullamcorper, dui id lobortis efficitur, mauris odio pharetra neque, vel tempor odio dolor blandit justo.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Example page shortcodes and JavaScript', function() {
4+
before(function() {
5+
// Track JavaScript errors
6+
cy.on('uncaught:exception', (err, runnable) => {
7+
// Log the error to the Cypress command log
8+
cy.log(`JavaScript error: ${err.message}`);
9+
10+
// Add the error to the test failure message
11+
Cypress.failures = Cypress.failures || [];
12+
Cypress.failures.push(err.message);
13+
14+
// Return false to prevent Cypress from failing the test
15+
// We want to continue the test and record all errors
16+
return false;
17+
});
18+
});
19+
20+
beforeEach(function() {
21+
// Clear any stored failures before each test
22+
Cypress.failures = [];
23+
24+
// Visit the example page
25+
cy.visit('/example/');
26+
});
27+
28+
it('loads without JavaScript errors', function() {
29+
// Check if page loaded successfully
30+
cy.title().should('not.be.empty');
31+
32+
// Verify no JavaScript errors were recorded
33+
cy.wrap(Cypress.failures).should('be.empty',
34+
'The following JavaScript errors were detected:\n' +
35+
(Cypress.failures || []).join('\n'));
36+
});
37+
38+
it('has expected content structure', function() {
39+
// Basic page structure checks
40+
cy.get('h1').should('exist');
41+
cy.get('main').should('exist');
42+
});
43+
44+
// Add more specific tests for the example page content as needed
45+
});

layouts/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
{{ $kapacitorVersion := replaceRE "v" "" .Site.Data.products.kapacitor.latest }}
77
{{ $fluxVersion := replaceRE "v" "" .Site.Data.products.flux.latest }}
88

9+
<!--
10+
Show the page if:
11+
- This is a regular page (not test-only) OR
12+
- This is a test-only page BUT we're currently in the testing environment
13+
-->
14+
{{ if or (not .Params.test_only) (and .Params.test_only (eq site.Params.environment "testing")) }}
15+
916
{{ partial "header.html" . }}
1017
{{ partial "topnav.html" . }}
1118

@@ -264,3 +271,9 @@ <h4>Enterprise</h4>
264271
</div>
265272
</div>
266273
{{ partial "footer.html" . }}
274+
{{ else }}
275+
<!-- Return 404 or empty template for test_only content in production -->
276+
{{ if eq .Params.test_only true }}
277+
{{ template "404.html" . }}
278+
{{ end }}
279+
{{ end }}

0 commit comments

Comments
 (0)