From 4f85f47b49bdb8313d7e448189205bc33e68b681 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Mon, 15 Nov 2021 17:08:25 +0000 Subject: [PATCH] Add tests for new module names --- .../__tests__/after-build-package.test.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tasks/gulp/__tests__/after-build-package.test.js b/tasks/gulp/__tests__/after-build-package.test.js index 99284c71da..a1b06866ab 100644 --- a/tasks/gulp/__tests__/after-build-package.test.js +++ b/tasks/gulp/__tests__/after-build-package.test.js @@ -9,11 +9,13 @@ var glob = require('glob') const configPaths = require('../../../config/paths.json') const lib = require('../../../lib/file-helper') +const { componentNameToJavaScriptModuleName } = require('../../../lib/helper-functions') const { renderSass } = require('../../../lib/jest-helpers') const readFile = util.promisify(fs.readFile) const componentNames = lib.allComponents.slice() +const componentsWithJavaScript = glob.sync(configPaths.package + 'govuk/components/' + '**/!(*.test).js') describe('package/', () => { it('should contain the expected files', () => { @@ -101,6 +103,19 @@ describe('package/', () => { }) }) + describe('all.js', () => { + it('should have correct module name', async () => { + const allJsFile = path.join(configPaths.package, 'govuk', 'all.js') + return readFile(allJsFile, 'utf8') + .then((data) => { + expect(data).toContain("typeof define === 'function' && define.amd ? define('GOVUKFrontend', ['exports'], factory)") + }) + .catch(error => { + throw error + }) + }) + }) + describe('component', () => { it.each(componentNames)('\'%s\' should have macro-options.json that contains JSON', (name) => { const filePath = path.join(configPaths.package, 'govuk', 'components', name, 'macro-options.json') @@ -127,6 +142,20 @@ describe('package/', () => { }) }) + describe('components with JavaScript', () => { + it.each(componentsWithJavaScript)('\'%s\' should have component JavaScript file with correct module name', (javaScriptFile) => { + const moduleName = componentNameToJavaScriptModuleName(path.parse(javaScriptFile).name) + + return readFile(javaScriptFile, 'utf8') + .then((data) => { + expect(data).toContain("typeof define === 'function' && define.amd ? define('" + moduleName + "', factory)") + }) + .catch(error => { + throw error + }) + }) + }) + describe('fixtures', () => { it.each(componentNames)('\'%s\' should have fixtures.json that contains JSON', (name) => { const filePath = path.join(configPaths.package, 'govuk', 'components', name, 'fixtures.json')