Skip to content

Commit 72ced7c

Browse files
committed
Decaffinate spec
Add options to waitsForPromise Simplify waitsForPromise again
1 parent 48cdbf9 commit 72ced7c

File tree

6 files changed

+307
-252
lines changed

6 files changed

+307
-252
lines changed

spec/client.coffee

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

spec/client.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* decaffeinate suggestions:
3+
* DS102: Remove unnecessary code created because of implicit returns
4+
* DS205: Consider reworking code to avoid use of IIFEs
5+
* DS207: Consider shorter variations of null checks
6+
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
7+
*/
8+
const path = require('path');
9+
const juno = require('../lib/julia-client');
10+
11+
const {client} = juno.connection;
12+
13+
module.exports = function() {
14+
15+
const clientStatus = () => [client.isActive(), client.isWorking()];
16+
const {echo, evalsimple} = client.import(['echo', 'evalsimple']);
17+
18+
describe("before booting", function() {
19+
const checkPath = p => juno.misc.paths.getVersion(p);
20+
21+
it("can invalidate a non-existant julia binary", () => waitsFor(done => checkPath(path.join(__dirname, "foobar")).catch(() => done())));
22+
23+
it("can validate a julia command", () => waitsFor(done => checkPath("julia").then(() => done())));
24+
25+
return it("can invalidate a non-existant julia command", () => waitsFor(done => checkPath("nojulia").catch(() => done())));
26+
});
27+
28+
let conn = null;
29+
beforeEach(function() {
30+
if (conn != null) {
31+
return client.attach(conn);
32+
}
33+
});
34+
35+
describe("when booting the client", function() {
36+
37+
it("recognises the client's state before boot", () => expect(clientStatus()).toEqual([false, false]));
38+
39+
it("initiates the boot", function() {
40+
waitsForPromise(() => juno.connection.local.start());
41+
return runs(() => conn = client.conn);
42+
});
43+
44+
return it("waits for the boot to complete", function() {
45+
const pong = client.import('ping')();
46+
expect(clientStatus()).toEqual([true, true]);
47+
return waitsFor('the client to boot', 5*60*1000, done => pong.then(function(pong) {
48+
expect(pong).toBe('pong');
49+
return done();
50+
}));
51+
});
52+
});
53+
54+
// it "recognises the client's state after boot", ->
55+
// expect(clientStatus()).toEqual [true, false]
56+
57+
describe("while the client is active", function() {
58+
59+
it("can send and receive nested objects, strings and arrays", function() {
60+
const msg = {x: 1, y: [1,2,3], z: "foo"};
61+
return waitsForPromise(() => echo(msg).then(response => expect(response).toEqual(msg)));
62+
});
63+
64+
it("can evaluate code and return the result", function() {
65+
const remote = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => evalsimple(`${x}^2`));
66+
return waitsForPromise(() => Promise.all(remote).then(remote => expect(remote).toEqual(([1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((x) => Math.pow(x, 2))))));
67+
});
68+
69+
it("can rpc into the frontend", function() {
70+
let x;
71+
client.handle({test(x) { return Math.pow(x, 2); }});
72+
const remote = ((() => {
73+
let i;
74+
const result = [];
75+
for (i = 1, x = i; i <= 10; i++, x = i) {
76+
result.push(evalsimple(`Atom.@rpc test(${x})`));
77+
}
78+
return result;
79+
})());
80+
return waitsForPromise(() => Promise.all(remote).then(remote => expect(remote).toEqual(((() => {
81+
const result1 = [];
82+
for (x = 1; x <= 10; x++) {
83+
result1.push(Math.pow(x, 2));
84+
}
85+
return result1;
86+
})()))));
87+
});
88+
89+
it("can retrieve promise values from the frontend", function() {
90+
client.handle({test(x) { return Promise.resolve(x); }});
91+
return waitsForPromise(() => evalsimple("Atom.@rpc test(2)").then(x => expect(x).toBe(2)));
92+
});
93+
94+
describe("when using callbacks", function() {
95+
let {cbs, workingSpy, doneSpy} = {};
96+
97+
beforeEach(function() {
98+
client.onWorking((workingSpy = jasmine.createSpy('working')));
99+
client.onDone((doneSpy = jasmine.createSpy('done')));
100+
return cbs = ([1, 2, 3, 4, 5].map((i) => evalsimple("peakflops(100)")));
101+
});
102+
103+
it("enters loading state", () => expect(client.isWorking()).toBe(true));
104+
105+
// it "emits a working event", ->
106+
// expect(workingSpy.calls.length).toBe(1)
107+
108+
it("isn't done yet", () => expect(doneSpy).not.toHaveBeenCalled());
109+
110+
return describe("when they finish", function() {
111+
112+
beforeEach(() => waitsFor(10*1000, done => Promise.all(cbs).then(done)));
113+
114+
it("stops loading after they are done", () => expect(client.isWorking()).toBe(false));
115+
116+
return it("emits a done event", () => expect(doneSpy.calls.length).toBe(1));
117+
});
118+
});
119+
120+
return it("can handle a large number of concurrent callbacks", function() {
121+
const n = 100;
122+
const cbs = (__range__(0, n, false).map((i) => evalsimple(`sleep(rand()); ${i}^2`)));
123+
return waitsForPromise(() => Promise.all(cbs).then(xs => expect(xs).toEqual((__range__(0, n, false).map((x) => Math.pow(x, 2))))));
124+
});
125+
});
126+
127+
return it("handles shutdown correctly", function() {
128+
waitsFor(done => evalsimple('exit()').catch(() => done()));
129+
return runs(function() {
130+
expect(client.isWorking()).toBe(false);
131+
return expect(clientStatus()).toEqual([false, false]);});
132+
});
133+
};
134+
135+
function __range__(left, right, inclusive) {
136+
let range = [];
137+
let ascending = left < right;
138+
let end = !inclusive ? right : ascending ? right + 1 : right - 1;
139+
for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
140+
range.push(i);
141+
}
142+
return range;
143+
}

spec/eval.coffee

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

0 commit comments

Comments
 (0)