forked from tagspaces/tagspaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-functions.js
150 lines (130 loc) · 3.86 KB
/
setup-functions.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import pathLib from 'path';
import fs from 'fs';
import sh from 'shelljs';
const S3rver = require('s3rver');
//const corsConfig = require.resolve('./s3rver/cors.xml');
export async function globalSetup() {
// global.isWin = /^win/.test(process.platform);
// global.isMac = /^darwin/.test(process.platform);
const extensionDir = pathLib.resolve(__dirname); //,'../tests');
if (!sh.test('-d', extensionDir)) {
sh.mkdir(extensionDir);
}
sh.cd(extensionDir);
}
export async function startMinio() {
const winMinio = pathLib.resolve(__dirname, './bin/minio.exe');
const unixMinio = pathLib.resolve(__dirname, './bin/minio');
const command = global.isWin ? winMinio : unixMinio;
const minioProcess = await require('child_process').spawn(command, [
'server',
pathLib.resolve(__dirname, './testdata-tmp/file-structure'),
]);
minioProcess.on('exit', function (code) {
// console.log('exit here with code: ', code);
});
minioProcess.on('close', (code, signal) => {
// console.log(`child process terminated due to receipt of signal ${signal}`);
});
minioProcess.stdout.on('data', function (data) {
// console.log('stdout: ' + data);
});
minioProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
return minioProcess;
}
export function stopMinio(process) {
if (process) {
// Send SIGHUP to process.
console.log('stopMinio');
process.stdin.pause();
process.kill(); //'SIGHUP');
}
}
export async function startChromeDriver() {
//const childProcess = await require('child_process');
const chromeDriver = await require('chromedriver');
//const binPath = chromedriver.path;
const args = ['--url-base=/', '--port=9515'];
await chromeDriver.start(args);
/*const process = await childProcess.execFile(binPath, args, function (err, stdout, stderr) {
// handle results
console.log('err: ' + err);
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
});*/
return chromeDriver;
}
export async function stopChromeDriver(chromeDriver) {
chromeDriver.stop();
// Send SIGHUP to process.
/*console.log('stopChromeDriver');
process.stdin.pause();
process.kill(); //'SIGHUP');*/
}
export async function startWebServer() {
const express = await require('express');
const serveStatic = await require('serve-static');
const port = 8000;
const app = express();
await app.use(
serveStatic(pathLib.resolve(__dirname, '../web'), {
index: ['index.html'],
}),
);
if (global.isMac) {
//todo copyfiles do not work for MacOS
// await app.use(serveStatic('../app'));
}
app.server = app.listen(port);
console.log('Webserver listining on http://127.0.0.1:' + port);
return app;
}
export async function stopServices(s3Server, webServer, minioServer) {
await stopS3Server(s3Server);
await stopWebServer(webServer);
await stopMinio(minioServer);
}
export async function stopWebServer(app) {
if (app) {
await app.server.close();
app = null;
}
}
export async function stopS3Server(server) {
if (server) {
await server.close();
server = null;
}
}
export async function runS3Server(silent = true) {
// Set NODE_OPTIONS environment variable to use openssl-legacy-provider
process.env.NODE_OPTIONS = '--openssl-legacy-provider';
const directoryTargetPath = pathLib.resolve(
__dirname,
'testdata-tmp',
'file-structure',
);
const corsConfig = pathLib.resolve(__dirname, 's3rver', 'cors.xml');
const instance = new S3rver({
port: 4569,
address: 'localhost',
silent: silent,
directory: directoryTargetPath,
resetOnClose: true,
sslEnabled: false,
configureBuckets: [
{
name: 'supported-filestypes',
configs: [fs.readFileSync(corsConfig)],
},
],
});
try {
await instance.run();
} catch (e) {
console.log('S3rver run', e);
}
return instance;
}