Skip to content

Commit

Permalink
Merge pull request #1807 from alphagov/warn-import-core-overrides-wit…
Browse files Browse the repository at this point in the history
…hout-dependencies

Warn if importing core, overrides w/o dependencies
  • Loading branch information
36degrees authored May 13, 2020
2 parents 22bbe47 + 7557564 commit 387c33d
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 387c33d

Please sign in to comment.