mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 16:11:33 +08:00
FIX & ADD more tests
This commit is contained in:
parent
8dfb0c0d4f
commit
d49c1aab4b
@ -2,7 +2,6 @@ import { VERSIONCHECK } from 'global';
|
||||
import semver from 'semver';
|
||||
import memoize from 'memoizerific';
|
||||
|
||||
import { version } from 'punycode';
|
||||
import { version as currentVersion } from '../version';
|
||||
|
||||
import { Module, API } from '../index';
|
||||
@ -84,7 +83,13 @@ export default function({ store, mode }: Module) {
|
||||
if (!latest.version) {
|
||||
return true;
|
||||
}
|
||||
return semver.gt(latest.version, current.version);
|
||||
if (!current.version) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const diff = semver.diff(current.version, latest.version);
|
||||
|
||||
return semver.gt(latest.version, current.version) && diff !== 'patch';
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
@ -24,8 +24,12 @@ jest.mock('@storybook/client-logger');
|
||||
function createMockStore() {
|
||||
let state = {
|
||||
versions: {
|
||||
latest: {},
|
||||
current: {},
|
||||
latest: {
|
||||
version: '3.0.0',
|
||||
},
|
||||
current: {
|
||||
version: '3.0.0',
|
||||
},
|
||||
},
|
||||
};
|
||||
return {
|
||||
@ -165,13 +169,75 @@ describe('versions API', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('versionUpdateAvailable works', async () => {
|
||||
const store = createMockStore();
|
||||
const { api, init, state: initialState } = initVersions({ store });
|
||||
store.setState(initialState);
|
||||
describe('versionUpdateAvailable', () => {
|
||||
it('matching version', async () => {
|
||||
const store = createMockStore();
|
||||
const { api, init, state: initialState } = initVersions({ store });
|
||||
store.setState({
|
||||
...initialState,
|
||||
versions: {
|
||||
...initialState.versions,
|
||||
current: { version: '5.2.1' },
|
||||
latest: { version: '5.2.1' },
|
||||
},
|
||||
});
|
||||
|
||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
||||
|
||||
expect(api.versionUpdateAvailable()).toEqual(true);
|
||||
expect(api.versionUpdateAvailable()).toEqual(false);
|
||||
});
|
||||
|
||||
it('new patch version', async () => {
|
||||
const store = createMockStore();
|
||||
const { api, init, state: initialState } = initVersions({ store });
|
||||
store.setState({
|
||||
...initialState,
|
||||
versions: {
|
||||
...initialState.versions,
|
||||
current: { version: '5.2.1' },
|
||||
latest: { version: '5.2.2' },
|
||||
},
|
||||
});
|
||||
|
||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
||||
|
||||
expect(api.versionUpdateAvailable()).toEqual(false);
|
||||
});
|
||||
|
||||
it('new minor version', async () => {
|
||||
const store = createMockStore();
|
||||
const { api, init, state: initialState } = initVersions({ store });
|
||||
|
||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
||||
|
||||
store.setState({
|
||||
...initialState,
|
||||
versions: {
|
||||
...initialState.versions,
|
||||
current: { version: '5.2.1' },
|
||||
latest: { version: '5.3.1' },
|
||||
},
|
||||
});
|
||||
|
||||
expect(api.versionUpdateAvailable()).toEqual(true);
|
||||
});
|
||||
|
||||
it('new major version', async () => {
|
||||
const store = createMockStore();
|
||||
const { api, init, state: initialState } = initVersions({ store });
|
||||
|
||||
await init({ api: { ...api, addNotification: jest.fn() } });
|
||||
|
||||
store.setState({
|
||||
...initialState,
|
||||
versions: {
|
||||
...initialState.versions,
|
||||
current: { version: '5.2.1' },
|
||||
latest: { version: '6.2.1' },
|
||||
},
|
||||
});
|
||||
|
||||
expect(api.versionUpdateAvailable()).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user