Skip to content

Commit 2a511d3

Browse files
Added tests
1 parent 3227eea commit 2a511d3

File tree

4 files changed

+101
-14
lines changed

4 files changed

+101
-14
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ src/*.d.ts
1212
!src/references.d.ts
1313
!src/code-push-lib.d.ts
1414

15-
demo/app/*.js
1615
!demo/karma.conf.js
17-
!demo/app/tests/*.js
16+
!demo/demoapp/tests/*.js
1817
demo/*.d.ts
1918
!demo/references.d.ts
2019
demo/lib

README.md

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ _To confuse you even more, have a diagram:_
3333

3434
<img src="https://github.com/EddyVerbruggen/nativescript-code-push/raw/master/media/NativeScript%20CodePush%20landscape.png" width="570px" height="508px">
3535

36-
### What can be CodePushed?
36+
### What can (and will) be CodePushed?
3737
- Anything inside your `/app` folder.
3838
- Anything inside your `/node_modules` folder.
3939

40+
> 💁‍♂️ Note that we don't actually use those folders, but the `app` folder in `platforms/ios/<appname>/app` and `platforms/android/app/src/main/assets/app`, the benefit of which is we don't "care" if you use Webpack or Uglify or whatever tools you use to minify or scramble your app's assets.
41+
4042
### What can't (and won't):
4143
- NativeScript platform updates. Example: bumping `tns-android` from version 2.5.1 to 2.5.2.
4244
- Plugins updates that also require a different version of a native library it depends on.
@@ -45,14 +47,16 @@ So as long as you don't change versions of dependencies and tns platforms in you
4547
can push happily. And if you do bump a version of a dependency make sure there are no changed platform libraries.
4648

4749
## Getting Started
48-
TODO test this workflow!
50+
> ⚠️ TODO test this workflow!
4951
5052
#### Globally install the NativeScript-compatible CodePush CLI
5153

5254
```shell
5355
npm i -g nativescript-code-push-cli
5456
```
5557

58+
> 💁‍♂️ This will also add the global `nativescript-code-push` command to your machine.
59+
5660
#### Login or register with the service
5761

5862
Log in if you already have an account:
@@ -75,7 +79,7 @@ nativescript-code-push app add MyApp-IOS ios nativescript
7579
nativescript-code-push app add MyApp-Android android nativescript
7680
```
7781

78-
> This will show you your deployment keys you'll need when connecting to the CodePush server.
82+
> 💁‍♂️ This will show you your deployment keys you'll need when connecting to the CodePush server.
7983
8084
#### List your registered apps
8185

@@ -89,15 +93,15 @@ nativescript-code-push app ls
8993
tns plugin add nativescript-code-push
9094
```
9195

92-
> If you're restricting access to the internet from within your app, make sure you whitelist `https://nativescript-codepush-server.herokuapp.com`.
96+
> ⚠️ If you're restricting access to the internet from within your app, make sure you whitelist `https://nativescript-codepush-server.herokuapp.com`.
9397
9498
## Checking for updates
9599
With the CodePush plugin installed and configured, the only thing left is to add the necessary code to your app to control when it checks for updates.
96100

97-
If an update is available, it will be silently downloaded, and installed the next time the app is restarted
98-
(so a cold boot, triggered either explicitly by the end user or by the OS),
99-
which ensures the least invasive experience for your end users.
100-
In the future we may add an option to reload the app instantly or upon resuming.
101+
If an update is available, it will be silently downloaded, and installed.
102+
103+
Then based on the provided `InstallMode` the plugin either waits until the next cold start (`InstallMode.ON_NEXT_RESTART`),
104+
warm restart (`InstallMode.ON_NEXT_RESUME`), or a positive response to a user prompt (`InstallMode.IMMEDIATE`).
101105

102106
> Also check out the [demo](/demo) for a solid example.
103107
@@ -140,7 +144,8 @@ CodePush.sync({
140144
});
141145
```
142146

143-
It's recommended to check for updates more than once in a cold boot cycle, so it may be easiest to tie this check to the `resume` event:
147+
It's recommended to check for updates more than once in a cold boot cycle,
148+
so it may be easiest to tie this check to the `resume` event:
144149

145150
```typescript
146151
import * as application from "tns-core-modules/application";
@@ -164,6 +169,8 @@ The easiest way to do this is to use the `release-nativescript` command in our C
164169
|targetBinaryVersion|t||Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3).
165170
|mandatory|m|not set, so "optional"|This specifies whether the update should be considered mandatory or not (e.g. it includes a critical security fix). This attribute is simply round tripped to the client, who can then decide if and how they would like to enforce it. This is flag, so its absence indicates an optional release.
166171

172+
Have a few examples for both platforms:
173+
167174
### iOS
168175

169176
```shell
@@ -182,17 +189,42 @@ nativescript-code-push release-nativescript <codepush-android-appname> android -
182189
```
183190

184191
### Tips
185-
> Make sure to create a release build first, so use the same command that you'd use for app store distribution, just don't send it to the AppStore. You can even webpack bundle and uglify your app, it's all transparent to this plugin.
192+
> Make sure to create a *release build* first, so use the same command that you'd use for app store distribution, just don't send it to the AppStore. You can even Webpack and Uglify your app, it's all transparent to this plugin.
186193
187194
> When releasing updates to CodePush, you do not need to bump your app's version since you aren't modifying the app store version at all. CodePush will automatically generate a "label" for each release you make (e.g. `v3`) in order to help identify it within your release history.
188195
189-
### Did folks install the update?
196+
### Which releases did I create and what are the install metrics?
190197
Using a command like this will tell you how many apps have the update installed:
191198

192199
```shell
193200
nativescript-code-push deployment history <codepush-ios-appname> Staging
194201
```
195202

203+
### Give me the details of the current release!
204+
205+
```shell
206+
nativescript-code-push deployment ls <codepush-ios-appname>
207+
```
208+
209+
And if you want to dump your deployment keys as well, use:
210+
211+
```shell
212+
nativescript-code-push deployment ls <codepush-ios-appname> --displayKeys
213+
```
214+
215+
┌────────────┬───────────────────────────────────────┬───────────────────────────────────────┬───────────────────────┐
216+
│ Name │ Deployment Key │ Update Metadata │ Install Metrics │
217+
├────────────┼───────────────────────────────────────┼───────────────────────────────────────┼───────────────────────┤
218+
│ Production │ r1DVaLfKjc0Y5d6BzqX45SFVss6a4ksvOXqog │ No updates released │ No installs recorded │
219+
├────────────┼───────────────────────────────────────┼───────────────────────────────────────┼───────────────────────┤
220+
│ Staging │ YTmVMy0GLCknVu3GVIynTxmfwxJN4ksvOXqog │ Label: v5 │ Active: 11% (2 of 19) │
221+
│ │ │ App Version: 1.0.0 │ Total: 2 │
222+
│ │ │ Mandatory: Yes │ │
223+
│ │ │ Release Time: an hour ago │ │
224+
│ │ │ Released By: eddyverbruggen@gmail.com │ │
225+
│ │ │ Description: Mandatory iOS version! │ │
226+
└────────────┴───────────────────────────────────────┴───────────────────────────────────────┴───────────────────────┘
227+
196228
## Testing CodePush packages during development
197229
You may want to play with CodePush before using it in production (smart move!).
198230
Perform these steps once you've pushed an update and added the `sync` command to your app:

demo/demoapp/tests/tests.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var CodePush = require("nativescript-code-push").CodePush;
2+
var SyncStatus = require("nativescript-code-push").SyncStatus;
3+
4+
describe("sync function", function() {
5+
it("exists", function() {
6+
expect(CodePush.sync).toBeDefined();
7+
});
8+
9+
it("expects a deploymentKey to be passed in", function (done) {
10+
try {
11+
CodePush.sync({});
12+
fail("Should have thrown an errot due to a missing deploymentKey");
13+
} catch (error) {
14+
expect(error).toEqual(new Error("Missing deploymentKey, pass it as part of the first parameter of the 'sync' function: { deploymentKey: 'your-key' }"));
15+
done();
16+
}
17+
});
18+
19+
it("expects a valid deploymentKey to be passed in", function (done) {
20+
CodePush.sync({deploymentKey: "invalid"}, function (syncStatus) {
21+
if (syncStatus === SyncStatus.ERROR) {
22+
// note that the details are logged to the console
23+
done();
24+
}
25+
});
26+
});
27+
28+
it("reports both 'checking for update' and 'error'", function (done) {
29+
var feedbackCount = 0;
30+
CodePush.sync({deploymentKey: "abc"}, function (syncStatus) {
31+
if (syncStatus === SyncStatus.CHECKING_FOR_UPDATE || syncStatus === SyncStatus.ERROR) {
32+
if (++feedbackCount === 2) {
33+
done();
34+
}
35+
}
36+
});
37+
});
38+
39+
it("ignores simultaneously being invoked", function (done) {
40+
var feedbackCount = 0;
41+
CodePush.sync({deploymentKey: "abc"}, function (syncStatus) {
42+
if (syncStatus === SyncStatus.CHECKING_FOR_UPDATE || syncStatus === SyncStatus.ERROR) {
43+
if (++feedbackCount === 3) {
44+
done();
45+
}
46+
}
47+
});
48+
CodePush.sync({deploymentKey: "abc"}, function (syncStatus) {
49+
if (syncStatus === SyncStatus.IN_PROGRESS) {
50+
if (++feedbackCount === 3) {
51+
done();
52+
}
53+
}
54+
});
55+
});
56+
});

demo/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function(config) {
1212

1313
// list of files / patterns to load in the browser
1414
files: [
15-
'app/**/*.js',
15+
'demoapp/**/*.js',
1616
],
1717

1818

0 commit comments

Comments
 (0)