-
Notifications
You must be signed in to change notification settings - Fork 582
/
environment.js
48 lines (43 loc) · 1.64 KB
/
environment.js
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
43
44
45
46
47
48
const dbPlugins = require("@webiny/handler-db").default;
const { DynamoDbDriver } = require("@webiny/db-dynamodb");
const dynamoDbPlugins = require("@webiny/db-dynamodb/plugins").default;
const { DocumentClient } = require("aws-sdk/clients/dynamodb");
const NodeEnvironment = require("jest-environment-node");
/**
* For this to work it must load plugins that have already been built
*/
const plugins = require("../../dist/index").default;
if (typeof plugins !== "function") {
throw new Error(`Loaded plugins file must export a function that returns an array of plugins.`);
}
class FileManagerTestEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
const documentClient = new DocumentClient({
convertEmptyValues: true,
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT || "http://localhost:8001",
sslEnabled: false,
region: "local",
accessKeyId: "test",
secretAccessKey: "test"
});
/**
* This is a global function that will be called inside the tests to get all relevant plugins, methods and objects.
*/
this.global.__getStorageOperationsPlugins = () => {
return () => {
return [
...dynamoDbPlugins(),
...plugins(),
...dbPlugins({
table: process.env.DB_TABLE,
driver: new DynamoDbDriver({
documentClient
})
})
];
};
};
}
}
module.exports = FileManagerTestEnvironment;