-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
69 lines (62 loc) · 2.36 KB
/
Copy pathjest.setup.ts
File metadata and controls
69 lines (62 loc) · 2.36 KB
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
import fs from 'fs';
try {
fs.mkdirSync('./logs');
} catch (err: any) {
if (err.code !== 'EEXIST') throw err;
}
// Force mongodb-memory-server to use a Windows x64 binary on ARM64 hosts.
if (process.platform === 'win32' && process.arch === 'arm64') {
process.env.MONGOMS_DOWNLOAD_URL =
process.env.MONGOMS_DOWNLOAD_URL ||
'https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-7.0.14.zip';
process.env.MONGOMS_VERSION = process.env.MONGOMS_VERSION || '7.0.14';
try {
// Patch mongodb-memory-server to accept "windows" archive names for parsing.
// This allows using the x64 Windows binary on ARM64 under emulation.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {
DryMongoBinary,
} = require('mongodb-memory-server-core/lib/util/DryMongoBinary');
const originalParse = DryMongoBinary.parseArchiveNameRegex;
DryMongoBinary.parseArchiveNameRegex = function (input: string, opts: any) {
const patchedInput = input.replace(/mongodb-windows-/g, 'mongodb-win32-');
return originalParse.call(this, patchedInput, opts);
};
} catch {
// ignore if patching fails; tests will surface the error
}
} else {
process.env.MONGOMS_VERSION = process.env.MONGOMS_VERSION || '7.0.14';
}
jest.mock('bcrypt', () => {
const hashValue = (value: string) => `mocked:${value}`;
return {
genSalt: async () => 'salt',
genSaltSync: () => 'salt',
hash: async (value: string) => hashValue(value),
hashSync: (value: string) => hashValue(value),
compare: async (value: string, hashed: string) =>
hashed === hashValue(value) || hashed === value,
compareSync: (value: string, hashed: string) =>
hashed === hashValue(value) || hashed === value,
};
});
jest.mock('sharp', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
const mockSharp = () => {
const api = {
metadata: async () => ({ width: 128, height: 128, format: 'png' }),
resize: () => api,
png: () => api,
toFile: async (filePath: string) => {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, Buffer.from(''));
},
};
return api;
};
return Object.assign(mockSharp, { default: mockSharp });
});