mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 09:49:24 +02:00
chore: switch to node test
This commit is contained in:
parent
67a07e2eb8
commit
dfb6acd2d5
115 changed files with 2433 additions and 4258 deletions
|
@ -1,14 +0,0 @@
|
|||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
export default {
|
||||
preset: "ts-jest/presets/default-esm",
|
||||
extensionsToTreatAsEsm: [".ts"],
|
||||
transform: {
|
||||
"^.+\\.tsx?$": [
|
||||
"ts-jest",
|
||||
{ tsconfig: "tsconfig.test.json", useESM: true },
|
||||
],
|
||||
},
|
||||
moduleNameMapper: {
|
||||
"^(\\.{1,2}/.*)\\.js$": "$1",
|
||||
},
|
||||
};
|
|
@ -30,7 +30,7 @@
|
|||
"build:watch": "tsc -b tsconfig.build.json",
|
||||
"lint": "run-eslint && prettier src/**/*.ts --write --tab-width 4",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" TS_JEST_DISABLE_VER_CHECKER=true jest --coverage"
|
||||
"test": "run-test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@yume-chan/async": "^2.2.0",
|
||||
|
@ -40,14 +40,11 @@
|
|||
"@yume-chan/struct": "workspace:^0.0.24"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/globals": "^30.0.0-alpha.4",
|
||||
"@types/node": "^20.14.9",
|
||||
"@yume-chan/eslint-config": "workspace:^1.0.0",
|
||||
"@yume-chan/test-runner": "workspace:^1.0.0",
|
||||
"@yume-chan/tsconfig": "workspace:^1.0.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"jest": "^30.0.0-alpha.4",
|
||||
"prettier": "^3.3.3",
|
||||
"ts-jest": "^29.2.2",
|
||||
"typescript": "^5.5.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import * as assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { AdbBanner } from "./banner.js";
|
||||
|
||||
|
@ -7,20 +8,20 @@ describe("AdbBanner", () => {
|
|||
const banner = AdbBanner.parse(
|
||||
"device::ro.product.name=NovaPro;ro.product.model=NovaPro;ro.product.device=NovaPro;\0",
|
||||
);
|
||||
expect(banner).toHaveProperty("product", "NovaPro");
|
||||
expect(banner).toHaveProperty("model", "NovaPro");
|
||||
expect(banner).toHaveProperty("device", "NovaPro");
|
||||
expect(banner).toHaveProperty("features", []);
|
||||
assert.strictEqual(banner.product, "NovaPro");
|
||||
assert.strictEqual(banner.model, "NovaPro");
|
||||
assert.strictEqual(banner.device, "NovaPro");
|
||||
assert.deepStrictEqual(banner.features, []);
|
||||
});
|
||||
|
||||
it("should parse new banner", () => {
|
||||
const banner = AdbBanner.parse(
|
||||
"device::ro.product.name=mblu_10_CN;ro.product.model=mblu10;ro.product.device=mblu10;features=sendrecv_v2_brotli,remount_shell,sendrecv_v2,abb_exec,fixed_push_mkdir,fixed_push_symlink_timestamp,abb,shell_v2,cmd,ls_v2,apex,stat_v2",
|
||||
);
|
||||
expect(banner).toHaveProperty("product", "mblu_10_CN");
|
||||
expect(banner).toHaveProperty("model", "mblu10");
|
||||
expect(banner).toHaveProperty("device", "mblu10");
|
||||
expect(banner).toHaveProperty("features", [
|
||||
assert.strictEqual(banner.product, "mblu_10_CN");
|
||||
assert.strictEqual(banner.model, "mblu10");
|
||||
assert.strictEqual(banner.device, "mblu10");
|
||||
assert.deepStrictEqual(banner.features, [
|
||||
"sendrecv_v2_brotli",
|
||||
"remount_shell",
|
||||
"sendrecv_v2",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { describe, expect, it, jest } from "@jest/globals";
|
||||
import { PromiseResolver } from "@yume-chan/async";
|
||||
import { ReadableStream, WritableStream } from "@yume-chan/stream-extra";
|
||||
import assert from "node:assert";
|
||||
import { describe, it, mock } from "node:test";
|
||||
|
||||
import type { AdbSocket } from "../../../adb.js";
|
||||
|
||||
|
@ -12,7 +13,7 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
const closed = new PromiseResolver<void>();
|
||||
const socket: AdbSocket = {
|
||||
service: "",
|
||||
close: jest.fn(() => {}),
|
||||
close: mock.fn(() => {}),
|
||||
closed: closed.promise,
|
||||
readable: new ReadableStream({
|
||||
async start(controller) {
|
||||
|
@ -28,11 +29,11 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
const process = new AdbSubprocessNoneProtocol(socket);
|
||||
const reader = process.stdout.getReader();
|
||||
|
||||
await expect(reader.read()).resolves.toEqual({
|
||||
assert.deepStrictEqual(await reader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([1, 2, 3]),
|
||||
});
|
||||
await expect(reader.read()).resolves.toEqual({
|
||||
assert.deepStrictEqual(await reader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([4, 5, 6]),
|
||||
});
|
||||
|
@ -42,7 +43,7 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
const closed = new PromiseResolver<void>();
|
||||
const socket: AdbSocket = {
|
||||
service: "",
|
||||
close: jest.fn(() => {}),
|
||||
close: mock.fn(() => {}),
|
||||
closed: closed.promise,
|
||||
readable: new ReadableStream({
|
||||
async start(controller) {
|
||||
|
@ -58,19 +59,20 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
const process = new AdbSubprocessNoneProtocol(socket);
|
||||
const reader = process.stdout.getReader();
|
||||
|
||||
await expect(reader.read()).resolves.toEqual({
|
||||
assert.deepStrictEqual(await reader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([1, 2, 3]),
|
||||
});
|
||||
await expect(reader.read()).resolves.toEqual({
|
||||
assert.deepStrictEqual(await reader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([4, 5, 6]),
|
||||
});
|
||||
|
||||
closed.resolve();
|
||||
|
||||
await expect(reader.read()).resolves.toEqual({
|
||||
assert.deepStrictEqual(await reader.read(), {
|
||||
done: true,
|
||||
value: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -80,7 +82,7 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
const closed = new PromiseResolver<void>();
|
||||
const socket: AdbSocket = {
|
||||
service: "",
|
||||
close: jest.fn(() => {}),
|
||||
close: mock.fn(() => {}),
|
||||
closed: closed.promise,
|
||||
readable: new ReadableStream({
|
||||
async start(controller) {
|
||||
|
@ -98,7 +100,10 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
|
||||
closed.resolve();
|
||||
|
||||
await expect(reader.read()).resolves.toEqual({ done: true });
|
||||
assert.deepStrictEqual(await reader.read(), {
|
||||
done: true,
|
||||
value: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -107,7 +112,7 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
const closed = new PromiseResolver<void>();
|
||||
const socket: AdbSocket = {
|
||||
service: "",
|
||||
close: jest.fn(() => {}),
|
||||
close: mock.fn(() => {}),
|
||||
closed: closed.promise,
|
||||
readable: new ReadableStream(),
|
||||
writable: new WritableStream(),
|
||||
|
@ -117,25 +122,25 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
|
||||
closed.resolve();
|
||||
|
||||
await expect(process.exit).resolves.toBe(0);
|
||||
assert.strictEqual(await process.exit, 0);
|
||||
});
|
||||
});
|
||||
|
||||
it("`resize` shouldn't throw any error", () => {
|
||||
const socket: AdbSocket = {
|
||||
service: "",
|
||||
close: jest.fn(() => {}),
|
||||
close: mock.fn(() => {}),
|
||||
closed: new PromiseResolver<void>().promise,
|
||||
readable: new ReadableStream(),
|
||||
writable: new WritableStream(),
|
||||
};
|
||||
|
||||
const process = new AdbSubprocessNoneProtocol(socket);
|
||||
expect(() => process.resize()).not.toThrow();
|
||||
assert.doesNotThrow(() => process.resize());
|
||||
});
|
||||
|
||||
it("`kill` should close `socket`", async () => {
|
||||
const close = jest.fn(() => {});
|
||||
const close = mock.fn(() => {});
|
||||
const socket: AdbSocket = {
|
||||
service: "",
|
||||
close,
|
||||
|
@ -146,6 +151,6 @@ describe("AdbSubprocessNoneProtocol", () => {
|
|||
|
||||
const process = new AdbSubprocessNoneProtocol(socket);
|
||||
await process.kill();
|
||||
expect(close).toHaveBeenCalledTimes(1);
|
||||
assert.deepEqual(close.mock.callCount(), 1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import { PromiseResolver } from "@yume-chan/async";
|
||||
import type { ReadableStreamDefaultController } from "@yume-chan/stream-extra";
|
||||
import { ReadableStream, WritableStream } from "@yume-chan/stream-extra";
|
||||
import assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import type { AdbSocket } from "../../../adb.js";
|
||||
|
||||
|
@ -45,6 +46,10 @@ function createMockSocket(
|
|||
return [socket, closed];
|
||||
}
|
||||
|
||||
async function assertResolves<T>(promise: Promise<T>, expected: T) {
|
||||
return assert.deepStrictEqual(await promise, expected);
|
||||
}
|
||||
|
||||
describe("AdbSubprocessShellProtocol", () => {
|
||||
describe("`stdout` and `stderr`", () => {
|
||||
it("should parse data from `socket", async () => {
|
||||
|
@ -54,11 +59,11 @@ describe("AdbSubprocessShellProtocol", () => {
|
|||
const stdoutReader = process.stdout.getReader();
|
||||
const stderrReader = process.stderr.getReader();
|
||||
|
||||
await expect(stdoutReader.read()).resolves.toEqual({
|
||||
assertResolves(stdoutReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([1, 2, 3]),
|
||||
});
|
||||
await expect(stderrReader.read()).resolves.toEqual({
|
||||
assertResolves(stderrReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([4, 5, 6]),
|
||||
});
|
||||
|
@ -87,11 +92,11 @@ describe("AdbSubprocessShellProtocol", () => {
|
|||
await stdoutReader.cancel();
|
||||
closed.resolve();
|
||||
|
||||
await expect(stderrReader.read()).resolves.toEqual({
|
||||
assertResolves(stderrReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([4, 5, 6]),
|
||||
});
|
||||
await expect(stderrReader.read()).resolves.toEqual({
|
||||
assertResolves(stderrReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([10, 11, 12]),
|
||||
});
|
||||
|
@ -115,24 +120,26 @@ describe("AdbSubprocessShellProtocol", () => {
|
|||
const stdoutReader = process.stdout.getReader();
|
||||
const stderrReader = process.stderr.getReader();
|
||||
|
||||
await expect(stdoutReader.read()).resolves.toEqual({
|
||||
assertResolves(stdoutReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([1, 2, 3]),
|
||||
});
|
||||
await expect(stderrReader.read()).resolves.toEqual({
|
||||
assertResolves(stderrReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([4, 5, 6]),
|
||||
});
|
||||
|
||||
closed.resolve();
|
||||
|
||||
await expect(stdoutReader.read()).resolves.toEqual({
|
||||
assertResolves(stdoutReader.read(), {
|
||||
done: true,
|
||||
value: undefined,
|
||||
});
|
||||
await expect(stderrReader.read()).resolves.toEqual({
|
||||
assertResolves(stderrReader.read(), {
|
||||
done: true,
|
||||
value: undefined,
|
||||
});
|
||||
await expect(process.exit).resolves.toBe(42);
|
||||
assert.strictEqual(await process.exit, 42);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -146,11 +153,11 @@ describe("AdbSubprocessShellProtocol", () => {
|
|||
const stdoutReader = process.stdout.getReader();
|
||||
const stderrReader = process.stderr.getReader();
|
||||
|
||||
await expect(stdoutReader.read()).resolves.toEqual({
|
||||
assertResolves(stdoutReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([1, 2, 3]),
|
||||
});
|
||||
await expect(stderrReader.read()).resolves.toEqual({
|
||||
assertResolves(stderrReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([4, 5, 6]),
|
||||
});
|
||||
|
@ -158,13 +165,15 @@ describe("AdbSubprocessShellProtocol", () => {
|
|||
closed.resolve();
|
||||
|
||||
await Promise.all([
|
||||
expect(stdoutReader.read()).resolves.toEqual({
|
||||
assertResolves(stdoutReader.read(), {
|
||||
done: true,
|
||||
value: undefined,
|
||||
}),
|
||||
expect(stderrReader.read()).resolves.toEqual({
|
||||
assertResolves(stderrReader.read(), {
|
||||
done: true,
|
||||
value: undefined,
|
||||
}),
|
||||
expect(process.exit).rejects.toThrow(),
|
||||
assert.rejects(process.exit),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
@ -181,11 +190,11 @@ describe("AdbSubprocessShellProtocol", () => {
|
|||
const stdoutReader = process.stdout.getReader();
|
||||
const stderrReader = process.stderr.getReader();
|
||||
|
||||
await expect(stdoutReader.read()).resolves.toEqual({
|
||||
await assertResolves(stdoutReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([1, 2, 3]),
|
||||
});
|
||||
await expect(stderrReader.read()).resolves.toEqual({
|
||||
await assertResolves(stderrReader.read(), {
|
||||
done: false,
|
||||
value: new Uint8Array([4, 5, 6]),
|
||||
});
|
||||
|
@ -193,9 +202,9 @@ describe("AdbSubprocessShellProtocol", () => {
|
|||
closed.resolve();
|
||||
|
||||
await Promise.all([
|
||||
expect(stdoutReader.read()).rejects.toThrow(),
|
||||
expect(stderrReader.read()).rejects.toThrow(),
|
||||
expect(process.exit).rejects.toThrow(),
|
||||
assert.rejects(stdoutReader.read()),
|
||||
assert.rejects(stderrReader.read()),
|
||||
assert.rejects(process.exit),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import * as assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { escapeArg } from "./utils.js";
|
||||
|
||||
describe("escapeArg", () => {
|
||||
it("should escape single quotes", () => {
|
||||
// https://android.googlesource.com/platform/packages/modules/adb/+/72c82a8d8ea0648ecea9dd47e0f4176bad792cfa/adb_utils_test.cpp#84
|
||||
expect(String.raw`''`).toBe(escapeArg(""));
|
||||
|
||||
expect(String.raw`'abc'`).toBe(escapeArg("abc"));
|
||||
assert.equal(escapeArg(""), String.raw`''`);
|
||||
assert.equal(escapeArg("abc"), String.raw`'abc'`);
|
||||
|
||||
function wrap(x: string) {
|
||||
return "'" + x + "'";
|
||||
}
|
||||
|
||||
const q = String.raw`'\''`;
|
||||
expect(wrap(q)).toBe(escapeArg("'"));
|
||||
expect(wrap(q + q)).toBe(escapeArg("''"));
|
||||
expect(wrap(q + "abc" + q)).toBe(escapeArg("'abc'"));
|
||||
expect(wrap(q + "abc")).toBe(escapeArg("'abc"));
|
||||
expect(wrap("abc" + q)).toBe(escapeArg("abc'"));
|
||||
expect(wrap("abc" + q + "def")).toBe(escapeArg("abc'def"));
|
||||
expect(wrap("a" + q + "b" + q + "c")).toBe(escapeArg("a'b'c"));
|
||||
expect(wrap("a" + q + "bcde" + q + "f")).toBe(escapeArg("a'bcde'f"));
|
||||
assert.equal(escapeArg("'"), wrap(q));
|
||||
assert.equal(escapeArg("''"), wrap(q + q));
|
||||
assert.equal(escapeArg("'abc'"), wrap(q + "abc" + q));
|
||||
assert.equal(escapeArg("'abc"), wrap(q + "abc"));
|
||||
assert.equal(escapeArg("abc'"), wrap("abc" + q));
|
||||
assert.equal(escapeArg("abc'def"), wrap("abc" + q + "def"));
|
||||
assert.equal(escapeArg("a'b'c"), wrap("a" + q + "b" + q + "c"));
|
||||
assert.equal(escapeArg("a'bcde'f"), wrap("a" + q + "bcde" + q + "f"));
|
||||
|
||||
expect(String.raw`' abc'`).toBe(escapeArg(" abc"));
|
||||
expect(String.raw`'"abc'`).toBe(escapeArg('"abc'));
|
||||
expect(String.raw`'\abc'`).toBe(escapeArg("\\abc"));
|
||||
expect(String.raw`'(abc'`).toBe(escapeArg("(abc"));
|
||||
expect(String.raw`')abc'`).toBe(escapeArg(")abc"));
|
||||
assert.equal(escapeArg(" abc"), String.raw`' abc'`);
|
||||
assert.equal(escapeArg('"abc'), String.raw`'"abc'`);
|
||||
assert.equal(escapeArg("\\abc"), String.raw`'\abc'`);
|
||||
assert.equal(escapeArg("(abc"), String.raw`'(abc'`);
|
||||
assert.equal(escapeArg(")abc"), String.raw`')abc'`);
|
||||
|
||||
expect(String.raw`'abc abc'`).toBe(escapeArg("abc abc"));
|
||||
expect(String.raw`'abc"abc'`).toBe(escapeArg('abc"abc'));
|
||||
expect(String.raw`'abc\abc'`).toBe(escapeArg("abc\\abc"));
|
||||
expect(String.raw`'abc(abc'`).toBe(escapeArg("abc(abc"));
|
||||
expect(String.raw`'abc)abc'`).toBe(escapeArg("abc)abc"));
|
||||
assert.equal(escapeArg("abc abc"), String.raw`'abc abc'`);
|
||||
assert.equal(escapeArg('abc"abc'), String.raw`'abc"abc'`);
|
||||
assert.equal(escapeArg("abc\\abc"), String.raw`'abc\abc'`);
|
||||
assert.equal(escapeArg("abc(abc"), String.raw`'abc(abc'`);
|
||||
assert.equal(escapeArg("abc)abc"), String.raw`'abc)abc'`);
|
||||
|
||||
expect(String.raw`'abc '`).toBe(escapeArg("abc "));
|
||||
expect(String.raw`'abc"'`).toBe(escapeArg('abc"'));
|
||||
expect(String.raw`'abc\'`).toBe(escapeArg("abc\\"));
|
||||
expect(String.raw`'abc('`).toBe(escapeArg("abc("));
|
||||
expect(String.raw`'abc)'`).toBe(escapeArg("abc)"));
|
||||
assert.equal(escapeArg("abc "), String.raw`'abc '`);
|
||||
assert.equal(escapeArg('abc"'), String.raw`'abc"'`);
|
||||
assert.equal(escapeArg("abc\\"), String.raw`'abc\'`);
|
||||
assert.equal(escapeArg("abc("), String.raw`'abc('`);
|
||||
assert.equal(escapeArg("abc)"), String.raw`'abc)'`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import * as assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { ReadableStream, WritableStream } from "@yume-chan/stream-extra";
|
||||
|
||||
import { AdbSyncSocket } from "./socket.js";
|
||||
|
@ -40,7 +42,7 @@ describe("AdbSyncSocket", () => {
|
|||
await Promise.resolve();
|
||||
}
|
||||
|
||||
expect(result).toEqual([1, 2, 3]);
|
||||
assert.deepStrictEqual(result, [1, 2, 3]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import * as assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { EMPTY_UINT8_ARRAY, encodeUtf8 } from "@yume-chan/struct";
|
||||
|
||||
import { decodeBase64 } from "../utils/base64.js";
|
||||
|
@ -93,7 +95,7 @@ describe("auth", () => {
|
|||
results.push(result);
|
||||
}
|
||||
|
||||
expect(results).toStrictEqual([
|
||||
assert.deepStrictEqual(results, [
|
||||
{
|
||||
command: AdbCommand.Auth,
|
||||
arg0: AdbAuthType.PublicKey,
|
||||
|
@ -125,7 +127,7 @@ describe("auth", () => {
|
|||
results.push(result);
|
||||
}
|
||||
|
||||
expect(results).toStrictEqual([
|
||||
assert.deepStrictEqual(results, [
|
||||
{
|
||||
command: AdbCommand.Auth,
|
||||
arg0: AdbAuthType.PublicKey,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import * as assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { decodeBase64 } from "../utils/base64.js";
|
||||
|
||||
|
@ -7,25 +8,25 @@ import { adbGeneratePublicKey, modInverse } from "./crypto.js";
|
|||
describe("modInverse", () => {
|
||||
it("should return correct value", () => {
|
||||
// https://github.com/openssl/openssl/blob/98161274636dca12e3bfafab7d2d2ac28f4d7c30/test/bntest.c#L3176
|
||||
expect(modInverse(5193817943, 3259122431)).toBe(2609653924);
|
||||
assert.strictEqual(modInverse(5193817943, 3259122431), 2609653924);
|
||||
|
||||
// https://cs.android.com/android/platform/superproject/main/+/main:external/cronet/third_party/boringssl/src/crypto/fipsmodule/bn/test/mod_inv_tests.txt
|
||||
expect(modInverse(0, 1)).toBe(NaN);
|
||||
expect(modInverse(1, 1)).toBe(NaN);
|
||||
expect(modInverse(2, 1)).toBe(NaN);
|
||||
expect(modInverse(3, 1)).toBe(NaN);
|
||||
expect(modInverse(0x54, 0xe3)).toBe(0x64);
|
||||
expect(modInverse(0x2b, 0x30)).toBe(0x13);
|
||||
expect(modInverse(0x30, 0x37)).toBe(0x2f);
|
||||
expect(modInverse(0x13, 0x4b)).toBe(0x4);
|
||||
expect(modInverse(0xcd4, 0x6a21)).toBe(0x1c47);
|
||||
expect(modInverse(0x8e7, 0x49c0)).toBe(0x2b97);
|
||||
expect(modInverse(0xfcb, 0x3092)).toBe(0x29b9);
|
||||
expect(modInverse(0x14bf, 0x41ae)).toBe(0xa83);
|
||||
expect(modInverse(0x11b5d53e, 0x322e92a1)).toBe(0x18f15fe1);
|
||||
expect(modInverse(0x8af6df6, 0x33d45eb7)).toBe(0x32f9453b);
|
||||
expect(modInverse(0xc5f89dd5, 0xfc09c17c)).toBe(0xd696369);
|
||||
expect(modInverse(0x60c2526, 0x74200493)).toBe(0x622839d8);
|
||||
assert.strictEqual(modInverse(0, 1), NaN);
|
||||
assert.strictEqual(modInverse(1, 1), NaN);
|
||||
assert.strictEqual(modInverse(2, 1), NaN);
|
||||
assert.strictEqual(modInverse(3, 1), NaN);
|
||||
assert.strictEqual(modInverse(0x54, 0xe3), 0x64);
|
||||
assert.strictEqual(modInverse(0x2b, 0x30), 0x13);
|
||||
assert.strictEqual(modInverse(0x30, 0x37), 0x2f);
|
||||
assert.strictEqual(modInverse(0x13, 0x4b), 0x4);
|
||||
assert.strictEqual(modInverse(0xcd4, 0x6a21), 0x1c47);
|
||||
assert.strictEqual(modInverse(0x8e7, 0x49c0), 0x2b97);
|
||||
assert.strictEqual(modInverse(0xfcb, 0x3092), 0x29b9);
|
||||
assert.strictEqual(modInverse(0x14bf, 0x41ae), 0xa83);
|
||||
assert.strictEqual(modInverse(0x11b5d53e, 0x322e92a1), 0x18f15fe1);
|
||||
assert.strictEqual(modInverse(0x8af6df6, 0x33d45eb7), 0x32f9453b);
|
||||
assert.strictEqual(modInverse(0xc5f89dd5, 0xfc09c17c), 0xd696369);
|
||||
assert.strictEqual(modInverse(0x60c2526, 0x74200493), 0x622839d8);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -72,26 +73,32 @@ const PUBLIC_KEY = decodeBase64(
|
|||
describe("adbGeneratePublicKey", () => {
|
||||
it("should return correct value", () => {
|
||||
const generated = adbGeneratePublicKey(PRIVATE_KEY);
|
||||
expect(generated.subarray(0, 4)).toStrictEqual(
|
||||
assert.deepStrictEqual(
|
||||
generated.subarray(0, 4),
|
||||
PUBLIC_KEY.subarray(0, 4),
|
||||
);
|
||||
expect(generated.subarray(4, 8)).toStrictEqual(
|
||||
assert.deepStrictEqual(
|
||||
generated.subarray(4, 8),
|
||||
PUBLIC_KEY.subarray(4, 8),
|
||||
);
|
||||
expect(generated.subarray(8, 264)).toStrictEqual(
|
||||
assert.deepStrictEqual(
|
||||
generated.subarray(8, 264),
|
||||
PUBLIC_KEY.subarray(8, 264),
|
||||
);
|
||||
expect(generated.subarray(265, 520)).toStrictEqual(
|
||||
assert.deepStrictEqual(
|
||||
generated.subarray(265, 520),
|
||||
PUBLIC_KEY.subarray(265, 520),
|
||||
);
|
||||
expect(generated.subarray(520, 524)).toStrictEqual(
|
||||
assert.deepStrictEqual(
|
||||
generated.subarray(520, 524),
|
||||
PUBLIC_KEY.subarray(520, 524),
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw if output is too small", () => {
|
||||
expect(() =>
|
||||
adbGeneratePublicKey(PRIVATE_KEY, new Uint8Array(1)),
|
||||
).toThrow("output buffer is too small");
|
||||
assert.throws(
|
||||
() => adbGeneratePublicKey(PRIVATE_KEY, new Uint8Array(1)),
|
||||
/output buffer is too small/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import * as assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import {
|
||||
calculateBase64EncodedLength,
|
||||
|
@ -9,13 +10,13 @@ import {
|
|||
describe("base64", () => {
|
||||
describe("calculateBase64EncodedLength", () => {
|
||||
it("should return correct length and padding", () => {
|
||||
expect(calculateBase64EncodedLength(0)).toEqual([0, 0]);
|
||||
expect(calculateBase64EncodedLength(1)).toEqual([4, 2]);
|
||||
expect(calculateBase64EncodedLength(2)).toEqual([4, 1]);
|
||||
expect(calculateBase64EncodedLength(3)).toEqual([4, 0]);
|
||||
expect(calculateBase64EncodedLength(4)).toEqual([8, 2]);
|
||||
expect(calculateBase64EncodedLength(5)).toEqual([8, 1]);
|
||||
expect(calculateBase64EncodedLength(6)).toEqual([8, 0]);
|
||||
assert.deepStrictEqual(calculateBase64EncodedLength(0), [0, 0]);
|
||||
assert.deepStrictEqual(calculateBase64EncodedLength(1), [4, 2]);
|
||||
assert.deepStrictEqual(calculateBase64EncodedLength(2), [4, 1]);
|
||||
assert.deepStrictEqual(calculateBase64EncodedLength(3), [4, 0]);
|
||||
assert.deepStrictEqual(calculateBase64EncodedLength(4), [8, 2]);
|
||||
assert.deepStrictEqual(calculateBase64EncodedLength(5), [8, 1]);
|
||||
assert.deepStrictEqual(calculateBase64EncodedLength(6), [8, 0]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -32,7 +33,8 @@ describe("base64", () => {
|
|||
inputs.forEach((input) => {
|
||||
describe(`input length = ${input.length}`, () => {
|
||||
it("should return correct decoded buffer", () => {
|
||||
expect(decodeBase64(nodeEncodeBase64(input))).toEqual(
|
||||
assert.deepStrictEqual(
|
||||
decodeBase64(nodeEncodeBase64(input)),
|
||||
input,
|
||||
);
|
||||
});
|
||||
|
@ -77,7 +79,7 @@ describe("base64", () => {
|
|||
|
||||
describe(`input length = ${input.length}`, () => {
|
||||
it("should return correct encoded buffer", () => {
|
||||
expect(encodeBase64(input)).toEqual(correct);
|
||||
assert.deepStrictEqual(encodeBase64(input), correct);
|
||||
});
|
||||
|
||||
it("should take `output`", () => {
|
||||
|
@ -90,14 +92,16 @@ describe("base64", () => {
|
|||
input,
|
||||
output.subarray(2, 2 + correct.length + 2),
|
||||
);
|
||||
expect(outputLength).toEqual(correct.length);
|
||||
expect(output).toEqual(expectedOutput);
|
||||
assert.strictEqual(outputLength, correct.length);
|
||||
assert.deepStrictEqual(output, expectedOutput);
|
||||
});
|
||||
|
||||
it("should throw if `output` is too small", () => {
|
||||
if (correct.length !== 0) {
|
||||
const output = new Uint8Array(correct.length - 1);
|
||||
expect(() => encodeBase64(input, output)).toThrow();
|
||||
assert.throws(() => {
|
||||
encodeBase64(input, output);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -184,8 +188,8 @@ describe("base64", () => {
|
|||
),
|
||||
buffer.subarray(outputOffset),
|
||||
);
|
||||
expect(outputLength).toEqual(correct.length);
|
||||
expect(buffer).toEqual(expectedBuffer);
|
||||
assert.strictEqual(outputLength, correct.length);
|
||||
assert.deepStrictEqual(buffer, expectedBuffer);
|
||||
}
|
||||
|
||||
// Validate with the dumb version of `canEncodeInPlace` above.
|
||||
|
@ -203,9 +207,9 @@ describe("base64", () => {
|
|||
it(`should throw with offset = ${
|
||||
i - 1
|
||||
}`, () => {
|
||||
expect(() =>
|
||||
testInPlaceEncodeBase64(i - 1),
|
||||
).toThrow();
|
||||
assert.throws(() => {
|
||||
testInPlaceEncodeBase64(i - 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -230,9 +234,9 @@ describe("base64", () => {
|
|||
last = i;
|
||||
|
||||
it(`should throw with offset = ${i}`, () => {
|
||||
expect(() =>
|
||||
testInPlaceEncodeBase64(i),
|
||||
).toThrow();
|
||||
assert.throws(() => {
|
||||
testInPlaceEncodeBase64(i);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.test.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.test.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue