Skip to content

Commit

Permalink
test(detectFlowVersion): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Apr 11, 2019
1 parent 66ba65f commit 42dce6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/util/version.js
Expand Up @@ -48,7 +48,8 @@ function getReactVersionFromContext(context) {

function detectFlowVersion() {
try {
const flowPackageJson = require('flow-bin/package.json');
const flowPackageJsonPath = resolve.sync('flow-bin/package.json', {basedir: process.cwd()});
const flowPackageJson = require(flowPackageJsonPath);
return flowPackageJson.version;
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
Expand Down

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

11 changes: 10 additions & 1 deletion tests/util/version.js
Expand Up @@ -26,12 +26,13 @@ describe('Version', () => {
});

describe('Detect version', () => {
const context = {settings: {react: {version: 'detect'}}};
const context = {settings: {react: {version: 'detect', flowVersion: 'detect'}}};

it('matches detected version', () => {
process.chdir('detect-version');
assert.equal(versionUtil.testReactVersion(context, '1.2.3'), true);
assert.equal(versionUtil.testReactVersion(context, '1.2.4'), false);
assert.equal(versionUtil.testFlowVersion(context, '0.92.0'), true);
});

it('assumes latest version if react is not installed', () => {
Expand All @@ -41,6 +42,14 @@ describe('Version', () => {
['Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.']
];
});

it('assumes latest version if flow-bin is not installed', () => {
assert.equal(versionUtil.testFlowVersion(context, '999.999.999'), true);

expectedErrorArgs = [
['Warning: Flow version was set to "detect" in eslint-plugin-react settings, but the "flow-bin" package is not installed. Assuming latest Flow version for linting.']
];
});
});

describe('string version', () => {
Expand Down

0 comments on commit 42dce6f

Please sign in to comment.