Skip to content

Commit 814de8a

Browse files
committed
tests: Convert tests to TypeScript.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent d9dbbf2 commit 814de8a

File tree

7 files changed

+58
-24
lines changed

7 files changed

+58
-24
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node-options=--experimental-strip-types

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint-js": "xo",
3232
"prettier-non-js": "prettier --check --log-level=warn . \"!**/*.{cjs,js,ts}\"",
3333
"test": "tsc && npm run lint-html && npm run lint-css && npm run lint-js && npm run prettier-non-js",
34-
"test-e2e": "vite build && tape \"tests/**/*.js\"",
34+
"test-e2e": "vite build && tape \"tests/**/*.ts\"",
3535
"pack": "vite build && electron-builder --dir",
3636
"dist": "vite build && electron-builder",
3737
"mas": "vite build && electron-builder --mac mas"
@@ -162,8 +162,10 @@
162162
"@types/backoff": "^2.5.2",
163163
"@types/i18n": "^0.13.1",
164164
"@types/node": "^22.13.10",
165+
"@types/p-fifo": "^1.0.2",
165166
"@types/requestidlecallback": "^0.3.4",
166167
"@types/semver": "^7.5.8",
168+
"@types/tape": "^5.8.1",
167169
"@types/yaireo__tagify": "^4.3.2",
168170
"@yaireo/tagify": "^4.5.0",
169171
"adm-zip": "^0.5.5",

tests/index.js renamed to tests/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import Fifo from "p-fifo";
2+
import type {Page} from "playwright-core";
23
import test from "tape";
34

4-
import * as setup from "./setup.js";
5+
import * as setup from "./setup.ts";
56

67
test("app runs", async (t) => {
78
t.timeoutAfter(10e3);
89
setup.resetTestDataDirectory();
910
const app = await setup.createApp();
1011
try {
11-
const windows = new Fifo();
12-
for (const win of app.windows()) windows.push(win);
13-
app.on("window", (win) => windows.push(win));
12+
const windows = new Fifo<Page>();
13+
for (const win of app.windows()) void windows.push(win);
14+
app.on("window", async (win) => windows.push(win));
1415

1516
const mainWindow = await windows.shift();
1617
t.equal(await mainWindow.title(), "Zulip");
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
import fs from "node:fs";
2+
import os from "node:os";
23
import path from "node:path";
34
import process from "node:process";
45

5-
import {_electron} from "playwright-core";
6+
import {type ElectronApplication, _electron} from "playwright-core";
7+
import z from "zod";
68

7-
const testsPackage = JSON.parse(
8-
fs.readFileSync(new URL("package.json", import.meta.url), "utf8"),
9-
);
9+
const testsPackage = z
10+
.object({productName: z.string()})
11+
.parse(
12+
JSON.parse(
13+
fs.readFileSync(new URL("package.json", import.meta.url), "utf8"),
14+
),
15+
);
1016

1117
// Runs Zulip Desktop.
1218
// Returns a promise that resolves to an Electron Application once the app has loaded.
13-
export function createApp() {
19+
export async function createApp(): Promise<ElectronApplication> {
1420
return _electron.launch({
1521
args: [import.meta.dirname], // Ensure this dir has a package.json file with a 'main' entry point
1622
});
1723
}
1824

1925
// Quit the app, end the test
20-
export async function endTest(app) {
26+
export async function endTest(app: ElectronApplication): Promise<void> {
2127
await app.close();
2228
}
2329

24-
function getAppDataDirectory() {
30+
function getAppDataDirectory(): string {
2531
let base;
2632

2733
switch (process.platform) {
2834
case "darwin": {
29-
base = path.join(process.env.HOME, "Library", "Application Support");
35+
base = path.join(os.homedir(), "Library", "Application Support");
3036
break;
3137
}
3238

3339
case "linux": {
34-
base =
35-
process.env.XDG_CONFIG_HOME ?? path.join(process.env.HOME, ".config");
40+
base = process.env.XDG_CONFIG_HOME ?? path.join(os.homedir(), ".config");
3641
break;
3742
}
3843

3944
case "win32": {
4045
base = process.env.APPDATA;
46+
if (base === undefined)
47+
throw new Error("Missing APPDATA environment variable.");
4148
break;
4249
}
4350

@@ -51,7 +58,7 @@ function getAppDataDirectory() {
5158
}
5259

5360
// Resets the test directory, containing domain.json, window-state.json, etc
54-
export function resetTestDataDirectory() {
61+
export function resetTestDataDirectory(): void {
5562
const appDataDirectory = getAppDataDirectory();
5663
fs.rmSync(appDataDirectory, {force: true, recursive: true});
5764
}

tests/test-add-organization.js renamed to tests/test-add-organization.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import Fifo from "p-fifo";
2+
import type {Page} from "playwright-core";
23
import test from "tape";
34

4-
import * as setup from "./setup.js";
5+
import * as setup from "./setup.ts";
56

67
test("add-organization", async (t) => {
78
t.timeoutAfter(50e3);
89
setup.resetTestDataDirectory();
910
const app = await setup.createApp();
1011
try {
11-
const windows = new Fifo();
12-
for (const win of app.windows()) windows.push(win);
13-
app.on("window", (win) => windows.push(win));
12+
const windows = new Fifo<Page>();
13+
for (const win of app.windows()) void windows.push(win);
14+
app.on("window", async (win) => windows.push(win));
1415

1516
const mainWindow = await windows.shift();
1617
t.equal(await mainWindow.title(), "Zulip");

tests/test-new-organization.js renamed to tests/test-new-organization.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Fifo from "p-fifo";
2+
import type {Page} from "playwright-core";
23
import test from "tape";
34

4-
import * as setup from "./setup.js";
5+
import * as setup from "./setup.ts";
56

67
// Create new org link should open in the default browser [WIP]
78

@@ -10,9 +11,9 @@ test("new-org-link", async (t) => {
1011
setup.resetTestDataDirectory();
1112
const app = await setup.createApp();
1213
try {
13-
const windows = new Fifo();
14-
for (const win of app.windows()) windows.push(win);
15-
app.on("window", (win) => windows.push(win));
14+
const windows = new Fifo<Page>();
15+
for (const win of app.windows()) void windows.push(win);
16+
app.on("window", async (win) => windows.push(win));
1617

1718
const mainWindow = await windows.shift();
1819
t.equal(await mainWindow.title(), "Zulip");

0 commit comments

Comments
 (0)