Skip to content

Commit cd00b13

Browse files
committed
Merge branch 'master' into develop
2 parents 6738d30 + d52a516 commit cd00b13

2 files changed

Lines changed: 108 additions & 24 deletions

File tree

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import PlayStoreProvider from '../playStore';
2+
3+
const options = {
4+
packageName: "com.myapp",
5+
}
6+
7+
const mockSuccesfulResponse = ( returnBody ) => {
8+
global.fetch = jest.fn().mockImplementationOnce(() => {
9+
return new Promise((resolve, reject) => {
10+
resolve(new Response(returnBody));
11+
});
12+
});
13+
};
14+
15+
describe('PlayStoreProvider get version from older Play Store layouts', () => {
16+
17+
it('get version from older (since ~Apr, 2018) Play Store layout', async () => {
18+
mockSuccesfulResponse("\
19+
<html>\
20+
<div class=\"hAyfc\">\
21+
<div class=\"BgcNfc\">\
22+
Current Version\
23+
</div>\
24+
<span class=\"htlgb\">\
25+
<div>\
26+
<span class=\"htlgb\">0.10.0</span>\
27+
</div>\
28+
</span>\
29+
</div>\
30+
</html>\
31+
")
32+
33+
await PlayStoreProvider.getVersion(options).then(
34+
r => expect(r).toBe("0.10.0")
35+
);
36+
});
37+
38+
it('get version from ancient (prior to ~Apr, 2018) Play Store layout', async () => {
39+
mockSuccesfulResponse("\
40+
<html>\
41+
<div class=\"hAyfc\">\
42+
<div class=\"BgcNfc\">\
43+
Current Version\
44+
</div>\
45+
<span class=\"htlgb\">\
46+
<span class=\"softwareVersion\">0.10.0</span>\
47+
</span>\
48+
</div>\
49+
</html>\
50+
")
51+
52+
await PlayStoreProvider.getVersion(options).then(
53+
r => expect(r).toBe("0.10.0")
54+
);
55+
});
56+
57+
});
58+
59+
describe('PlayStoreProvider get version current (since ~Dec, 2018) Play Store', () => {
60+
61+
it('with format x.x.x', async () => {
62+
mockSuccesfulResponse("\
63+
<html>\
64+
<div class=\"hAyfc\">\
65+
<div class=\"BgcNfc\">\
66+
Current Version\
67+
</div>\
68+
<span class=\"htlgb\">\
69+
<div class=\"IQ1z0d\">\
70+
<span class=\"htlgb\">0.10.0</span>\
71+
</div>\
72+
</span>\
73+
</div>\
74+
</html>\
75+
")
76+
77+
await PlayStoreProvider.getVersion(options).then(
78+
r => expect(r).toBe("0.10.0")
79+
);
80+
});
81+
82+
it('with format xxx', async () => {
83+
mockSuccesfulResponse("\
84+
<html>\
85+
<div class=\"hAyfc\">\
86+
<div class=\"BgcNfc\">\
87+
Current Version\
88+
</div>\
89+
<span class=\"htlgb\">\
90+
<div class=\"IQ1z0d\">\
91+
<span class=\"htlgb\">234</span>\
92+
</div>\
93+
</span>\
94+
</div>\
95+
</html>\
96+
")
97+
98+
await PlayStoreProvider.getVersion(options).then(
99+
r => expect(r).toBe("234")
100+
);
101+
});
102+
});
103+

packages/react-native-version-check/src/providers/playStore.js

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import { getVersionInfo } from '../versionInfo';
33

44
import { type IProvider } from './types';
55

6-
const MARKETVERSION_STARTTOKEN = 'softwareVersion">';
7-
const MARKETVERSION_ENDTOKEN = '</span>';
8-
const MARKETVERSION_STARTTOKEN_NEW =
9-
'Current Version</div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">';
10-
116
export type PlayStoreGetVersionOption = {
127
packageName?: string,
138
fetchOptions?: any,
@@ -41,28 +36,14 @@ class PlayStoreProvider implements IProvider {
4136
)
4237
.then(res => res.text())
4338
.then(text => {
44-
let indexStart = text.indexOf(MARKETVERSION_STARTTOKEN);
45-
let startTokenLength = MARKETVERSION_STARTTOKEN.length;
46-
let latestVersion = null;
47-
if (indexStart === -1) {
48-
indexStart = text.indexOf(MARKETVERSION_STARTTOKEN_NEW);
49-
startTokenLength = MARKETVERSION_STARTTOKEN_NEW.length;
50-
if (indexStart === -1) {
51-
return Promise.reject(error(text));
52-
}
39+
match = text.match(/Current Version.+>([\d.]+)<\/span>/);
40+
if(match){
41+
latestVersion = match[1].trim();
42+
return Promise.resolve(latestVersion);
5343
}
54-
55-
text = text.substr(indexStart + startTokenLength);
56-
57-
const indexEnd = text.indexOf(MARKETVERSION_ENDTOKEN);
58-
if (indexEnd === -1) {
44+
else{
5945
return Promise.reject(error(text));
6046
}
61-
62-
text = text.substr(0, indexEnd);
63-
64-
latestVersion = text.trim();
65-
return Promise.resolve(latestVersion);
6647
});
6748
} catch (e) {
6849
if (option.ignoreErrors) {

0 commit comments

Comments
 (0)