add ava for testing upend.js
parent
a33943bdb7
commit
bf4e0efd2c
|
@ -3,12 +3,14 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Client library to interact with the UpEnd system.",
|
"description": "Client library to interact with the UpEnd system.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc"
|
"build": "tsc",
|
||||||
|
"test": "ava"
|
||||||
},
|
},
|
||||||
"author": "Tomáš Mládek <t@mldk.cz>",
|
"author": "Tomáš Mládek <t@mldk.cz>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"ava": "^3.15.0",
|
||||||
"typescript": "^4.4.4"
|
"typescript": "^4.4.4"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@3.1.0"
|
"packageManager": "yarn@3.1.1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
import test from "ava";
|
||||||
|
import http from "http";
|
||||||
|
import { asDict, listingAsOrdered } from ".";
|
||||||
|
import { ListingResult, OrderedListing } from "./types";
|
||||||
|
|
||||||
|
function fetchJSON(url: string): Promise<unknown> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
http
|
||||||
|
.get(url, (res) => {
|
||||||
|
let data = "";
|
||||||
|
|
||||||
|
res.on("data", (chunk) => {
|
||||||
|
data += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on("end", () => {
|
||||||
|
resolve(JSON.parse(data));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("error", (error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test("my passing test", async (t) => {
|
||||||
|
const data = (await fetchJSON(
|
||||||
|
"http://localhost:8093/api/hier/NATIVE"
|
||||||
|
)) as ListingResult;
|
||||||
|
|
||||||
|
console.log(asDict(Object.values(data)));
|
||||||
|
|
||||||
|
t.pass();
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue