Skip to content

Commit 746d72a

Browse files
committed
Type fixes and imports
1 parent 067f326 commit 746d72a

8 files changed

+51
-23
lines changed

src/__tests__/local-cli.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { main } from "@/cli/browserstack-local.ts";
22
import { env } from "@/env.ts";
33
import { beforeAll, beforeEach, describe, expect, test } from "vitest";
4-
import { BrowserStackTestContext } from "./setup";
4+
import { BrowserStackTestContext } from "./setup.ts";
55

66
describe("LocalCLI", () => {
77
beforeAll(() => {

src/__tests__/local.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { components } from "@/generated/openapi.ts";
33
import { LocalTestingBinary } from "@/local-testing-binary.ts";
44
import { unlink } from "node:fs/promises";
55
import { join } from "node:path";
6+
import process from "node:process";
67
import { beforeAll, describe, expect, expectTypeOf, test } from "vitest";
78
import type { BrowserStackTestContext } from "./setup.ts";
89

@@ -59,4 +60,14 @@ describe("LocalClient", () => {
5960
// expect(data).toMatch(/successfully disconnected/i);
6061
expectTypeOf(data).toMatchTypeOf<string>();
6162
});
63+
64+
test.skip<BrowserStackTestContext>("downloadBinary-darwin-x64", async ({
65+
localTesting: { client },
66+
}) => {
67+
const { content, filename } = await client.downloadBinary("darwin-x64");
68+
expect(content).toBeDefined();
69+
expect(content).toBeInstanceOf(Uint8Array);
70+
expect(content.length).toBeGreaterThan(0);
71+
expectTypeOf(filename).toMatchTypeOf<string>();
72+
});
6273
}, 30_000);

src/__tests__/setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "@/local-testing-binary.ts";
1515
import { homedir, tmpdir } from "node:os";
1616
import { join } from "node:path";
17+
import process from "node:process";
1718
import { assert, beforeEach } from "vitest";
1819

1920
export interface BrowserStackTestContext {

src/cli/browserstack-app-automate.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env node
22

3-
import { ensureKeyExists, ensureUsernameExists } from "@/cli/cli-utils";
4-
import { BrowserStackError } from "@/error";
5-
import { components } from "@/generated/openapi";
3+
import { ensureKeyExists, ensureUsernameExists } from "@/cli/cli-utils.ts";
4+
import { BrowserStackError } from "@/error.ts";
5+
import { components } from "@/generated/openapi.ts";
66
import {
77
AppAutomateClient,
88
BrowserStackOptions,
99
FlutterPlatform,
10-
} from "@/index";
10+
} from "@/index.ts";
1111
import { randomBytes } from "node:crypto";
1212
import { readFile } from "node:fs/promises";
1313
import { createRequire } from "node:module";
1414
import { basename, resolve } from "node:path";
15+
import process from "node:process";
1516

1617
const require = createRequire(import.meta.url);
1718

src/cli/browserstack-local.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env node
2-
3-
import { env } from "@/env";
4-
import { BrowserStackError } from "@/error";
5-
import { ensureDirExists } from "@/fs-utils";
6-
import { BrowserStack, LocalTestingBinaryOptions } from "@/index.node";
7-
import { writeFileAtomic } from "@/write-file-atomic";
2+
import { env } from "@/env.ts";
3+
import { BrowserStackError } from "@/error.ts";
4+
import { ensureDirExists } from "@/fs-utils.ts";
5+
import { LocalTestingBinary, LocalTestingBinaryOptions } from "@/index.node.ts";
6+
import { BufferEncoding, writeFileAtomic } from "@/write-file-atomic.ts";
87
import cp from "node:child_process";
98
import { readFile } from "node:fs/promises";
109
import { createRequire } from "node:module";
1110
import { homedir, tmpdir } from "node:os";
1211
import { join } from "node:path";
12+
import process from "node:process";
1313
import { onExit } from "signal-exit";
1414

1515
const require = createRequire(import.meta.url);
@@ -44,10 +44,7 @@ async function start(
4444
statusPath
4545
);
4646

47-
const localTestingBinary = new BrowserStack.LocalTestingBinary({
48-
...options,
49-
});
50-
47+
const localTestingBinary = new LocalTestingBinary(options);
5148
const localIdentifier = localTestingBinary.localIdentifier;
5249
let status: string | undefined;
5350

@@ -79,7 +76,7 @@ async function stopInstance(
7976
options: Omit<LocalTestingBinaryOptions, "localIdentifier">,
8077
logger: Logger = globalThis.console
8178
) {
82-
const localTestingBinary = new BrowserStack.LocalTestingBinary({
79+
const localTestingBinary = new LocalTestingBinary({
8380
...options,
8481
localIdentifier,
8582
});
@@ -315,7 +312,7 @@ async function readOrCreateStatusFile(
315312
): Promise<{ localIdentifiers: string[] } & Record<string, unknown>> {
316313
try {
317314
const contents = await readFile(statusPath, fileEncoding).then((data) =>
318-
data.trim()
315+
data.toString().trim()
319316
);
320317

321318
if (contents.length) {
@@ -406,8 +403,9 @@ export async function main(
406403
const localIdentifier =
407404
resolveEnvLocalIdentifier() ??
408405
(args[1] === cmdSeparator ? undefined : args[1]);
409-
410-
const key = ensureKeyExists(args[2] === cmdSeparator ? undefined : args[2]);
406+
const key = ensureKeyExists(
407+
action === BrowserStackLocalAction.runWith ? undefined : args[2]
408+
);
411409
const binHome = await ensureBinHomeExists();
412410
const statusPath = join(binHome, "status.json");
413411

src/cli/cli-utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { env } from "@/env";
2-
import { BrowserStackError } from "@/error";
1+
import { env } from "@/env.ts";
2+
import { BrowserStackError } from "@/error.ts";
33

44
/**
55
* Ensures that a key exists and returns it.

src/fs-utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { currentArch, currentPlatform } from "@/env.ts";
22
import { BrowserStackError } from "@/error.ts";
33
import { operations } from "@/generated/openapi.ts";
4-
import { writeFileAtomic } from "@/write-file-atomic";
4+
import { writeFileAtomic } from "@/write-file-atomic.ts";
5+
import { Buffer } from "node:buffer";
56
import { spawnSync } from "node:child_process";
67
import {
78
chmod,
@@ -12,6 +13,7 @@ import {
1213
unlink,
1314
} from "node:fs/promises";
1415
import { join, resolve } from "node:path";
16+
import process from "node:process";
1517

1618
export async function binaryPath(
1719
binHome: string,

src/write-file-atomic.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,27 @@
1010
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1111
*/
1212

13-
import fs from "fs";
13+
import { Buffer } from "node:buffer";
1414
import { randomBytes } from "node:crypto";
15+
import fs from "node:fs";
1516
import path from "node:path";
17+
import process from "node:process";
1618
import { promisify } from "node:util";
1719
import { onExit } from "signal-exit";
1820

21+
export type BufferEncoding =
22+
| "ascii"
23+
| "utf8"
24+
| "utf-8"
25+
| "utf16le"
26+
| "ucs2"
27+
| "ucs-2"
28+
| "base64"
29+
| "base64url"
30+
| "latin1"
31+
| "binary"
32+
| "hex";
33+
1934
interface ActiveFiles {
2035
[key: string]: (() => void)[];
2136
}

0 commit comments

Comments
 (0)