Skip to content

Commit bdce3c9

Browse files
committed
test(resolveConfig): add tests for "envToBool"
1 parent 8f16a2a commit bdce3c9

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

packages/mongodb-memory-server-core/src/util/__tests__/resolveConfig.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { promises as fspromises } from 'fs';
22
import * as tmp from 'tmp';
3-
import resolveConfig, { findPackageJson, ResolveConfigVariables } from '../resolveConfig';
3+
import resolveConfig, {
4+
envToBool,
5+
findPackageJson,
6+
ResolveConfigVariables,
7+
} from '../resolveConfig';
48
import { assertion, isNullOrUndefined } from '../utils';
59

610
tmp.setGracefulCleanup();
@@ -26,6 +30,10 @@ describe('resolveConfig', () => {
2630
const originalDir = process.cwd();
2731
let tmpObj: tmp.DirResult;
2832

33+
afterEach(() => {
34+
jest.restoreAllMocks();
35+
});
36+
2937
describe('findPackageJson', () => {
3038
beforeAll(async () => {
3139
// Set up test project/subproject structure in a temporary directory:
@@ -86,4 +94,26 @@ describe('resolveConfig', () => {
8694
expect(out.config.inner).toBe(true);
8795
});
8896
});
97+
98+
describe('envToBool', () => {
99+
it('should resolve all supported cases to right booleans', () => {
100+
expect(envToBool('1')).toStrictEqual(true);
101+
expect(envToBool('on')).toStrictEqual(true);
102+
expect(envToBool('ON')).toStrictEqual(true);
103+
expect(envToBool('yes')).toStrictEqual(true);
104+
expect(envToBool('YES')).toStrictEqual(true);
105+
expect(envToBool('true')).toStrictEqual(true);
106+
expect(envToBool('TRUE')).toStrictEqual(true);
107+
108+
expect(envToBool('anythingelse')).toStrictEqual(false);
109+
expect(envToBool('false')).toStrictEqual(false);
110+
});
111+
112+
it('should return false when input is not a string', () => {
113+
expect(
114+
// @ts-expect-error "envToBool" only supports "string" as a input
115+
envToBool(true)
116+
).toStrictEqual(false);
117+
});
118+
});
89119
});

0 commit comments

Comments
 (0)