-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathoptional_require.test.ts
More file actions
89 lines (77 loc) · 2.22 KB
/
optional_require.test.ts
File metadata and controls
89 lines (77 loc) · 2.22 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { expect } from 'chai';
import { existsSync } from 'fs';
import { resolve } from 'path';
import * as zlib from 'zlib';
import {
AuthContext,
compress,
GSSAPI,
HostAddress,
MongoMissingDependencyError
} from '../../mongodb';
import { runtime } from '../../tools/utils';
function moduleExistsSync(moduleName) {
return existsSync(resolve(__dirname, `../../../node_modules/${moduleName}`));
}
describe('optionalRequire', function () {
describe('Zstandard', function () {
it('supports built-in zstd when the addon is not installed', async function () {
const moduleName = '@mongodb-js/zstd';
if (moduleExistsSync(moduleName)) {
return this.skip();
}
const error = await compress(
{ zlibCompressionLevel: 0, agreedCompressor: 'zstd' },
Buffer.from('test', 'utf8')
).then(
() => null,
e => e
);
const hasBuiltInZstd =
typeof zlib.zstdCompress === 'function' && typeof zlib.zstdDecompress === 'function';
if (hasBuiltInZstd) {
expect(error).to.equal(null);
} else {
expect(error).to.be.instanceOf(MongoMissingDependencyError);
}
});
});
describe('Snappy', function () {
it('should error if not installed', async function () {
const moduleName = 'snappy';
if (moduleExistsSync(moduleName)) {
return this.skip();
}
const error = await compress(
{ zlibCompressionLevel: 0, agreedCompressor: 'snappy' },
Buffer.alloc(1)
).then(
() => null,
e => e
);
expect(error).to.be.instanceOf(MongoMissingDependencyError);
});
});
describe('Kerberos', function () {
it('should error if not installed', async function () {
const moduleName = 'kerberos';
if (moduleExistsSync(moduleName)) {
return this.skip();
}
const gssapi = new GSSAPI();
const error = await gssapi
.auth(
new AuthContext(null, true, {
hostAddress: new HostAddress('a'),
credentials: true,
runtime
})
)
.then(
() => null,
e => e
);
expect(error).to.be.instanceOf(MongoMissingDependencyError);
});
});
});