Skip to content

Commit

Permalink
add context to liquid rendering in linting tests (github#26055)
Browse files Browse the repository at this point in the history
* HACK

* back

* remove consolelog

* remove debugging

* remove more debugging
  • Loading branch information
peterbe authored Mar 9, 2022
1 parent fcda086 commit 5d5c3e9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/linting/lint-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import allowedVersionOperators from '../../lib/liquid-tags/ifversion-supported-o
import semver from 'semver'
import { jest } from '@jest/globals'
import { getDiffFiles } from '../helpers/diff-files.js'
import loadSiteData from '../../lib/site-data.js'

jest.useFakeTimers('legacy')

Expand Down Expand Up @@ -410,6 +411,9 @@ if (

describe('lint markdown content', () => {
if (mdToLint.length < 1) return

const siteData = loadSiteData()

describe.each(mdToLint)('%s', (markdownRelPath, markdownAbsPath) => {
let content,
ast,
Expand Down Expand Up @@ -453,12 +457,14 @@ describe('lint markdown content', () => {
}
})

const context = { site: siteData.en.site }

// visit is not async-friendly so we need to do an async map to parse the YML snippets
yamlScheduledWorkflows = (
await Promise.all(
yamlScheduledWorkflows.map(async (snippet) => {
// If we don't parse the Liquid first, yaml loading chokes on {% raw %} tags
const rendered = await renderContent.liquid.parseAndRender(snippet)
const rendered = await renderContent.liquid.parseAndRender(snippet, context)
const parsed = yaml.load(rendered)
return parsed.on.schedule
})
Expand Down Expand Up @@ -1031,6 +1037,9 @@ describe('lint GHAE release notes', () => {

describe('lint learning tracks', () => {
if (learningTracksToLint.length < 1) return

const siteData = loadSiteData()

describe.each(learningTracksToLint)('%s', (yamlRelPath, yamlAbsPath) => {
let dictionary
let dictionaryError = false
Expand Down Expand Up @@ -1066,7 +1075,7 @@ describe('lint learning tracks', () => {
const productVersions = getApplicableVersions(data.versions, productTocPath)

const featuredTracks = {}
const context = { enterpriseServerVersions }
const context = { enterpriseServerVersions, site: siteData.en.site }

// For each of the product's versions, render the learning track data and look for a featured track.
await Promise.all(
Expand Down

0 comments on commit 5d5c3e9

Please sign in to comment.