Skip to content

Commit

Permalink
Apply changes to tasks/helpers/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Jun 7, 2023
1 parent 942ad6d commit 9731413
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Components', () => {
describe('Nunjucks environment', () => {
it('renders template for each component', () => {
return Promise.all(componentNames.map((componentName) =>
expect(nunjucksEnvDefault.render(`${componentName}/template.njk`, {})).resolves
expect(nunjucksEnvDefault.render(`govuk/components/${componentName}/template.njk`, {})).resolves
))
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { callMacro } from 'govuk-frontend-helpers/nunjucks'
describe('i18n.njk', () => {
describe('govukPluralisedI18nAttributes', () => {
function callMacroUnderTest (...args) {
return callMacro('govukPluralisedI18nAttributes', 'macros/i18n.njk', ...args)
return callMacro('govukPluralisedI18nAttributes', 'govuk/macros/i18n.njk', ...args)
}

it('renders a single plural type', () => {
Expand Down
7 changes: 3 additions & 4 deletions shared/helpers/nunjucks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const nunjucks = require('nunjucks')
const { outdent } = require('outdent')

const nunjucksPaths = [
packageNameToPath('govuk-frontend', 'src/govuk'),
packageNameToPath('govuk-frontend', 'src/govuk/components')
packageNameToPath('govuk-frontend', 'src')
]

const nunjucksEnv = nunjucks.configure(nunjucksPaths, {
Expand All @@ -24,7 +23,7 @@ const nunjucksEnv = nunjucks.configure(nunjucksPaths, {
*/
function renderHTML (componentName, options, callBlock) {
const macroName = componentNameToMacroName(componentName)
const macroPath = `${componentName}/macro.njk`
const macroPath = `govuk/components/${componentName}/macro.njk`

return callMacro(macroName, macroPath, [options], callBlock)
}
Expand Down Expand Up @@ -75,7 +74,7 @@ function callMacro (macroName, macroPath, params = [], callBlock) {
* @returns {import('cheerio').CheerioAPI} Nunjucks template output
*/
function renderTemplate (context = {}, blocks = {}) {
let viewString = '{% extends "template.njk" %}'
let viewString = '{% extends "govuk/template.njk" %}'

for (const [blockName, blockContent] of Object.entries(blocks)) {
viewString += outdent`
Expand Down
2 changes: 1 addition & 1 deletion shared/tasks/components.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function generateFixture (componentDataPath, options) {
}

// Nunjucks template
const template = join(dirname(componentDataPath), 'template.njk')
const template = join(options.srcPath, dirname(componentDataPath), 'template.njk')
const componentName = basename(dirname(componentDataPath))

// Loop examples
Expand Down

0 comments on commit 9731413

Please sign in to comment.