From 97314135a39a8a8346237c0a223760e3f77bd82a Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Mon, 5 Jun 2023 14:29:52 +0100 Subject: [PATCH] Apply changes to tasks/helpers/tests --- .../src/govuk/components/components.template.test.js | 2 +- .../govuk-frontend/src/govuk/macros/i18n.unit.test.mjs | 2 +- shared/helpers/nunjucks.js | 7 +++---- shared/tasks/components.mjs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/govuk-frontend/src/govuk/components/components.template.test.js b/packages/govuk-frontend/src/govuk/components/components.template.test.js index daeafb75ef..333b378ba3 100644 --- a/packages/govuk-frontend/src/govuk/components/components.template.test.js +++ b/packages/govuk-frontend/src/govuk/components/components.template.test.js @@ -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 )) }) diff --git a/packages/govuk-frontend/src/govuk/macros/i18n.unit.test.mjs b/packages/govuk-frontend/src/govuk/macros/i18n.unit.test.mjs index 0167468981..757b39ccdf 100644 --- a/packages/govuk-frontend/src/govuk/macros/i18n.unit.test.mjs +++ b/packages/govuk-frontend/src/govuk/macros/i18n.unit.test.mjs @@ -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', () => { diff --git a/shared/helpers/nunjucks.js b/shared/helpers/nunjucks.js index 650989136a..4529f85a0a 100644 --- a/shared/helpers/nunjucks.js +++ b/shared/helpers/nunjucks.js @@ -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, { @@ -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) } @@ -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` diff --git a/shared/tasks/components.mjs b/shared/tasks/components.mjs index 6a86e37596..54be979195 100644 --- a/shared/tasks/components.mjs +++ b/shared/tasks/components.mjs @@ -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