Skip to content

Commit

Permalink
Set log timestamps as relative to start of execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Terando committed Oct 6, 2024
1 parent 887a356 commit 792bfe8
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 102 deletions.
4 changes: 2 additions & 2 deletions @apicize/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions @apicize/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apicize-run"
version = "0.6.2"
version = "0.6.3"
description = "Apicize CLI test runner"
authors = ["Apicize"]
license = "MIT"
Expand All @@ -11,7 +11,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
apicize_lib = { path = "../lib-rust", version = "^0.6.2" }
apicize_lib = { path = "../lib-rust", version = "^0.6.3" }
clap = { version = "4.5.18", features = ["derive"] }
colored = "2.1.0"
num-format = { version = "0.4.4", features = ["with-system-locale"] }
Expand Down
2 changes: 1 addition & 1 deletion @apicize/lib-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @apicize/lib-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUST_BACKTRACE = "0"

[package]
name = "apicize_lib"
version = "0.6.2"
version = "0.6.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
21 changes: 15 additions & 6 deletions @apicize/lib-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,12 @@ impl Parameters {
}

impl ApicizeSettings {

fn get_settings_directory() -> path::PathBuf {
if let Some(directory) = config_dir() {
return directory.join("apicize");
} else {
panic!("Operating system did not provide configuration directory")
}

}

/// Return the file name for settings
Expand Down Expand Up @@ -288,9 +286,13 @@ impl ApicizeSettings {
/// Save Apicize common environment to the specified name in the default path
pub fn save(&self) -> Result<SerializationSaveSuccess, SerializationFailure> {
let dir = Self::get_settings_directory();
if ! Path::new(&dir).is_dir() {
if !Path::new(&dir).is_dir() {
if let Err(err) = create_dir_all(&dir) {
panic!("Unable to create {} - {}", &dir.to_string_lossy(), err.to_string());
panic!(
"Unable to create {} - {}",
&dir.to_string_lossy(),
err.to_string()
);
}
}
save_data_file(&Self::get_settings_filename(), self)
Expand Down Expand Up @@ -934,6 +936,7 @@ impl Workspace {
request: &WorkbookRequest,
response: &ApicizeResponse,
variables: &HashMap<String, Value>,
tests_started: Arc<Instant>,
) -> Result<Option<ExecutedTestResponse>, ExecutionError> {
// Create a new Isolate and make it the current one.
let isolate = &mut v8::Isolate::new(v8::CreateParams::default());
Expand All @@ -959,12 +962,17 @@ impl Workspace {
return Ok(None);
}

let cloned_tests_started = *tests_started;

let mut init_code = String::new();
init_code.push_str(&format!(
"runTestSuite({}, {}, {}, () => {{{}}})",
"runTestSuite({}, {}, {}, {}, () => {{{}}})",
serde_json::to_string(request).unwrap(),
serde_json::to_string(response).unwrap(),
serde_json::to_string(variables).unwrap(),
std::time::UNIX_EPOCH.elapsed().unwrap().as_millis()
- cloned_tests_started.elapsed().as_millis()
+ 1,
request.test.as_ref().unwrap()
));

Expand Down Expand Up @@ -1180,7 +1188,8 @@ impl Workspace {

match &dispatch_response {
Ok((request, response)) => {
let test_response = Workspace::execute_test(&info, response, &variables);
let test_response =
Workspace::execute_test(&info, response, &variables, tests_started);
match test_response {
Ok(test_results) => {
let mut test_count = 0;
Expand Down
35 changes: 26 additions & 9 deletions @apicize/lib-rust/src/static/routines.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@

let request = {};
let response = {};
let variables = {};
let testOffset = 0;
let names = [];
let inIt = false;
let results = [];
let logs = []

fmtMinSec = (value, subZero = null) => {
if (value === 0 && subZero) {
return subZero
}
const m = Math.floor(value / 60000)
value -= m * 60000
const s = Math.floor(value / 1000)
value -= s * 1000
return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}${(0.1).toString()[1]}${value.toString().padEnd(3, '0')}`
}


appendLog = (type, message, ...optionalParams) => {
logs.push(`${(new Date()).toTimeString().replace(' ()', '')} [${type}] ${format(message, ...optionalParams)}`)
const timestamp = fmtMinSec(Date.now() - testOffset)
logs.push(`${timestamp} [${type}] ${format(message, ...optionalParams)}`)
}
clearLog = () => logs = [];

Expand All @@ -13,12 +35,6 @@ console = {
debug: (msg, ...args) => appendLog('debug', msg, ...args),
};

var request = {};
var response = {};
var variables = {};
var names = [];
var inIt = false;
var results = [];

function pushResult(result) {
results.push({
Expand Down Expand Up @@ -56,11 +72,12 @@ function it(behavior, run) {
}
}

const runTestSuite = (request1, response1, variables1, testSuite) => {
const runTestSuite = (request1, response1, variables1, testOffset1, testSuite) => {
request = request1
response = response1
variables = variables1 ?? {}
console.log('variables', variables)
testOffset = testOffset1
// console.log('variables', variables)
names = []
clearLog()
results = []
Expand Down
67 changes: 0 additions & 67 deletions @apicize/lib-rust/src/static/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,3 @@ format = require('util').format;
assert = chai.assert;
expect = chai.expect;
should = chai.should;

// let logs = []
// appendLog = (type, message, ...optionalParams) => {
// // logs.push(`${(new Date()).toTimeString()} [${type}] ${format(message, ...optionalParams)}`)
// }
// clearLog = () => logs = [];

// console = {
// log: (msg, ...args) => appendLog('log', msg, ...args),
// info: (msg, ...args) => appendLog('info', msg, ...args),
// warn: (msg, ...args) => appendLog('warn', msg, ...args),
// error: (msg, ...args) => appendLog('error', msg, ...args),
// trace: (msg, ...args) => appendLog('trace', msg, ...args),
// debug: (msg, ...args) => appendLog('debug', msg, ...args),
// };

// var request = {};
// var response = {};
// var names = [];
// var inIt = false;
// var results = [];

// function pushResult(result) {
// results.push({
// ...result,
// logs: logs.length > 0 ? logs : undefined
// });
// }

// function describe(name, run) {
// names.push(name);
// try {
// run()
// } finally {
// names.pop();
// }
// }

// function it(behavior, run) {
// try {
// if (inIt) {
// throw new Error('\"it\" cannot be contained in another \"it\" block')
// }
// if (names.length === 0) {
// throw new Error('\"it\" must be contained in a \"describe\" block');
// }
// inIt = true;
// run();
// pushResult({ testName: [...names, behavior], success: true, logs });
// clearLog();
// } catch (e) {
// pushResult({ testName: [...names, behavior], success: false, error: e.message, logs })
// clearLog()
// } finally {
// inIt = false
// }
// }

// function runTestSuite(request1, response1, testSuite) {
// request = request1;
// response = response1;
// names = []
// clearLog()
// results = []
// testSuite()
// return JSON.stringify(results)
// }
2 changes: 1 addition & 1 deletion @apicize/lib-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apicize/lib-typescript",
"private": true,
"version": "0.6.2",
"version": "0.6.3",
"description": "TypeScript model definitions for Apicize",
"scripts": {
"build": "tsc",
Expand Down
4 changes: 2 additions & 2 deletions @apicize/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apicize/toolkit",
"private": true,
"version": "0.6.2",
"version": "0.6.3",
"description": "UI toolkit for Apicize applications",
"keywords": [],
"license": "MIT",
Expand Down Expand Up @@ -40,7 +40,7 @@
"mobx-react-lite": "^4.0.7"
},
"dependencies": {
"@apicize/lib-typescript": "^0.6.2",
"@apicize/lib-typescript": "^0.6.3",
"@dnd-kit/core": "^6.1.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

# 0.6.3

* Set log timestamps as relative to start of execution

# 0.6.2

* Add deployment packages for CLI
Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "0.6.2",
"version": "0.6.3",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -10,7 +10,7 @@
"tauri": "tauri"
},
"dependencies": {
"@apicize/toolkit": "^0.6.2",
"@apicize/toolkit": "^0.6.3",
"@dnd-kit/core": "^6.1.0",
"@mui/material": "^6.1.1",
"@mui/system": "^6.1.1",
Expand Down
4 changes: 2 additions & 2 deletions app/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apicize"
version = "0.6.2"
version = "0.6.3"
description = "Apicize HTTP call testing application"
authors = ["Jason Terando"]
license = ""
Expand All @@ -17,7 +17,7 @@ tauri-build = { version = "2.0.0", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
apicize_lib = { version = "0.6.2", path = "../../@apicize/lib-rust" }
apicize_lib = { version = "0.6.3", path = "../../@apicize/lib-rust" }
tauri = { version = "2.0.0", features = ["image-png"] }
tokio-util = "0.7.11"
tauri-plugin-fs = "2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../node_modules/@tauri-apps/cli/config.schema.json",
"identifier": "apicize.app",
"productName": "apicize",
"version": "0.6.2",
"version": "0.6.3",
"app": {
"security": {
"csp": null
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@tauri-apps/cli": "^2.0.0",
"concurrently": "^8.2.2",
"rimraf": "^5.0.5",
"smol-toml": "^1.3.0",
"typescript": "^5.5.4"
},
"packageManager": "[email protected]"
Expand Down
Loading

0 comments on commit 792bfe8

Please sign in to comment.