forked from 1Password/op-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
42 lines (38 loc) · 865 Bytes
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Joi from "joi";
import { setGlobalFlags } from "./src";
declare global {
namespace jest {
interface Matchers<R, T> {
toMatchSchema(schema: Joi.AnySchema): R;
}
}
}
expect.extend({
toMatchSchema: (receivedInput: any, schema: Joi.AnySchema) => {
const { error } = schema.validate(receivedInput);
const pass = error === undefined;
return {
message: () =>
pass
? "Success"
: `Error: ${error.message}\n\nReceived: ${JSON.stringify(
receivedInput,
null,
2,
)}`,
pass,
};
},
});
if (process.env.npm_lifecycle_event === "test:integration") {
for (const envVar of ["ACCOUNT", "VAULT"]) {
if (!process.env[`OP_${envVar}`]) {
throw new Error(
`OP_${envVar} environment variable is required for integration tests.`,
);
}
}
setGlobalFlags({
account: process.env.OP_ACCOUNT,
});
}