Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
fix(cli): Use latest version when stable unavailable (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored and francoischalifour committed Jun 15, 2018
1 parent 3bca8bc commit e764cd5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ yarn-error.log*

# release
/build
/sample
20 changes: 20 additions & 0 deletions src/cli/__tests__/getConfiguration.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const path = require('path');
const utils = require('../../utils');
const getConfiguration = require('../getConfiguration');

jest.mock('../../utils', () => ({
...require.requireActual('../../utils'),
fetchLibraryVersions: jest.fn(() => Promise.resolve(['1.0.0'])),
}));

test('without template throws', async () => {
expect.assertions(1);

Expand Down Expand Up @@ -42,6 +48,20 @@ test('with options from arguments and prompt merge', async () => {
);
});

test('without stable version available', async () => {
utils.fetchLibraryVersions.mockImplementationOnce(() =>
Promise.resolve(['1.0.0-beta.0'])
);

const configuration = await getConfiguration({
answers: {
template: 'InstantSearch.js',
},
});

expect(configuration.libraryVersion).toBe('1.0.0-beta.0');
});

test('with config file overrides all options', async () => {
const loadJsonFileFn = jest.fn(x => Promise.resolve(x));
const ignoredOptions = {
Expand Down
7 changes: 6 additions & 1 deletion src/cli/getConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ module.exports = async function getConfiguration({

libraryVersion = await fetchLibraryVersions(
templateConfig.libraryName
).then(latestSemver);
).then(
versions =>
// Return the lastest available version when
// the stable version is not available
latestSemver(versions) || versions[0]
);
}

return {
Expand Down

0 comments on commit e764cd5

Please sign in to comment.