-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
remote.spec.js
69 lines (62 loc) · 2.41 KB
/
remote.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
describe('remotes', function () {
this.timeout(20000);
let worker;
const createWorker = async () => {
worker = new Worker(new URL('worker.js', import.meta.url), {type: 'module'});
await new Promise(resolve => {
worker.onmessage = msg => {
if (msg.data.ready) {
resolve(msg);
}
}
});
}
const callWorker = async (command, params) => {
return await new Promise(resolve => {
worker.onmessage = msg => resolve(msg.data);
worker.postMessage(Object.assign({
command: command
}, params));
});
};
const callWorkerWithArgs = async (command, ...args) => {
return await new Promise(resolve => {
worker.onmessage = msg => resolve(msg.data)
worker.postMessage({
command: command,
args: args
});
});
};
this.beforeAll(async () => {
await createWorker();
await callWorker('synclocal', {url: `${location.origin}/testremote.git`, newrepo: true });
});
this.afterAll(async () => {
assert.equal((await callWorker('deletelocal')).deleted, 'testremote.git');
worker.terminate();
});
it('should be possible to create a new repo locally, set remotes and push', async () => {
await callWorkerWithArgs('init', '.');
await callWorkerWithArgs('config', 'user.name', 'Test');
await callWorkerWithArgs('config', 'user.email', '[email protected]');
await callWorker(
'writefile', {
filename: 'test.txt',
contents: 'blabla'
});
await callWorkerWithArgs('add', 'test.txt');
await callWorkerWithArgs('commit', '-m', 'first commit');
await callWorker(
'writefile', {
filename: 'test2.txt',
contents: 'blabla'
});
await callWorkerWithArgs('add', 'test2.txt');
await callWorkerWithArgs('commit', '-m', 'second commit');
assert.isTrue((await callWorker('push')).stderr.indexOf("remote 'origin' does not exist") > -1);
await callWorkerWithArgs('remote', 'add', 'origin', `${location.origin}/testremote.git`);
assert.equal((await callWorker('push')).stderr, '');
assert.equal((await callWorkerWithArgs('fetch', 'origin')).stderr, '');
});
});