forked from webiny/webiny-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.base.js
111 lines (102 loc) · 3.96 KB
/
jest.config.base.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const { basename, join } = require("path");
const merge = require("merge");
const tsPreset = require("ts-jest/presets/js-with-babel/jest-preset");
const { version } = require("@webiny/cli/package.json");
module.exports = function ({ path }, presets = []) {
const name = basename(path);
// Enables us to run tests of only a specific type (for example "integration" or "e2e").
let type = "";
if (process.env.TEST_TYPE) {
type = `.${process.env.TEST_TYPE}`;
}
const merged = merge.recursive({ setupFilesAfterEnv: [] }, tsPreset, ...presets, {
displayName: name,
modulePaths: [`${path}/src`],
testMatch: [`${path}/**/__tests__/**/*${type}.test.[jt]s?(x)`],
transform: {
"^.+\\.[jt]sx?$": "ts-jest"
},
transformIgnorePatterns: ["/node_modules/(?!(nanoid)/)"],
moduleDirectories: ["node_modules"],
moduleNameMapper: {
"~tests/(.*)": `${path}/__tests__/$1`,
"~/(.*)": `${path}/src/$1`
},
modulePathIgnorePatterns: [],
globals: {
WEBINY_VERSION: version,
"ts-jest": {
isolatedModules: true,
babelConfig: `${path}/.babelrc.js`,
diagnostics: false
}
},
collectCoverage: false,
collectCoverageFrom: ["packages/**/*.{ts,tsx,js,jsx}"],
coverageReporters: ["html"]
});
merged.setupFilesAfterEnv = [
join(__dirname, "jest.config.base.setup.js"),
...merged.setupFilesAfterEnv
];
// IMPORTANT!
// We need to delete the following keys to let our rules be the only ones applied.
delete merged.transform["^.+\\.jsx?$"];
delete merged.transform["^.+\\.tsx?$"];
return merged;
};
process.env.DB_TABLE = "DynamoDB";
process.env.DB_TABLE_ELASTICSEARCH = "ElasticsearchStream";
process.env.WEBINY_VERSION = version;
process.env.WEBINY_ELASTICSEARCH_INDEX_LOCALE = "true";
const createDynaliteTables = (options = {}) => {
return {
tables: [
{
TableName: process.env.DB_TABLE,
KeySchema: [
{ AttributeName: "PK", KeyType: "HASH" },
{ AttributeName: "SK", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "PK", AttributeType: "S" },
{ AttributeName: "SK", AttributeType: "S" },
{ AttributeName: "GSI1_PK", AttributeType: "S" },
{ AttributeName: "GSI1_SK", AttributeType: "S" }
],
ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 },
GlobalSecondaryIndexes: [
{
IndexName: "GSI1",
KeySchema: [
{ AttributeName: "GSI1_PK", KeyType: "HASH" },
{ AttributeName: "GSI1_SK", KeyType: "RANGE" }
],
Projection: {
ProjectionType: "ALL"
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
}
],
data: options.data || []
},
{
TableName: process.env.DB_TABLE_ELASTICSEARCH,
KeySchema: [
{ AttributeName: "PK", KeyType: "HASH" },
{ AttributeName: "SK", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "PK", AttributeType: "S" },
{ AttributeName: "SK", AttributeType: "S" }
],
ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }
}
],
basePort: 8000
};
};
module.exports.createDynaliteTables = createDynaliteTables;