Skip to content

Commit

Permalink
Merge branch 'main' into cli/api
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 authored Sep 19, 2024
2 parents 7bbef0f + 3c39ead commit c62902f
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ jobs:
- name: Build webpack bundles
run: npm run webpack

- name: Run unit-tests
run: npx ts-node test/unit-tests/runtime
- name: Run tests
run: npm run test:tests
3 changes: 2 additions & 1 deletion demos/dashboards-rna-news/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<link rel="stylesheet" href="demo.css" />
<script src="https://code.highcharts.com/dashboards/datagrid.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="../../code/connectors-morningstar.src.js"></script>
<script src="https://code.highcharts.com/dashboards/dashboards.js"></script>
<script src="https://code.highcharts.com/connectors/morningstar/connectors-morningstar.src.js"></script>
<title>Highcharts Dashboards + Morningstar RNA News</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion demos/stock-ohlcv/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<script src="https://code.highcharts.com/stock/highstock.src.js"></script>
<script src="../../code/connectors-morningstar.src.js"></script>
<script src="https://code.highcharts.com/connectors/morningstar/connectors-morningstar.src.js"></script>
<title>Highcharts Stock + Morningstar OHLCV TimeSeries</title>
<style>
body {
Expand Down
2 changes: 1 addition & 1 deletion demos/stock-timeseries/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<script src="https://code.highcharts.com/stock/highstock.src.js"></script>
<script src="../../code/connectors-morningstar.src.js"></script>
<script src="https://code.highcharts.com/connectors/morningstar/connectors-morningstar.src.js"></script>
<title>Highcharts Stock + Morningstar TimeSeries</title>
<style>
body {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
"scripts:bin": "rm -rf bin/ && tsc -p src/CLI/ && chmod +x bin/*.js && cp -R src/CLI/Static bin/ && ts-node tools/api",
"scripts:code": "rm -rf code/ && tsc -p src/",
"reset": "rm -rf bin/ build/ code/ node_modules/ ; npm i",
"test": "npm run webpack && npm run test:eslint && npm run test:unit-tests",
"test": "npm run webpack && npm run test:eslint && npm run test:tests",
"test:eslint": "eslint .",
"test:morningstar": "npx -y newman run --bail tmp/Collection.json -e tmp/Environment.json",
"test:unit-tests": "ts-node test/unit-tests/runtime",
"test:tests": "ts-node tools/tests",
"watch": "tsc -p src/ -w",
"webpack": "npm run scripts && webpack && npm run webpack:dts",
"webpack:dts": "npm run webpack:dts:cm",
Expand Down
36 changes: 26 additions & 10 deletions src/CLI/Library/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ export const DEFAULT_PORT = 8080;


export const MIME_TYPES: Record<string, string> = {
css: 'text/css; charset=UTF-8',
css: 'text/css; charset=utf-8',
eot: 'application/vnd.ms-fontobject',
gif: 'image/gif',
html: 'text/html; charset=UTF-8',
html: 'text/html; charset=utf-8',
ico: 'image/x-icon',
jpeg: 'image/jpeg',
jpg: 'image/jpeg',
js: 'application/javascript; charset=UTF-8',
json: 'application/json; charset=UTF-8',
map: 'application/json; charset=UTF-8',
js: 'application/javascript',
json: 'application/json',
map: 'application/json',
markdown: 'text/markdown',
md: 'text/markdown; charset=UTF-8',
md: 'text/markdown; charset=utf-8',
png: 'image/png',
svg: 'image/svg+xml; charset=UTF-8',
svg: 'image/svg+xml',
ttf: 'font/ttf',
txt: 'text/plain; charset=UTF-8',
txt: 'text/plain; charset=utf-8',
woff: 'font/woff',
woff2: 'font/woff2',
xml: 'application/xml; charset=UTF-8'
xml: 'application/xml'
};


Expand Down Expand Up @@ -235,7 +235,22 @@ export class Server {
].join('\n'));
ext = 'html';
}
response.writeHead(200, { 'Content-Type': MIME_TYPES[ext] });

if (['html', 'js'].includes(ext)) {
fileBuffer = Buffer.from(
fileBuffer
.toString('utf8')
.replace(
/https:\/\/code\.highcharts\.com\/connectors\/morningstar\//u,
'/code/'
)
);
}

response.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Content-Type': MIMES[ext]

Check failure on line 252 in src/CLI/Library/Server.ts

View workflow job for this annotation

GitHub Actions / Test eslint style

Cannot find name 'MIMES'.

Check failure on line 252 in src/CLI/Library/Server.ts

View workflow job for this annotation

GitHub Actions / Test distribution

Cannot find name 'MIMES'.

Check failure on line 252 in src/CLI/Library/Server.ts

View workflow job for this annotation

GitHub Actions / Test unit-tests

Cannot find name 'MIMES'.
});
response.end(fileBuffer);

} catch (error) {
Expand Down Expand Up @@ -271,6 +286,7 @@ export class Server {
): Server {

this.folder = (folder || this.folder);

this.http.listen(port);

return this;
Expand Down
4 changes: 3 additions & 1 deletion src/CLI/connectors-morningstar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export async function main (): Promise<void> {

server.start(port);

console.info(`Content available at http://localhost:${port}.`);
if (server.http?.listening) {
console.info(`Content available at http://localhost:${port}.`);
}

process.stdin.on('data', (data) => {
const input = data.toString('utf8');
Expand Down
19 changes: 9 additions & 10 deletions src/Shared/MorningstarPostman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,20 @@ export namespace MorningstarPostman {
const url = postmanEnvironment.getValueOf(/^Morningstar as a Service \(/u);
const username = postmanEnvironment.getValueOf('Morningstar as a Service Username');

if (url) {
apiOptions.url = url.value;
if (apiOptions.url.startsWith('www.')) {
apiOptions.url = `https://${apiOptions.url}`;
}
}

if (password && username) {
apiOptions.access = {
password: password.value,
username: username.value
};
if (url) {
apiOptions.access.url = `https://${url.value}`;
}
}

if (url) {
apiOptions.url = url.value;

if (apiOptions.url.startsWith('www.')) {
apiOptions.url = `https://${apiOptions.url}`;
if (apiOptions.url && url) {
apiOptions.access.url = `${apiOptions.url}/token/oauth`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/README.md → tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ You have to define the Morningstar credentials to be able to run the tests.

3. Now you can run the tests with:

- `npm run test:unit-tests`
- `npm run test:tests`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import RNANewsJSON from '../../../src/RNANews/RNANewsJSON';
import * as MC from '../../code/connectors-morningstar.src';
import RNANewsJSON from '../../src/RNANews/RNANewsJSON';

export async function rnaNewsLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import * as MC from '../../code/connectors-morningstar.src';

export async function apiAccess (
apiOptions: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import * as MC from '../../code/connectors-morningstar.src';

export async function cumulativeReturnLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import * as MC from '../../code/connectors-morningstar.src';

export async function ratingLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import * as MC from '../../code/connectors-morningstar.src';

export async function growthLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import * as MC from '../../code/connectors-morningstar.src';

export async function ohlcvLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import MorningstarURL from '../../../src/Shared/MorningstarURL';
import * as MC from '../../code/connectors-morningstar.src';
import MorningstarURL from '../../src/Shared/MorningstarURL';

export async function priceLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import * as MC from '../../code/connectors-morningstar.src';

export async function ratingLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../../code/connectors-morningstar.src';
import * as MC from '../../code/connectors-morningstar.src';

export async function breakdownLoad (
api: MC.Shared.MorningstarAPIOptions
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/version.test.ts → tests/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../code/connectors-morningstar.src';
import * as MC from '../code/connectors-morningstar.src';

export function version (): void {

Expand Down
2 changes: 1 addition & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Highcharts Morningstar Connectors Tools
=======================================

These scripts are used to prepare distribution of new releases.
These scripts are used to prepare the distribution of new releases.



Expand Down
8 changes: 5 additions & 3 deletions test/unit-tests/runtime.ts → tools/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
* */


import type { Shared } from '../../code/connectors-morningstar.src';
import type { Shared } from '../code/connectors-morningstar.src';

import * as FS from 'node:fs/promises';
import * as FSSync from 'node:fs';
import * as JSDOM from 'jsdom';
import * as Path from 'node:path';


/* *
Expand Down Expand Up @@ -125,19 +126,20 @@ async function runUnitTests () {
const failures: Array<string> = [];
const successes: Array<string> = [];
const stdout = process.stdout;
const testFolder = Path.join(__dirname, '..', 'tests');

let test: unknown;
let unitTests: Record<string, unknown>;

for (let path of (await FS.readdir(__dirname, { recursive: true })).sort()) {
for (let path of (await FS.readdir(testFolder, { recursive: true })).sort()) {

if (!path.endsWith('.test.ts')) {
continue;
}

stdWrite('Start', path.substring(0, path.length - 8), 'tests ...\n');

path = './' + path.substring(0, path.length - 3);
path = Path.join(testFolder, path.substring(0, path.length - 3));
unitTests = await import(path) as Record<string, unknown>;

for (let testName of Object.keys(unitTests)) {
Expand Down

0 comments on commit c62902f

Please sign in to comment.