Skip to content

Commit

Permalink
Polyfill process.exitCode for Node.js < v20
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Nov 2, 2023
1 parent 6f80560 commit b28ffe1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (process.argv.indexOf('--suppress-node-version-warning') === -1 || (process.a
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 v18 and v20.' + additionalText + '\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) {
Expand Down
13 changes: 12 additions & 1 deletion lib/plugins/plugin-validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +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: [],
exitCodeSetterSpy
exitCodeSetterSpy,
originalExitCode
}
jest.spyOn(console, 'log').mockImplementation((message, ...args) => {
if (args.length > 0) {
Expand All @@ -42,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 Down

0 comments on commit b28ffe1

Please sign in to comment.