-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throwing error messaging on node 12 being unsupported (#486)
* feat: throwing error messaging on node 12 being unsupported * revert: adding some optional chaining back in * fix: removing optional chaining from the bin file * fix: pr feedback * fix: fixes
- Loading branch information
Showing
7 changed files
with
113 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { exec } = require('child_process'); | ||
const { isSupportedNodeVersion } = require('../src/lib/nodeVersionUtils'); | ||
const pkg = require('../package.json'); | ||
|
||
describe('bin', () => { | ||
if (isSupportedNodeVersion(process.version)) { | ||
it('should show our help screen', async () => { | ||
expect.assertions(1); | ||
|
||
await new Promise(done => { | ||
exec(`node ${__dirname}/../bin/rdme`, (error, stdout) => { | ||
expect(stdout).toContain('a utlity for interacting with ReadMe'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
it('should fail with a message', async () => { | ||
expect.assertions(1); | ||
|
||
await new Promise(done => { | ||
exec(`node ${__dirname}/../bin/rdme`, (error, stdout, stderr) => { | ||
expect(stderr).toContain( | ||
`We're sorry, this release of rdme does not support Node.js v${process.version}. We support the following versions: ${pkg.engines.node}` | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { isSupportedNodeVersion, getNodeVersion } = require('../../src/lib/nodeVersionUtils'); | ||
const pkg = require('../../package.json'); | ||
const semver = require('semver'); | ||
|
||
describe('#isSupportedNodeVersion()', () => { | ||
it('should return true for a supported version of node', () => { | ||
expect(isSupportedNodeVersion('14.5.1')).toBe(true); | ||
expect(isSupportedNodeVersion('16.0.0')).toBe(true); | ||
}); | ||
|
||
it('should return false for an unsupported version of node', () => { | ||
expect(isSupportedNodeVersion('10.0.0')).toBe(false); | ||
expect(isSupportedNodeVersion('12.0.0')).toBe(false); | ||
expect(isSupportedNodeVersion('18.0.0')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('#getNodeVersion()', () => { | ||
it('should extract version that matches range in package.json', () => { | ||
const version = parseInt(getNodeVersion(), 10); | ||
const cleanedVersion = semver.valid(semver.coerce(version)); | ||
expect(semver.satisfies(cleanedVersion, pkg.engines.node)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const semver = require('semver'); | ||
const pkg = require('../../package.json'); | ||
|
||
module.exports = { | ||
/** | ||
* Determine if the current version of Node is one that we explicitly support. | ||
* | ||
*/ | ||
isSupportedNodeVersion(version) { | ||
return semver.satisfies(semver.coerce(version), pkg.engines.node); | ||
}, | ||
|
||
/** | ||
* @example 14 | ||
* @returns {String} The maximum major Node.js version specified in the package.json | ||
*/ | ||
getNodeVersion() { | ||
const { node } = pkg.engines; | ||
return Array.from(node.matchAll(/\d+/g)).pop(); | ||
}, | ||
}; |