Skip to content

Commit

Permalink
Warn if importing core, overrides w/o dependencies
Browse files Browse the repository at this point in the history
Add deprecation warnings if users import files from the core and overrides layers without first importing the settings, helpers and tools layers.

We'll remove the imports of "base" from files in these layers in 4.0[1], so this will no longer work.

[1]: #1800
  • Loading branch information
36degrees committed May 12, 2020
1 parent 22bbe47 commit 7557564
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/govuk/core/_global-styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the core layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@import "links";
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/core/_links.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the core layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/core/links") {
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/core/_lists.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the core layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/core/lists") {
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/core/_section-break.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the core layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/core/section-break") {
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/core/_template.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the core layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/core/template") {
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/core/_typography.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the core layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/core/typography") {
Expand Down
24 changes: 22 additions & 2 deletions src/govuk/core/core.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
/* eslint-env jest */

const sass = require('node-sass')

const glob = require('glob')
const { renderSass } = require('../../../lib/jest-helpers')
const configPaths = require('../../../config/paths.json')

const sassFiles = glob.sync(`${configPaths.src}/core/**/*.scss`)

it.each(sassFiles)('%s renders to CSS without errors', (file) => {
return renderSass({ file: file })
it.each(sassFiles)('%s renders with a deprecation warning', (file) => {
// Create a mock warn function that we can use to override the native @warn
// function, that we can make assertions about post-render.
const mockWarnFunction = jest.fn()
.mockReturnValue(sass.NULL)

return renderSass({
file: file,
functions: {
'@warn': mockWarnFunction
}
}).then(() => {
// Expect our mocked @warn function to have been called once with a single
// argument, which should be the deprecation notice
return expect(mockWarnFunction.mock.calls[0][0].getValue())
.toEqual(
'Importing items from the core layer without first importing `base` ' +
'is deprecated, and will no longer work as of GOV.UK Frontend v4.0.'
)
})
})
4 changes: 4 additions & 0 deletions src/govuk/overrides/_display.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the overrides layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/overrides/display") {
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/overrides/_spacing.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the overrides layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

////
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/overrides/_typography.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the overrides layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/overrides/typography") {
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/overrides/_width.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@if not mixin-exists("govuk-exports") {
@warn "Importing items from the overrides layer without first importing `base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.";
}

@import "../base";

@include govuk-exports("govuk/overrides/width") {
Expand Down
24 changes: 22 additions & 2 deletions src/govuk/overrides/overrides.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
/* eslint-env jest */

const sass = require('node-sass')

const glob = require('glob')
const { renderSass } = require('../../../lib/jest-helpers')
const configPaths = require('../../../config/paths.json')

const sassFiles = glob.sync(`${configPaths.src}/overrides/**/*.scss`)

it.each(sassFiles)('%s renders to CSS without errors', (file) => {
return renderSass({ file: file })
it.each(sassFiles)('%s renders with a deprecation warning', (file) => {
// Create a mock warn function that we can use to override the native @warn
// function, that we can make assertions about post-render.
const mockWarnFunction = jest.fn()
.mockReturnValue(sass.NULL)

return renderSass({
file: file,
functions: {
'@warn': mockWarnFunction
}
}).then(() => {
// Expect our mocked @warn function to have been called once with a single
// argument, which should be the deprecation notice
return expect(mockWarnFunction.mock.calls[0][0].getValue())
.toEqual(
'Importing items from the overrides layer without first importing ' +
'`base` is deprecated, and will no longer work as of GOV.UK Frontend v4.0.'
)
})
})

0 comments on commit 7557564

Please sign in to comment.