mirror of
https://github.com/chatmail/core.git
synced 2026-05-13 03:46:32 +03:00
chore: run npm run prettier:fix
This commit is contained in:
@@ -5,24 +5,24 @@ const json = JSON.parse(readFileSync("./coverage/coverage-final.json"));
|
|||||||
const jsonCoverage =
|
const jsonCoverage =
|
||||||
json[Object.keys(json).find((k) => k.includes(generatedFile))];
|
json[Object.keys(json).find((k) => k.includes(generatedFile))];
|
||||||
const fnMap = Object.keys(jsonCoverage.fnMap).map(
|
const fnMap = Object.keys(jsonCoverage.fnMap).map(
|
||||||
(key) => jsonCoverage.fnMap[key]
|
(key) => jsonCoverage.fnMap[key],
|
||||||
);
|
);
|
||||||
const htmlCoverage = readFileSync(
|
const htmlCoverage = readFileSync(
|
||||||
"./coverage/" + generatedFile + ".html",
|
"./coverage/" + generatedFile + ".html",
|
||||||
"utf8"
|
"utf8",
|
||||||
);
|
);
|
||||||
const uncoveredLines = htmlCoverage
|
const uncoveredLines = htmlCoverage
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.filter((line) => line.includes(`"function not covered"`));
|
.filter((line) => line.includes(`"function not covered"`));
|
||||||
const uncoveredFunctions = uncoveredLines.map(
|
const uncoveredFunctions = uncoveredLines.map(
|
||||||
(line) => />([\w_]+)\(/.exec(line)[1]
|
(line) => />([\w_]+)\(/.exec(line)[1],
|
||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
"\nUncovered api functions:\n" +
|
"\nUncovered api functions:\n" +
|
||||||
uncoveredFunctions
|
uncoveredFunctions
|
||||||
.map((uF) => fnMap.find(({ name }) => name === uF))
|
.map((uF) => fnMap.find(({ name }) => name === uF))
|
||||||
.map(
|
.map(
|
||||||
({ name, line }) => `.${name.padEnd(40)} (${generatedFile}:${line})`
|
({ name, line }) => `.${name.padEnd(40)} (${generatedFile}:${line})`,
|
||||||
)
|
)
|
||||||
.join("\n")
|
.join("\n"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ while (null != (match = regex.exec(header_data))) {
|
|||||||
|
|
||||||
const constants = data
|
const constants = data
|
||||||
.filter(
|
.filter(
|
||||||
({ key }) => key.toUpperCase()[0] === key[0] // check if define name is uppercase
|
({ key }) => key.toUpperCase()[0] === key[0], // check if define name is uppercase
|
||||||
)
|
)
|
||||||
.sort((lhs, rhs) => {
|
.sort((lhs, rhs) => {
|
||||||
if (lhs.key < rhs.key) return -1;
|
if (lhs.key < rhs.key) return -1;
|
||||||
@@ -50,5 +50,5 @@ const constants = data
|
|||||||
|
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
resolve(__dirname, "../generated/constants.ts"),
|
resolve(__dirname, "../generated/constants.ts"),
|
||||||
`// Generated!\n\nexport enum C {\n${constants.replace(/:/g, " =")},\n}\n`
|
`// Generated!\n\nexport enum C {\n${constants.replace(/:/g, " =")},\n}\n`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import { TinyEmitter } from "@deltachat/tiny-emitter";
|
|||||||
type Events = { ALL: (accountId: number, event: EventType) => void } & {
|
type Events = { ALL: (accountId: number, event: EventType) => void } & {
|
||||||
[Property in EventType["kind"]]: (
|
[Property in EventType["kind"]]: (
|
||||||
accountId: number,
|
accountId: number,
|
||||||
event: Extract<EventType, { kind: Property }>
|
event: Extract<EventType, { kind: Property }>,
|
||||||
) => void;
|
) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ContextEvents = { ALL: (event: EventType) => void } & {
|
type ContextEvents = { ALL: (event: EventType) => void } & {
|
||||||
[Property in EventType["kind"]]: (
|
[Property in EventType["kind"]]: (
|
||||||
event: Extract<EventType, { kind: Property }>
|
event: Extract<EventType, { kind: Property }>,
|
||||||
) => void;
|
) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export type DcEventType<T extends EventType["kind"]> = Extract<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
export class BaseDeltaChat<
|
export class BaseDeltaChat<
|
||||||
Transport extends BaseTransport<any>
|
Transport extends BaseTransport<any>,
|
||||||
> extends TinyEmitter<Events> {
|
> extends TinyEmitter<Events> {
|
||||||
rpc: RawClient;
|
rpc: RawClient;
|
||||||
account?: T.Account;
|
account?: T.Account;
|
||||||
@@ -34,7 +34,10 @@ export class BaseDeltaChat<
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
private eventTask: Promise<void>;
|
private eventTask: Promise<void>;
|
||||||
|
|
||||||
constructor(public transport: Transport, startEventLoop: boolean) {
|
constructor(
|
||||||
|
public transport: Transport,
|
||||||
|
startEventLoop: boolean,
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.rpc = new RawClient(this.transport);
|
this.rpc = new RawClient(this.transport);
|
||||||
if (startEventLoop) {
|
if (startEventLoop) {
|
||||||
@@ -53,7 +56,7 @@ export class BaseDeltaChat<
|
|||||||
this.contextEmitters[event.contextId].emit(
|
this.contextEmitters[event.contextId].emit(
|
||||||
event.event.kind,
|
event.event.kind,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
event.event as any
|
event.event as any,
|
||||||
);
|
);
|
||||||
this.contextEmitters[event.contextId].emit("ALL", event.event as any);
|
this.contextEmitters[event.contextId].emit("ALL", event.event as any);
|
||||||
}
|
}
|
||||||
@@ -83,7 +86,10 @@ export class StdioDeltaChat extends BaseDeltaChat<StdioTransport> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class StdioTransport extends BaseTransport {
|
export class StdioTransport extends BaseTransport {
|
||||||
constructor(public input: any, public output: any) {
|
constructor(
|
||||||
|
public input: any,
|
||||||
|
public output: any,
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
var buffer = "";
|
var buffer = "";
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ describe("basic tests", () => {
|
|||||||
|
|
||||||
expect(
|
expect(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
validAddresses.map((email) => dc.rpc.checkEmailValidity(email))
|
validAddresses.map((email) => dc.rpc.checkEmailValidity(email)),
|
||||||
)
|
),
|
||||||
).to.not.contain(false);
|
).to.not.contain(false);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
invalidAddresses.map((email) => dc.rpc.checkEmailValidity(email))
|
invalidAddresses.map((email) => dc.rpc.checkEmailValidity(email)),
|
||||||
)
|
),
|
||||||
).to.not.contain(true);
|
).to.not.contain(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ describe("basic tests", () => {
|
|||||||
const contactId = await dc.rpc.createContact(
|
const contactId = await dc.rpc.createContact(
|
||||||
accountId,
|
accountId,
|
||||||
"example@delta.chat",
|
"example@delta.chat",
|
||||||
null
|
null,
|
||||||
);
|
);
|
||||||
expect((await dc.rpc.getContact(accountId, contactId)).isBlocked).to.be
|
expect((await dc.rpc.getContact(accountId, contactId)).isBlocked).to.be
|
||||||
.false;
|
.false;
|
||||||
@@ -126,7 +126,7 @@ describe("basic tests", () => {
|
|||||||
await dc.rpc.batchSetConfig(accountId, config);
|
await dc.rpc.batchSetConfig(accountId, config);
|
||||||
const retrieved = await dc.rpc.batchGetConfig(
|
const retrieved = await dc.rpc.batchGetConfig(
|
||||||
accountId,
|
accountId,
|
||||||
Object.keys(config)
|
Object.keys(config),
|
||||||
);
|
);
|
||||||
expect(retrieved).to.deep.equal(config);
|
expect(retrieved).to.deep.equal(config);
|
||||||
});
|
});
|
||||||
@@ -138,7 +138,7 @@ describe("basic tests", () => {
|
|||||||
await dc.rpc.batchSetConfig(accountId, config);
|
await dc.rpc.batchSetConfig(accountId, config);
|
||||||
const retrieved = await dc.rpc.batchGetConfig(
|
const retrieved = await dc.rpc.batchGetConfig(
|
||||||
accountId,
|
accountId,
|
||||||
Object.keys(config)
|
Object.keys(config),
|
||||||
);
|
);
|
||||||
expect(retrieved).to.deep.equal(config);
|
expect(retrieved).to.deep.equal(config);
|
||||||
});
|
});
|
||||||
@@ -152,7 +152,7 @@ describe("basic tests", () => {
|
|||||||
await dc.rpc.batchSetConfig(accountId, config);
|
await dc.rpc.batchSetConfig(accountId, config);
|
||||||
const retrieved = await dc.rpc.batchGetConfig(
|
const retrieved = await dc.rpc.batchGetConfig(
|
||||||
accountId,
|
accountId,
|
||||||
Object.keys(config)
|
Object.keys(config),
|
||||||
);
|
);
|
||||||
expect(retrieved).to.deep.equal(config);
|
expect(retrieved).to.deep.equal(config);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ describe("online tests", function () {
|
|||||||
if (process.env.COVERAGE && !process.env.COVERAGE_OFFLINE) {
|
if (process.env.COVERAGE && !process.env.COVERAGE_OFFLINE) {
|
||||||
console.error(
|
console.error(
|
||||||
"CAN NOT RUN COVERAGE correctly: Missing CHATMAIL_DOMAIN environment variable!\n\n",
|
"CAN NOT RUN COVERAGE correctly: Missing CHATMAIL_DOMAIN environment variable!\n\n",
|
||||||
"You can set COVERAGE_OFFLINE=1 to circumvent this check and skip the online tests, but those coverage results will be wrong, because some functions can only be tested in the online test"
|
"You can set COVERAGE_OFFLINE=1 to circumvent this check and skip the online tests, but those coverage results will be wrong, because some functions can only be tested in the online test",
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
"Missing CHATMAIL_DOMAIN environment variable!, skip integration tests"
|
"Missing CHATMAIL_DOMAIN environment variable!, skip integration tests",
|
||||||
);
|
);
|
||||||
this.skip();
|
this.skip();
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ describe("online tests", function () {
|
|||||||
account1 = createTempUser(process.env.CHATMAIL_DOMAIN);
|
account1 = createTempUser(process.env.CHATMAIL_DOMAIN);
|
||||||
if (!account1 || !account1.email || !account1.password) {
|
if (!account1 || !account1.email || !account1.password) {
|
||||||
console.log(
|
console.log(
|
||||||
"We didn't got back an account from the api, skip integration tests"
|
"We didn't got back an account from the api, skip integration tests",
|
||||||
);
|
);
|
||||||
this.skip();
|
this.skip();
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ describe("online tests", function () {
|
|||||||
account2 = createTempUser(process.env.CHATMAIL_DOMAIN);
|
account2 = createTempUser(process.env.CHATMAIL_DOMAIN);
|
||||||
if (!account2 || !account2.email || !account2.password) {
|
if (!account2 || !account2.email || !account2.password) {
|
||||||
console.log(
|
console.log(
|
||||||
"We didn't got back an account2 from the api, skip integration tests"
|
"We didn't got back an account2 from the api, skip integration tests",
|
||||||
);
|
);
|
||||||
this.skip();
|
this.skip();
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ describe("online tests", function () {
|
|||||||
accountId2,
|
accountId2,
|
||||||
chatIdOnAccountB,
|
chatIdOnAccountB,
|
||||||
false,
|
false,
|
||||||
false
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(messageList).have.length(1);
|
expect(messageList).have.length(1);
|
||||||
@@ -124,11 +124,11 @@ describe("online tests", function () {
|
|||||||
accountId2,
|
accountId2,
|
||||||
chatIdOnAccountB,
|
chatIdOnAccountB,
|
||||||
false,
|
false,
|
||||||
false
|
false,
|
||||||
);
|
);
|
||||||
const message = await dc.rpc.getMessage(
|
const message = await dc.rpc.getMessage(
|
||||||
accountId2,
|
accountId2,
|
||||||
messageList.reverse()[0]
|
messageList.reverse()[0],
|
||||||
);
|
);
|
||||||
expect(message.text).equal("Hello2");
|
expect(message.text).equal("Hello2");
|
||||||
// Send message back from B to A
|
// Send message back from B to A
|
||||||
@@ -150,7 +150,7 @@ describe("online tests", function () {
|
|||||||
const info = await dc.rpc.getProviderInfo(acc, "example.com");
|
const info = await dc.rpc.getProviderInfo(acc, "example.com");
|
||||||
expect(info).to.be.not.null;
|
expect(info).to.be.not.null;
|
||||||
expect(info?.overviewPage).to.equal(
|
expect(info?.overviewPage).to.equal(
|
||||||
"https://providers.delta.chat/example-com"
|
"https://providers.delta.chat/example-com",
|
||||||
);
|
);
|
||||||
expect(info?.status).to.equal(3);
|
expect(info?.status).to.equal(3);
|
||||||
});
|
});
|
||||||
@@ -167,12 +167,12 @@ async function waitForEvent<T extends DcEvent["kind"]>(
|
|||||||
dc: DeltaChat,
|
dc: DeltaChat,
|
||||||
eventType: T,
|
eventType: T,
|
||||||
accountId: number,
|
accountId: number,
|
||||||
timeout: number = EVENT_TIMEOUT
|
timeout: number = EVENT_TIMEOUT,
|
||||||
): Promise<Extract<DcEvent, { kind: T }>> {
|
): Promise<Extract<DcEvent, { kind: T }>> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const rejectTimeout = setTimeout(
|
const rejectTimeout = setTimeout(
|
||||||
() => reject(new Error("Timeout reached before event came in")),
|
() => reject(new Error("Timeout reached before event came in")),
|
||||||
timeout
|
timeout,
|
||||||
);
|
);
|
||||||
const callback = (contextId: number, event: DcEvent) => {
|
const callback = (contextId: number, event: DcEvent) => {
|
||||||
if (contextId == accountId) {
|
if (contextId == accountId) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export async function startServer(): Promise<RpcServerHandle> {
|
|||||||
const tmpDir = await mkdtemp(join(tmpdir(), "deltachat-jsonrpc-test"));
|
const tmpDir = await mkdtemp(join(tmpdir(), "deltachat-jsonrpc-test"));
|
||||||
|
|
||||||
const pathToServerBinary = resolve(
|
const pathToServerBinary = resolve(
|
||||||
join(await getTargetDir(), "debug/deltachat-rpc-server")
|
join(await getTargetDir(), "debug/deltachat-rpc-server"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const server = spawn(pathToServerBinary, {
|
const server = spawn(pathToServerBinary, {
|
||||||
@@ -29,7 +29,7 @@ export async function startServer(): Promise<RpcServerHandle> {
|
|||||||
throw new Error(
|
throw new Error(
|
||||||
"Failed to start server executable " +
|
"Failed to start server executable " +
|
||||||
pathToServerBinary +
|
pathToServerBinary +
|
||||||
", make sure you built it first."
|
", make sure you built it first.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
let shouldClose = false;
|
let shouldClose = false;
|
||||||
@@ -83,7 +83,7 @@ function getTargetDir(): Promise<string> {
|
|||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user