systemview 1.11.8 → 1.12.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/index.js CHANGED
@@ -24,6 +24,7 @@ const DEFAULT_PORT = 3000;
24
24
 
25
25
  async function startApp() {
26
26
  const port = isNaN(input[1]) ? DEFAULT_PORT : input[1];
27
+
27
28
  try {
28
29
  await launchApp(port);
29
30
  } catch (error) {
@@ -33,13 +34,17 @@ async function startApp() {
33
34
  }
34
35
 
35
36
  async function startTest() {
36
- const api = `http://localhost:${DEFAULT_PORT}/systemview/api`;
37
+ const url = `http://localhost:${DEFAULT_PORT}`;
37
38
  input.shift();
38
39
  try {
39
40
  const lineReader = await launchApp(DEFAULT_PORT);
40
41
  setTimeout(async () => {
41
- await runTests(api, ...input);
42
- if (lineReader) lineReader.prompt();
42
+ await runTests(url, ...input);
43
+ if (lineReader) {
44
+ lineReader.prompt();
45
+ } else {
46
+ process.exit(0);
47
+ }
43
48
  }, 0);
44
49
  } catch (error) {
45
50
  console.error("Error executing tests:", error.message);
@@ -47,15 +52,16 @@ async function startTest() {
47
52
  }
48
53
 
49
54
  async function open() {
50
- const port = isNaN(input[1]) ? DEFAULT_PORT : input[1];
55
+ const project_code = input[1];
56
+ const namespace = input[2];
51
57
  const ui = `http://localhost:${DEFAULT_PORT}`;
52
58
  const api = `${ui}/systemview/api`;
53
59
  if (await appIsRunning(api)) {
54
- openBrowser(ui);
60
+ openBrowser(ui, project_code, namespace);
55
61
  process.exit(0);
56
62
  } else {
57
- await launchApp(port);
58
- openBrowser(ui);
63
+ await launchApp(DEFAULT_PORT);
64
+ openBrowser(ui, project_code, namespace);
59
65
  }
60
66
  }
61
67
  async function quitApp() {
@@ -93,7 +99,7 @@ async function quitApp() {
93
99
  cli.showHelp(0);
94
100
  } else if (input.includes("test")) {
95
101
  startTest();
96
- } else if (["exit", "q", "shutdown"].includes(input[0])) {
102
+ } else if (["exit", "q", "shutdown", "stop"].includes(input[0])) {
97
103
  quitApp();
98
104
  } else if (input[0] === "start") {
99
105
  startApp();
package/cli/launchApp.js CHANGED
@@ -9,7 +9,7 @@ module.exports = async function launchApp(port) {
9
9
  function logConnection() {
10
10
  log("connected!", "success");
11
11
  console.log(`SystemView UI running @${ui}`);
12
- console.log(`SystemView API running @${api}`);
12
+ console.log(`SystemView API running @${api}\n`);
13
13
  }
14
14
 
15
15
  if (await appIsRunning(api)) {
@@ -1,14 +1,16 @@
1
1
  const { exec } = require("child_process");
2
2
 
3
- module.exports = function openBrowser(url) {
3
+ module.exports = function openBrowser(url, project_code, namespace) {
4
4
  if (!url || typeof url !== "string" || url.trim() === "") {
5
5
  console.error("Invalid URL provided");
6
6
  return;
7
7
  }
8
8
 
9
9
  const browserCommand = process.platform === "win32" ? "start" : "open";
10
-
11
- exec(`${browserCommand} ${url}`, (error, stdout, stderr) => {
10
+ const code = project_code ? "/" + project_code : "";
11
+ const nsp = code && namespace ? "/" + namespace.replace(/\./g, "/") : "";
12
+ console.log(`opening... ${url}${code}${nsp}`);
13
+ exec(`${browserCommand} ${url}${code}${nsp}`, (error, stdout, stderr) => {
12
14
  if (error) {
13
15
  console.error(`Failed to open browser: ${error.message}`);
14
16
  } else if (stderr) {
package/cli/runTests.js CHANGED
@@ -6,17 +6,14 @@ const validationMessages = require("../testing-utilities/validtionMessages");
6
6
  const { runFullTest } = new FullTestController();
7
7
 
8
8
  const PARTITION =
9
- "-------------------------------------------------------------------------";
9
+ "-----------------------------------------------------------------------------";
10
10
 
11
- module.exports = async function runTests(
12
- api,
13
- project_code,
14
- namespace,
15
- printAll,
16
- trackTime
17
- ) {
11
+ module.exports = async function runTests(url, project_code, namespace) {
12
+ const api = `${url}/systemview/api`;
18
13
  if (!project_code) {
19
- return log("project_code or service_url are required", "warning", "warning");
14
+ log("project_code and/or service_url are required", "warning", "warning");
15
+ console.log(`Example -> systemview test myAPI Users`);
16
+ return;
20
17
  }
21
18
  // get connected services from the systemview api
22
19
  const connectedServices = await getConnectedServices(api, project_code);
@@ -34,7 +31,6 @@ module.exports = async function runTests(
34
31
  }
35
32
 
36
33
  const testsReceived = await getTests(connectedServices);
37
-
38
34
  const testToRun = !namespace
39
35
  ? testsReceived
40
36
  : testsReceived
@@ -46,61 +42,71 @@ module.exports = async function runTests(
46
42
  .filter((testList) => testList.length);
47
43
 
48
44
  if (testToRun.length) {
49
- const executeTest = async (savedTests) => {
50
- const tests = initializeSavedTests(savedTests, connectedServices);
51
- await runAllTests(tests, trackTime);
52
- };
53
-
45
+ const summary = {};
54
46
  await new Promise((resolve) => {
55
47
  async function recursiveExecuteTest(i = 0) {
56
48
  if (i === testToRun.length) resolve();
57
49
  else {
58
50
  const { serviceId } = testToRun[i][0].namespace;
59
51
  log(`Initializing Tests...`, "info", serviceId);
60
- executeTest(testToRun[i]).then(() => recursiveExecuteTest(i + 1));
52
+
53
+ try {
54
+ const tests = initializeSavedTests(testToRun[i], connectedServices);
55
+ summary[serviceId] = await runAllTests(tests, url, project_code);
56
+ } catch (error) {
57
+ log(`Unexpected error halting test`, "error", serviceId);
58
+ } finally {
59
+ recursiveExecuteTest(i + 1);
60
+ }
61
61
  }
62
62
  }
63
63
  recursiveExecuteTest();
64
64
  });
65
+ console.log(PARTITION);
66
+ console.log(PARTITION);
67
+ log("TEST COMPLETE!", "info");
68
+ for (let key in summary) {
69
+ const { passed, failed } = summary[key];
70
+ log(
71
+ `tests: ${passed + failed}, passed: ${passed}, failed: ${failed}`,
72
+ failed ? "error" : "success",
73
+ key
74
+ );
75
+ }
65
76
  } else {
66
77
  log(`No tests found matching ${project_code} ${namespace}`, "warning", "warning");
67
78
  }
68
79
  };
69
80
 
70
- const Logger = function (trackTime) {
71
- this.start = (test) => {
72
- // if (trackTime) {
73
- // console.log
74
- // }
75
- };
76
-
77
- this.end = ({ errors, results, namespace, title }) => {
78
- // const { moduleName, methodName, serviceId } = namespace;
79
- // if (errors.length) {
80
- // log(title, "error", "failed");
81
- // console.error(results);
82
- // errors.forEach((err) => console.log(validationMessages(err)));
83
- // } else {
84
- // log(title, "success", "passed");
85
- // console.log(`${serviceId}.${moduleName}.${methodName}(...)`);
86
- // }
87
- };
88
- };
89
-
90
- const runAllTests = async (savedTest, trackTime) => {
81
+ const runAllTests = async (savedTest, url, project_code) => {
82
+ const sum = { passed: 0, failed: 0 };
91
83
  const runTest = async ({ Before, Main, Events, After }) => {
92
84
  const fullTest = [Before, Main, Events, After];
93
- await runFullTest(fullTest, new Logger(trackTime));
94
85
  const { namespace } = Main[0];
95
- const { moduleName, methodName } = namespace;
86
+ const { moduleName, methodName, serviceId } = namespace;
96
87
 
97
- log(`Testing: ${moduleName}.${methodName}(...)`, "info", namespace.serviceId);
98
88
  console.log(PARTITION);
89
+ log(
90
+ `testing -> ${serviceId}.${moduleName}.${methodName}(...)`,
91
+ "info",
92
+ namespace.serviceId
93
+ );
94
+ console.log(
95
+ `systemview ui -> @${url}/${project_code}/${serviceId}/${moduleName}/${methodName}`
96
+ );
99
97
  console.log(PARTITION);
100
- logTestSection(Before, "Before");
101
- logTestSection(Main, "Main", true);
102
- logTestSection(Events, "Events");
103
- logTestSection(After, "After");
98
+
99
+ await runFullTest(fullTest);
100
+ if (
101
+ logResults(Before, "Before") +
102
+ logResults(Main, "Main", true) +
103
+ logResults(Events, "Events") +
104
+ logResults(After, "After")
105
+ ) {
106
+ sum.failed++;
107
+ } else {
108
+ sum.passed++;
109
+ }
104
110
  };
105
111
 
106
112
  await new Promise((resolve) => {
@@ -110,21 +116,27 @@ const runAllTests = async (savedTest, trackTime) => {
110
116
  }
111
117
  recursiveRunTest();
112
118
  });
113
- };
114
119
 
115
- function logTestSection(tests, section, logSuccess = false) {
116
- tests.forEach(({ errors, results, namespace, title, response_type }, i) => {
120
+ return sum;
121
+ };
122
+ function logResults(tests, section, logSuccess = false) {
123
+ let failed = 0;
124
+ tests.forEach(({ errors, results, namespace, title, response_type }) => {
117
125
  const { serviceId, moduleName, methodName } = namespace;
118
126
  const LOG_TYPE = errors.length ? "error" : "success";
119
127
  const LABEL = LOG_TYPE === "error" ? "FAILED" : "PASSED";
128
+
120
129
  if (LOG_TYPE === "error" || logSuccess) {
121
130
  log(title, "info", section + ":");
122
131
  log(`${serviceId}.${moduleName}.${methodName}(...)`, LOG_TYPE, `${LABEL}`);
123
132
  console.log(`${response_type}:`, results);
133
+ errors.length && log(`${errors.length} errors`, "warning", "validations");
124
134
  errors.forEach((err) => console.log(`-> ${validationMessages(err)}`));
125
135
  console.log(PARTITION);
136
+ if (!failed && errors.length) failed = 1;
126
137
  }
127
138
  });
139
+ return failed;
128
140
  }
129
141
  async function getTests(connectedServices) {
130
142
  return await new Promise(async (resolve) => {
@@ -136,7 +148,7 @@ async function getTests(connectedServices) {
136
148
  try {
137
149
  results.push(await Client.createService(connectionData).Plugin.getTests());
138
150
  } catch (error) {
139
- console.log(`Failed to retrieve test from:${connectionData.serviceUrl}`);
151
+ console.log(`Failed to retrieve test from:${connectionData.serviceUrl}:\n`);
140
152
  }
141
153
 
142
154
  await recursiveGetTests(i + 1);
@@ -3,8 +3,7 @@ const cli = require("./utils/cli");
3
3
  const openBrowser = require("./openBrowser");
4
4
  const readline = require("readline");
5
5
 
6
- module.exports = function startLineReader(ui) {
7
- const api = `${ui}/systemview/api`;
6
+ module.exports = function startLineReader(url) {
8
7
  const lineReader = readline.createInterface({
9
8
  input: process.stdin,
10
9
  output: process.stdout,
@@ -12,18 +11,18 @@ module.exports = function startLineReader(ui) {
12
11
  const handleInput = (input = "") => {
13
12
  const args = input.split(" ").map((s) => s.trim());
14
13
  const command = args.shift();
15
- if (["exit", "q", "shutdown"].includes(command)) {
14
+ if (["exit", "q", "shutdown", "stop"].includes(command)) {
16
15
  process.exit(0);
17
16
  } else if (command === "test") {
18
17
  try {
19
- runTests(api, ...args);
18
+ runTests(url, ...args);
20
19
  } catch (error) {
21
20
  console.error("Error executing tests:", error.message);
22
21
  }
23
22
  } else if (command === "help") {
24
23
  cli.showHelp(0);
25
24
  } else if (command === "open") {
26
- openBrowser(ui);
25
+ openBrowser(url, ...args);
27
26
  }
28
27
  lineReader.prompt();
29
28
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "systemview",
3
3
  "description": "A documentation and testing suite for SystemLynx",
4
- "version": "1.11.8",
4
+ "version": "1.12.8",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
7
7
  "systemview": "cli/index.js"
@@ -30,7 +30,7 @@
30
30
  "react-syntax-highlighter": "^15.5.0",
31
31
  "readline": "^1.3.0",
32
32
  "remark-gfm": "^3.0.1",
33
- "systemlynx": "^1.10.6",
33
+ "systemlynx": "^1.11.8",
34
34
  "web-vitals": "^0.2.4"
35
35
  },
36
36
  "scripts": {
@@ -3,13 +3,13 @@ const Test = require("./Test.class");
3
3
  const sections = ["Before", "Main", "Events", "After"];
4
4
 
5
5
  module.exports = function FullTestController({ FullTest, connectedServices } = {}) {
6
- this.runFullTest = async ([Before, Main, Events, After] = FullTest || [], Logger) => {
7
- Events.forEach((test) => test.runTest(Logger));
6
+ this.runFullTest = async ([Before, Main, Events, After] = FullTest || []) => {
7
+ Events.forEach((test) => test.runTest());
8
8
 
9
9
  await new Promise((resolve) => {
10
10
  function recursiveRunTest(tests, i = 0) {
11
11
  if (i === tests.length) resolve();
12
- else tests[i].runTest(Logger).then(() => recursiveRunTest(tests, i + 1));
12
+ else tests[i].runTest().then(() => recursiveRunTest(tests, i + 1));
13
13
  }
14
14
  recursiveRunTest([...Before, ...Main, ...After]);
15
15
  });
@@ -11,6 +11,7 @@ module.exports = function Test({
11
11
  savedEvaluations = [],
12
12
  index,
13
13
  editMode = true,
14
+ logger,
14
15
  }) {
15
16
  this.index = index;
16
17
  this.connection = {};
@@ -49,8 +50,7 @@ module.exports = function Test({
49
50
 
50
51
  this.validate = validateResults.bind(this);
51
52
 
52
- this.runTest = async (_logger) => {
53
- const logger = _logger || new TestLogger(this);
53
+ this.runTest = async () => {
54
54
  const { serviceId, moduleName, methodName } = this.namespace;
55
55
  const args = this.args.map((arg) => arg.value());
56
56
 
@@ -62,25 +62,25 @@ module.exports = function Test({
62
62
  this.test_end = moment().toJSON();
63
63
  this.response_type = "event";
64
64
  this.shouldValidate && this.validate();
65
- logger.end(this);
65
+ if (logger) logger.end(this);
66
66
  Module.$clearEvent(args[0], "eventTest");
67
67
  };
68
- logger.start(args);
68
+ if (logger) logger.start(args);
69
69
  Module.on(args[0], eventTest);
70
70
  } else {
71
71
  try {
72
- logger.start(args);
72
+ if (logger) logger.start(args);
73
73
  this.results = await Module[methodName](...args);
74
74
  this.test_end = moment().toJSON();
75
75
  this.response_type = "results";
76
76
  this.shouldValidate && this.validate();
77
- logger.end(this);
77
+ if (logger) logger.end(this);
78
78
  } catch (error) {
79
79
  this.test_end = moment().toJSON();
80
80
  this.results = error;
81
81
  this.response_type = "error";
82
82
  this.shouldValidate && this.validate();
83
- logger.end(this);
83
+ if (logger) logger.end(this);
84
84
  }
85
85
  }
86
86
  return this;
@@ -137,27 +137,3 @@ module.exports = function Test({
137
137
  );
138
138
  };
139
139
  };
140
-
141
- function TestLogger(test) {
142
- this.start = (args) => {
143
- const { serviceId, moduleName, methodName } = test.namespace;
144
-
145
- console.log(
146
- `[${moment(this.test_start).format(
147
- "L LTS"
148
- )}]> [invoking]:${serviceId}.${moduleName}.${methodName}()`
149
- );
150
- console.log.apply({}, ["args:"].concat(args));
151
- };
152
- this.end = () => {
153
- const { serviceId, moduleName, methodName } = test.namespace;
154
- const { results, response_type } = test;
155
- console.log(
156
- `[${moment(this.test_end).format(
157
- "L LTS"
158
- )}]> [${response_type}]:${serviceId}.${moduleName}.${methodName}()`,
159
- `${response_type}:`,
160
- results
161
- );
162
- };
163
- }
@@ -9,37 +9,36 @@ module.exports = function validationMessage({ name, namespace, expected, receive
9
9
  return errorMessages[name](namespace, expected, received);
10
10
  };
11
11
  const errorMessages = {
12
- typeError: (namespace, expected, received) => {
13
- const a = isVowel(expected) ? "an" : "a";
14
- return `Expected ${namespace} to be ${a} ${expected}, received ${received}`;
15
- },
16
-
12
+ typeError: (namespace, expected, received) =>
13
+ `Expected ${namespace} to be ${an(expected)} ${expected}, but received ${an(
14
+ received
15
+ )} ${received}`,
17
16
  lengthEquals: (namespace, expected, received) =>
18
- `Expected ${namespace} to have a length of ${expected}, received ${received}`,
17
+ `Expected ${namespace} to have a length of ${expected}, but received ${received}`,
19
18
  maxLength: (namespace, expected, received) =>
20
- `Expected ${namespace} to have a maximum length of ${expected}, received ${received}`,
19
+ `Expected ${namespace} to have a maximum length of ${expected}, but received ${received}`,
21
20
  minLength: (namespace, expected, received) =>
22
- `Expected ${namespace} to have a minimum length of ${expected}, received ${received}`,
21
+ `Expected ${namespace} to have a minimum length of ${expected}, but received ${received}`,
23
22
  includes: (namespace, expected, received) =>
24
- `Expected ${namespace} to include the following value: ${expected}, received ${received}`,
23
+ `Expected ${namespace} to include the following value: ${expected}, but received ${received}`,
25
24
  isLike: (namespace, expected, received) =>
26
- `Expected ${namespace} to be like the following expression: ${expected}, received ${received}`,
25
+ `Expected ${namespace} to be like the following expression: ${expected}, but received ${received}`,
27
26
  isOneOf: (namespace, expected, received) =>
28
- `Expected ${namespace} to be one of the following values: ${expected}, received ${received}`,
27
+ `Expected ${namespace} to be one of the following values: ${expected}, but received ${received}`,
29
28
  strEquals: (namespace, expected, received) =>
30
- `Expected ${namespace} to equal "${expected}"`,
29
+ `Expected ${namespace} to equal "${expected}" but received "${received}"`,
31
30
  numEquals: (namespace, expected, received) =>
32
- `Expected ${namespace} to equal ${expected}, received ${received}`,
31
+ `Expected ${namespace} to equal ${expected}, but received ${received}`,
33
32
  max: (namespace, expected, received) =>
34
- `Expected ${namespace} to be less than ${expected}, received ${received}`,
33
+ `Expected ${namespace} to be less than ${expected}, but received ${received}`,
35
34
  min: (namespace, expected, received) =>
36
- `Expected ${namespace} to be greater than ${expected}, received ${received}`,
35
+ `Expected ${namespace} to be greater than ${expected}, but received ${received}`,
37
36
  boolEquals: (namespace, expected, received) =>
38
- `Expected ${namespace} to be ${expected.toString()}`,
37
+ `Expected ${namespace} to be ${expected}, but received ${received}`,
39
38
  dateEquals: (namespace, expected, received) =>
40
- `Expected ${namespace} to be ${moment(expected).format()}`,
39
+ `Expected ${namespace} to be ${expected}, but received ${received}`,
41
40
  minDate: (namespace, expected, received) =>
42
- `Expected ${namespace} to be a date/time later than ${expected}, received ${received}`,
41
+ `Expected ${namespace} to be a date/time later than ${expected}, but received ${received}`,
43
42
  maxDate: (namespace, expected, received) =>
44
- `Expected ${namespace} to be a date/time earlier than ${expected}, received ${received}`,
43
+ `Expected ${namespace} to be a date/time earlier than ${expected}, but received ${received}`,
45
44
  };