Skip to content

Commit 93c5bc8

Browse files
authored
Merge pull request #14 from watanabeyu/develop
v1.3.0
2 parents 23117a1 + a406005 commit 93c5bc8

14 files changed

Lines changed: 6289 additions & 5466 deletions

File tree

.vscode/settings.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
{
22
"eslint.nodePath": "./node_modules/eslint",
33
"eslint.run": "onSave",
4-
"eslint.autoFixOnSave": true,
54
"eslint.alwaysShowStatus": true,
65
"eslint.enable": true,
76
"eslint.validate": [
87
"javascript",
98
"javascriptreact",
10-
{
11-
"language": "typescript",
12-
"autoFix": true
13-
},
14-
{
15-
"language": "typescriptreact",
16-
"autoFix": true
17-
}
18-
]
9+
"typescript",
10+
"typescriptreact"
11+
],
12+
"editor.codeActionsOnSave": {
13+
"source.fixAll.eslint": true
14+
}
1915
}

README.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,51 @@ By writing code successfully, you can make a forced update.
77
$ npm install --save react-native-store-version
88
```
99

10+
## CHANGELOG
11+
### v1.3.0
12+
- if failed, throw an error.
13+
1014
## Usage
11-
```jsx
15+
```tsx
1216
import checkVersion from 'react-native-store-version';
1317

14-
export default class App extends React.Component {
15-
...
16-
17-
async componentDidMount(){
18-
const check = await checkVersion({
19-
version: "1.0.0", // app local version
20-
iosStoreURL: 'ios app store url',
21-
androidStoreURL: 'android app store url',
22-
country: 'jp' // default value is 'jp'
23-
});
24-
25-
if(check.result === "new"){
26-
// if app store version is new
27-
}
28-
}
18+
export default function App() {
19+
useEffect(() => {
20+
const init = async () => {
21+
try{
22+
const check = await checkVersion({
23+
version: "1.0.0", // app local version
24+
iosStoreURL: 'ios app store url',
25+
androidStoreURL: 'android app store url',
26+
country: 'jp' // default value is 'jp'
27+
});
28+
29+
if(check.result === "new"){
30+
// if app store version is new
31+
}
32+
} catch(e) {
33+
console.log(e);
34+
}
35+
};
36+
37+
init();
38+
},[]);
2939
}
3040
```
3141

3242
## Return value
3343
```jsx
44+
// correct
3445
{
35-
error: false,
36-
message: null, // if has error return error message
3746
local: "1.0.0",
3847
remote: "1.1.0",
3948
result: "new" // "new" | "old" | "equal"
4049
}
50+
51+
// catch error
52+
{
53+
message: "string",
54+
}
4155
```
4256
result compare from a `local` to `remote`.
4357
If `local(1.0.0)` and `remote(1.1.0)`, result is new.

__tests__/index.test.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,29 @@
1-
import fetch from 'jest-fetch-mock';
21
import checkVersion, { compareVersion } from '../src';
32
import getIOSVersion from '../src/ios';
43
import getAndroidVersion from '../src/android';
54

6-
describe('checkVersion', () => {
5+
require('jest-fetch-mock');
6+
7+
describe('ios', () => {
78
beforeEach(() => {
8-
jest.mock('Platform', () => ({ OS: 'ios' }));
9-
jest.mock('fetch', () => fetch);
10-
jest.setTimeout(30000);
9+
jest.resetModules();
10+
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
11+
OS: 'ios',
12+
select: () => null,
13+
}));
1114
});
1215

13-
// it('ios correct pattern', async () => {
14-
// jest.mock('Platform', () => ({ OS: 'ios' }));
15-
16-
// const result = await checkVersion({
17-
// version: '1.0.0',
18-
// iosStoreURL: 'https://itunes.apple.com/app/id1321198947?mt=8',
19-
// country: 'us',
20-
// });
21-
22-
// expect(result).toHaveProperty('local');
23-
// expect(result).toHaveProperty('remote');
24-
// expect(result).toHaveProperty('result', 'new');
25-
// });
26-
27-
// it('android correct pattern', async () => {
28-
// jest.mock('Platform', () => ({ OS: 'android' }));
29-
30-
// const result = await checkVersion({
31-
// version: '100.0.0',
32-
// iosStoreURL: 'https://play.google.com/store/apps/details?id=jp.ewaf.likedsearch.android',
33-
// });
34-
35-
// expect(result).toHaveProperty('local');
36-
// expect(result).toHaveProperty('remote');
37-
// expect(result).toHaveProperty('result', 'old');
38-
// });
39-
4016
it('error pattern', async () => {
41-
const result = await checkVersion({
42-
version: '1.0.0',
43-
});
44-
45-
expect(result).toHaveProperty('error', true);
17+
try {
18+
await checkVersion({
19+
version: '1.0.0',
20+
});
21+
} catch (e) {
22+
expect(e.message).toBe('iosStoreURL is not set.');
23+
}
4624
});
4725

48-
it('ios get version', async () => {
26+
it('get version', async () => {
4927
const correctPattern = await getIOSVersion('https://itunes.apple.com/jp/app/pin-point/id1321198947');
5028
expect(correctPattern).toEqual(expect.stringMatching(/[0-9]{1,}\.?[0-9]*\.?[0-9]*\.?/));
5129

@@ -61,8 +39,28 @@ describe('checkVersion', () => {
6139
expect(e).toHaveProperty('message');
6240
}
6341
});
42+
});
43+
44+
describe('android', () => {
45+
beforeEach(() => {
46+
jest.resetModules();
47+
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
48+
OS: 'android',
49+
select: () => null,
50+
}));
51+
});
6452

65-
it('android get version', async () => {
53+
it('error pattern', async () => {
54+
try {
55+
await checkVersion({
56+
version: '1.0.0',
57+
});
58+
} catch (e) {
59+
expect(e.message).toBe('androidStoreURL is not set.');
60+
}
61+
});
62+
63+
it('get version', async () => {
6664
const correctPattern = await getAndroidVersion('https://play.google.com/store/apps/details?id=jp.ewaf.likedsearch.android');
6765
expect(correctPattern).toEqual(expect.stringMatching(/[0-9]{1,}\.?[0-9]*\.?[0-9]*\.?/));
6866

@@ -78,7 +76,9 @@ describe('checkVersion', () => {
7876
expect(e).toHaveProperty('message');
7977
}
8078
});
79+
});
8180

81+
describe('other', () => {
8282
it('compare version', () => {
8383
const remoteIsOld = compareVersion('1.1.0', '1.0.3');
8484
expect(remoteIsOld).toBe('old');

babel.config.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
11
module.exports = {
2-
presets: [
3-
[
4-
'@babel/preset-env',
5-
{
6-
targets: {
7-
node: 'current',
8-
},
9-
},
10-
],
11-
],
12-
env: {
13-
test: {
14-
plugins: [
15-
'@babel/plugin-proposal-class-properties',
16-
],
17-
},
18-
},
2+
presets: ['module:metro-react-native-babel-preset'],
193
};

example/App.js

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)