forked from webiny/webiny-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.base.js
143 lines (129 loc) · 5 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const { basename, join, dirname } = require("path");
const fs = require("fs");
const merge = require("merge");
const findUp = require("find-up");
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}`;
}
process.env.JEST_DYNALITE_CONFIG_DIRECTORY = path;
const merged = merge.recursive(true, { setupFilesAfterEnv: [] }, tsPreset, {
displayName: name,
modulePaths: [`${path}/src`],
testMatch: [`${path}/**/__tests__/**/*${type}.test.[jt]s?(x)`],
transform: {
"^.+\\.[jt]sx?$": [
"ts-jest",
{
isolatedModules: true,
babelConfig: `${path}/.babelrc.js`,
diagnostics: false
}
]
},
transformIgnorePatterns: ["/node_modules/(?!(nanoid)/)"],
moduleDirectories: ["node_modules"],
moduleNameMapper: {
"~tests/(.*)": `${path}/__tests__/$1`,
"~/(.*)": `${path}/src/$1`
},
modulePathIgnorePatterns: [
"<rootDir>/.verdaccio",
"<rootDir>/.webiny",
"<rootDir>/apps",
"<rootDir>/packages/.*/dist"
],
globals: {
WEBINY_VERSION: version
}
});
merged.setupFiles = [
...(merged.setupFiles || []),
...presets
.map(preset => preset.setupFiles)
.flat()
.filter(Boolean)
];
const setupAfterEnv = join(path, "__tests__", "setup", "setupAfterEnv.js");
const setupAfterEnvExists = fs.existsSync(setupAfterEnv);
merged.setupFilesAfterEnv = [
join(__dirname, "jest.config.base.setup.js"),
setupAfterEnvExists ? setupAfterEnv : null,
...merged.setupFilesAfterEnv,
...presets.map(preset => preset.setupFilesAfterEnv || []).flat()
].filter(Boolean);
// 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?$"];
process.stdout.write(`Loading test setup files from the following packages:\n`);
merged.setupFilesAfterEnv.forEach(setupFile => {
const filePkg = findUp.sync("package.json", { cwd: dirname(setupFile) });
const pkg = require(filePkg);
if (pkg.name) {
process.stdout.write(`- ${pkg.name}\n`);
}
});
process.stdout.write(`\n---------------------------\n`);
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;