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

fix(cli): use latest version when stable unavailable #57

Merged
merged 2 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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