diff --git a/tasks/gulp/__tests__/after-build-dist.test.mjs b/tasks/gulp/__tests__/after-build-dist.test.mjs index 8993ce7749..f9ef4c4f4c 100644 --- a/tasks/gulp/__tests__/after-build-dist.test.mjs +++ b/tasks/gulp/__tests__/after-build-dist.test.mjs @@ -50,14 +50,20 @@ describe('dist/', () => { }) describe('govuk-frontend-[version].min.js', () => { + let filename let javascript beforeAll(async () => { - javascript = await readFile(join(configPaths.dist, `govuk-frontend-${pkg.version}.min.js`), 'utf8') + filename = `govuk-frontend-${pkg.version}.min.js` + javascript = await readFile(join(configPaths.dist, filename), 'utf8') }) it('should have the correct version name', () => { expect(javascript).toBeTruthy() }) + + it('should contain source mapping URL', () => { + expect(javascript).toMatch(new RegExp(`//# sourceMappingURL=${filename}.map$`)) + }) }) }) diff --git a/tasks/gulp/__tests__/after-build-package.test.mjs b/tasks/gulp/__tests__/after-build-package.test.mjs index d4ae6b697c..28b30a9a40 100644 --- a/tasks/gulp/__tests__/after-build-package.test.mjs +++ b/tasks/gulp/__tests__/after-build-package.test.mjs @@ -51,7 +51,10 @@ describe('package/', () => { const importFilter = /^govuk(?!-)/ // All source `**/*.mjs` files compiled to `**/*.js` - const output = [join(requirePath, `${name}.js`)] + const output = [ + join(requirePath, `${name}.js`), + join(requirePath, `${name}.js.map`) // with source map + ] // Only source `./govuk/**/*.mjs` files copied to `./govuk-esm/**/*.mjs` if (importFilter.test(requirePath)) { diff --git a/tasks/gulp/compile-assets.mjs b/tasks/gulp/compile-assets.mjs index 301141444f..857abf1838 100644 --- a/tasks/gulp/compile-assets.mjs +++ b/tasks/gulp/compile-assets.mjs @@ -136,8 +136,12 @@ export async function compileJavaScripts () { ? componentNameToJavaScriptModuleName(name) : 'GOVUKFrontend' - return compileJavaScript(gulp.src(slash(join(configPaths.src, file))), moduleName) - .pipe(gulp.dest(slash(join(destPath, modulePath)))) + return compileJavaScript(gulp.src(slash(join(configPaths.src, file)), { + sourcemaps: true + }), moduleName) + .pipe(gulp.dest(slash(join(destPath, modulePath)), { + sourcemaps: '.' + })) })) }