Skip to content

Commit

Permalink
Merge pull request #2363 from alphagov/test-node-20
Browse files Browse the repository at this point in the history
Support for the new Node LTS (version 20)
  • Loading branch information
BenSurgisonGDS authored Nov 3, 2023
2 parents 3da894c + b28ffe1 commit a3e4c96
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-acceptance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false # continue other tests if one test in matrix fails
matrix:
node-version: [18.x]
node-version: [20.x]
os: [macos-latest, windows-latest, ubuntu-latest]
type: [smoke, plugins, styles, dev, prod, errors]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-heroku.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: '18'
node-version: '20'
- name: Cache Cypress binary
uses: actions/cache@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false # continue other tests if one test in matrix fails
matrix:
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
os: [macos-latest, windows-latest, ubuntu-latest]

name: Test kit on Node v${{ matrix.node-version }} (${{ matrix.os }})
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/*
lts/iron
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### New features

- [#2363: Support for the new Node LTS (version 20)](https://github.com/alphagov/govuk-prototype-kit/pull/2363)

## 13.13.6

### Fixes
Expand Down
8 changes: 4 additions & 4 deletions bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

if (process.argv.indexOf('--suppress-node-version-warning') === -1 || (process.argv[2] === 'migrate' && process.argv[3] === '--')) {
const majorNodeVersion = parseInt(process.version.split('.')[0].substring(1), 10)
const versionIsWithinRecommendation = majorNodeVersion === 18 || majorNodeVersion === 16
const versionIsWithinRecommendation = [16, 18, 20].includes(majorNodeVersion)
if (!versionIsWithinRecommendation) {
const nodeVersionIsTooOldToUse = majorNodeVersion < 14
const updateOrDownload = majorNodeVersion < 18 ? 'update to' : 'download'
const updateOrDownload = majorNodeVersion < 20 ? 'update to' : 'download'
const printLn = nodeVersionIsTooOldToUse ? console.error.bind(console) : console.warn.bind(console)
const additionalText = nodeVersionIsTooOldToUse ? '' : ' Some features may not work with your version.'

printLn('\nYou\'re using Node', process.version)
printLn('The GOV.UK Prototype Kit only supports Node v16 and v18.' + additionalText + '\n')
printLn('You can', updateOrDownload, 'Node v18 at https://nodejs.org/en/download\n')
printLn('The GOV.UK Prototype Kit only supports Node v16, v18 and v20.' + additionalText + '\n')
printLn('You can', updateOrDownload, 'Node v20 at https://nodejs.org/en/download\n')

if (nodeVersionIsTooOldToUse) {
process.exit(0)
Expand Down
16 changes: 15 additions & 1 deletion lib/plugins/plugin-validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@ describe('plugin-validator', () => {
const validSuccessMessages = phaseOneSuccessMessages.concat([ansiColors.green('The plugin config is valid.')])

beforeEach(() => {
// Polyfill process.exitCode property for Node.js < v20
const originalExitCode = process.exitCode
if (!process.exitCode) {
Object.defineProperty(process, 'exitCode', {
get: jest.fn(),
set: jest.fn()
})
}
const mockFileSystemRoot = path.join(process.cwd(), 'example-plugin')
const exitCodeSetterSpy = jest.spyOn(process, 'exitCode', 'set').mockImplementation(() => {})
testScope = {
mockFileSystemRoot,
fileSystem: mockFileSystem(mockFileSystemRoot),
stdLogs: [],
errLogs: []
errLogs: [],
exitCodeSetterSpy,
originalExitCode
}
jest.spyOn(console, 'log').mockImplementation((message, ...args) => {
if (args.length > 0) {
Expand All @@ -40,6 +51,8 @@ describe('plugin-validator', () => {

afterEach(() => {
jest.clearAllMocks()
// Reset polyfill process.exitCode property for Node.js < v20
process.exitCode = testScope.originalExitCode
})

describe('unexpected keys', () => {
Expand All @@ -50,6 +63,7 @@ describe('plugin-validator', () => {
await validatePlugin(testScope.mockFileSystemRoot)
expect(testScope.errLogs).toEqual([ansiColors.red('Error: The following invalid keys exist in your config: myExample')])
expect(testScope.stdLogs).toEqual(phaseOneSuccessMessages)
expect(testScope.exitCodeSetterSpy).toHaveBeenCalledWith(100)
})
it('should allow a single unknown key when specified', async () => {
testScope.fileSystem.writeFile(['govuk-prototype-kit.config.json'], JSON.stringify({
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Rapidly create HTML prototypes of GOV.UK services",
"version": "13.13.6",
"engines": {
"node": "^16.x || >= 18.x"
"node": "^16.x || ^18.x || >= 20.x"
},
"main": "index.js",
"bin": {
Expand Down

0 comments on commit a3e4c96

Please sign in to comment.