Skip to content

Commit

Permalink
Add tests for new module names
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanita Barrett committed Nov 16, 2021
1 parent badd319 commit 4f85f47
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tasks/gulp/__tests__/after-build-package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 4f85f47

Please sign in to comment.