From 853e628880e7195d0a774d530c619373edbd5d19 Mon Sep 17 00:00:00 2001 From: Jason Stirnaman Date: Wed, 14 May 2025 10:57:25 -0500 Subject: [PATCH] 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. --- content/example.md | 2 +- cypress/e2e/content/example-page.cy.js | 45 ++++++++++++++++++++++++++ layouts/index.html | 13 ++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/content/example-page.cy.js diff --git a/content/example.md b/content/example.md index d484b26f8..677341bbc 100644 --- a/content/example.md +++ b/content/example.md @@ -6,7 +6,7 @@ related: - /influxdb/v2/write-data/ - /influxdb/v2/write-data/quick-start - https://influxdata.com, This is an external link -draft: true +test_only: true # Custom parameter to indicate test-only content --- 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. diff --git a/cypress/e2e/content/example-page.cy.js b/cypress/e2e/content/example-page.cy.js new file mode 100644 index 000000000..5b5a59e98 --- /dev/null +++ b/cypress/e2e/content/example-page.cy.js @@ -0,0 +1,45 @@ +/// + +describe('Example page shortcodes and JavaScript', function() { + before(function() { + // Track JavaScript errors + cy.on('uncaught:exception', (err, runnable) => { + // Log the error to the Cypress command log + cy.log(`JavaScript error: ${err.message}`); + + // Add the error to the test failure message + Cypress.failures = Cypress.failures || []; + Cypress.failures.push(err.message); + + // Return false to prevent Cypress from failing the test + // We want to continue the test and record all errors + return false; + }); + }); + + beforeEach(function() { + // Clear any stored failures before each test + Cypress.failures = []; + + // Visit the example page + cy.visit('/example/'); + }); + + it('loads without JavaScript errors', function() { + // Check if page loaded successfully + cy.title().should('not.be.empty'); + + // Verify no JavaScript errors were recorded + cy.wrap(Cypress.failures).should('be.empty', + 'The following JavaScript errors were detected:\n' + + (Cypress.failures || []).join('\n')); + }); + + it('has expected content structure', function() { + // Basic page structure checks + cy.get('h1').should('exist'); + cy.get('main').should('exist'); + }); + + // Add more specific tests for the example page content as needed +}); \ No newline at end of file diff --git a/layouts/index.html b/layouts/index.html index 62d82ec82..f46bea3a6 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -6,6 +6,13 @@ {{ $kapacitorVersion := replaceRE "v" "" .Site.Data.products.kapacitor.latest }} {{ $fluxVersion := replaceRE "v" "" .Site.Data.products.flux.latest }} + +{{ if or (not .Params.test_only) (and .Params.test_only (eq site.Params.environment "testing")) }} + {{ partial "header.html" . }} {{ partial "topnav.html" . }} @@ -264,3 +271,9 @@ {{ partial "footer.html" . }} +{{ else }} + + {{ if eq .Params.test_only true }} + {{ template "404.html" . }} + {{ end }} +{{ end }} \ No newline at end of file