From 751f06ee064c953f9683fc4f0cb7b40f5e318fe2 Mon Sep 17 00:00:00 2001 From: Vanita Barrett Date: Mon, 15 Nov 2021 17:08:25 +0000 Subject: [PATCH] WIP add tests --- tasks/gulp/__tests__/after-build-package.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tasks/gulp/__tests__/after-build-package.test.js b/tasks/gulp/__tests__/after-build-package.test.js index 99284c71da..bb55d62759 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 helperFunctions = 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', () => { @@ -127,6 +129,20 @@ describe('package/', () => { }) }) + describe('components with JavaScript', () => { + it.each(componentsWithJavaScript)('\'%s\' should have component JavaScript file with correct module name', (javaScriptFile) => { + let moduleName = helperFunctions.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')