mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Start testing website (#813)
This commit is contained in:
parent
c124db4701
commit
17a7b03d1b
4 changed files with 132 additions and 21 deletions
|
@ -17,3 +17,5 @@ import "./symlink_test.ts";
|
||||||
import "./platform_test.ts";
|
import "./platform_test.ts";
|
||||||
import "./text_encoding_test.ts";
|
import "./text_encoding_test.ts";
|
||||||
import "./trace_test.ts";
|
import "./trace_test.ts";
|
||||||
|
|
||||||
|
import "../website/app_test.js";
|
||||||
|
|
|
@ -1,18 +1,46 @@
|
||||||
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
export async function getJson(path) {
|
||||||
|
return (await fetch(path)).json();
|
||||||
|
}
|
||||||
|
|
||||||
const benchmarkNames = ["hello", "relative_import"];
|
const benchmarkNames = ["hello", "relative_import"];
|
||||||
|
export function createExecTimeColumns(data) {
|
||||||
(async () => {
|
return benchmarkNames.map(name => [
|
||||||
const data = await (await fetch("./data.json")).json();
|
|
||||||
|
|
||||||
const execTimeColumns = benchmarkNames.map(name => [
|
|
||||||
name,
|
name,
|
||||||
...data.map(d => {
|
...data.map(d => {
|
||||||
const benchmark = d.benchmark[name];
|
const benchmark = d.benchmark[name];
|
||||||
return benchmark ? benchmark.mean : 0;
|
const meanValue = benchmark ? benchmark.mean : 0;
|
||||||
|
return meanValue || 0;
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
const binarySizeList = data.map(d => d.binary_size || 0);
|
export function createBinarySizeColumns(data) {
|
||||||
const sha1List = data.map(d => d.sha1);
|
return [["binary_size", ...data.map(d => d.binary_size || 0)]];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createSha1List(data) {
|
||||||
|
return data.map(d => d.sha1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Formats the byte sizes e.g. 19000 -> 18.55 KB
|
||||||
|
// Copied from https://stackoverflow.com/a/18650828
|
||||||
|
export function formatBytes(a, b) {
|
||||||
|
if (0 == a) return "0 Bytes";
|
||||||
|
var c = 1024,
|
||||||
|
d = b || 2,
|
||||||
|
e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
|
||||||
|
f = Math.floor(Math.log(a) / Math.log(c));
|
||||||
|
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function main() {
|
||||||
|
const data = await getJson("./data.json");
|
||||||
|
|
||||||
|
const execTimeColumns = createExecTimeColumns(data);
|
||||||
|
const binarySizeColumns = createBinarySizeColumns(data);
|
||||||
|
const sha1List = createSha1List(data);
|
||||||
|
|
||||||
c3.generate({
|
c3.generate({
|
||||||
bindto: "#exec-time-chart",
|
bindto: "#exec-time-chart",
|
||||||
|
@ -27,7 +55,7 @@ const benchmarkNames = ["hello", "relative_import"];
|
||||||
|
|
||||||
c3.generate({
|
c3.generate({
|
||||||
bindto: "#binary-size-chart",
|
bindto: "#binary-size-chart",
|
||||||
data: { columns: [["binary_size", ...binarySizeList]] },
|
data: { columns: binarySizeColumns },
|
||||||
axis: {
|
axis: {
|
||||||
x: {
|
x: {
|
||||||
type: "category",
|
type: "category",
|
||||||
|
@ -40,15 +68,4 @@ const benchmarkNames = ["hello", "relative_import"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
|
||||||
|
|
||||||
// Formats the byte sizes e.g. 19000 -> 18.55KB
|
|
||||||
// Copied from https://stackoverflow.com/a/18650828
|
|
||||||
function formatBytes(a, b) {
|
|
||||||
if (0 == a) return "0 Bytes";
|
|
||||||
var c = 1024,
|
|
||||||
d = b || 2,
|
|
||||||
e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
|
|
||||||
f = Math.floor(Math.log(a) / Math.log(c));
|
|
||||||
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
|
|
||||||
}
|
}
|
||||||
|
|
89
website/app_test.js
Normal file
89
website/app_test.js
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
import { test, testPerm, assertEqual } from "../js/test_util.ts";
|
||||||
|
import {
|
||||||
|
createBinarySizeColumns,
|
||||||
|
createExecTimeColumns,
|
||||||
|
createSha1List,
|
||||||
|
formatBytes
|
||||||
|
} from "./app.js";
|
||||||
|
|
||||||
|
const regularData = [
|
||||||
|
{
|
||||||
|
created_at: "2018-01-01T01:00:00Z",
|
||||||
|
sha1: "abcdef",
|
||||||
|
binary_size: 100000000,
|
||||||
|
benchmark: {
|
||||||
|
hello: {
|
||||||
|
mean: 0.05
|
||||||
|
},
|
||||||
|
relative_import: {
|
||||||
|
mean: 0.06
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
created_at: "2018-01-02T01:00:00Z",
|
||||||
|
sha1: "012345",
|
||||||
|
binary_size: 110000000,
|
||||||
|
benchmark: {
|
||||||
|
hello: {
|
||||||
|
mean: 0.055
|
||||||
|
},
|
||||||
|
relative_import: {
|
||||||
|
mean: 0.065
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const irregularData = [
|
||||||
|
{
|
||||||
|
created_at: "2018-01-01T01:00:00Z",
|
||||||
|
sha1: "123",
|
||||||
|
benchmark: {
|
||||||
|
hello: {},
|
||||||
|
relative_import: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
created_at: "2018-02-01T01:00:00Z",
|
||||||
|
sha1: "456",
|
||||||
|
benchmark: {}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
test(function createExecTimeColumnsRegularData() {
|
||||||
|
const columns = createExecTimeColumns(regularData);
|
||||||
|
assertEqual(columns, [
|
||||||
|
["hello", 0.05, 0.055],
|
||||||
|
["relative_import", 0.06, 0.065]
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function createExecTimeColumnsIrregularData() {
|
||||||
|
const columns = createExecTimeColumns(irregularData);
|
||||||
|
assertEqual(columns, [["hello", 0, 0], ["relative_import", 0, 0]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function createBinarySizeColumnsRegularData() {
|
||||||
|
const columns = createBinarySizeColumns(regularData);
|
||||||
|
assertEqual(columns, [["binary_size", 100000000, 110000000]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function createBinarySizeColumnsIrregularData() {
|
||||||
|
const columns = createBinarySizeColumns(irregularData);
|
||||||
|
assertEqual(columns, [["binary_size", 0, 0]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function createSha1ListRegularData() {
|
||||||
|
const sha1List = createSha1List(regularData);
|
||||||
|
assertEqual(sha1List, ["abcdef", "012345"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function formatBytesPatterns() {
|
||||||
|
assertEqual(formatBytes(18000), "17.58 KB");
|
||||||
|
assertEqual(formatBytes(1800000), "1.72 MB");
|
||||||
|
assertEqual(formatBytes(180000000), "171.66 MB");
|
||||||
|
assertEqual(formatBytes(18000000000), "16.76 GB");
|
||||||
|
});
|
|
@ -11,7 +11,10 @@
|
||||||
<div id="binary-size-chart"></div>
|
<div id="binary-size-chart"></div>
|
||||||
<script src="https://unpkg.com/d3@5.7.0/dist/d3.min.js"></script>
|
<script src="https://unpkg.com/d3@5.7.0/dist/d3.min.js"></script>
|
||||||
<script src="https://unpkg.com/c3@0.6.7/c3.min.js"></script>
|
<script src="https://unpkg.com/c3@0.6.7/c3.min.js"></script>
|
||||||
<script src="./app.js"></script>
|
<script type="module">
|
||||||
|
import { main } from "./app.js";
|
||||||
|
main();
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue