Skip to content

Commit

Permalink
test: port test-format to typescript
Browse files Browse the repository at this point in the history
This was pretty much completely pain-free, with a minor exception: the
test overrides the `cockpit.language` attribute, which we would
otherwise probably declare as `const`.
  • Loading branch information
allisonkarlitskaya committed Apr 18, 2024
1 parent 2c907d4 commit 9fd6155
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion files.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const info = {
"base1/test-events.js",
"base1/test-external.js",
"base1/test-file.js",
"base1/test-format.js",
"base1/test-format.ts",
"base1/test-framed-cache.js",
"base1/test-framed.js",
"base1/test-http.js",
Expand Down
8 changes: 4 additions & 4 deletions pkg/base1/test-format.js → pkg/base1/test-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ QUnit.test("format_number", function (assert) {
[-123.01, "-123", "-123"],
[null, "", ""],
[undefined, "", ""],
];
] as const;

const saved_language = cockpit.language;

Expand Down Expand Up @@ -101,7 +101,7 @@ QUnit.test("format_bytes", function (assert) {
[0, "KB", "0 KB"],
[undefined, "KB", ""],
[null, "KB", ""],
];
] as const;

for (let i = 0; i < checks.length; i++) {
if (typeof checks[i][1] === 'string') {
Expand Down Expand Up @@ -150,7 +150,7 @@ QUnit.test("format_bytes_per_sec", function (assert) {
// significant integer digits exceed custom precision
[25555000, "kB/s", { precision: 2 }, "25555 kB/s"],
[25555678, "kB/s", { precision: 2 }, "25556 kB/s"],
];
] as const;

for (let i = 0; i < checks.length; i++) {
if (typeof checks[i][1] === 'string') {
Expand Down Expand Up @@ -185,7 +185,7 @@ QUnit.test("format_bits_per_sec", function (assert) {
[2555, "2.56 Kbps"],
[2000, "2 Kbps"],
[2003, "2.00 Kbps"]
];
] as const;

assert.expect(checks.length);
for (let i = 0; i < checks.length; i++) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/lib/cockpit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ declare module 'cockpit' {

function assert(predicate: unknown, message?: string): asserts predicate;

export let language: string;

/* === Events mix-in ========================= */

interface EventMap {
Expand Down

0 comments on commit 9fd6155

Please sign in to comment.