This repository was archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
45 lines (40 loc) · 1.37 KB
/
test.js
File metadata and controls
45 lines (40 loc) · 1.37 KB
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
'use strict';
require('require-rewrite')(__dirname);
const Fs = require('fs-extra');
const chalk = require('chalk');
const request = require('request');
const { loadConfig, console } = require('lib/config');
//------------------------------------------------------------------------------
const run = async () => {
if (process.argv.length < 3) {
console.log(`Usage: node test <testfile> [<configname>]`);
process.exit(1);
}
const testFile = process.argv[2];
const configName = process.argv.length > 3
? process.argv[3]
: 'default';
const config = await loadConfig(configName);
process.env.NODE_ENV = config.NODE_ENV;
console.log(`Config: ${chalk.whiteBright(config.__file)}.`);
console.log(`NODE_ENV: ${chalk.whiteBright(process.env.NODE_ENV)}.`);
const gitlabService = config.services.find(service => service.name === 'gitlab');
const gitlabUrl = gitlabService && gitlabService.url;
if (!gitlabUrl) {
throw new Error(`Invalid or missing services.gitlab`);
}
const testData = await Fs.readJson(testFile);
request.post({
url: `http://127.0.0.1:${config.port}${gitlabUrl}`,
headers: testData.header,
body: testData.body,
json: true,
}, () => {
console.log('');
}).pipe(process.stdout);
};
//==============================================================================
run().catch(error => {
console.log(chalk.red(`✗ ${error.message}`));
process.exit(1);
});