-
Notifications
You must be signed in to change notification settings - Fork 314
Expand file tree
/
Copy pathutils.test.ts
More file actions
47 lines (40 loc) · 1.58 KB
/
utils.test.ts
File metadata and controls
47 lines (40 loc) · 1.58 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
/**
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/
import * as assert from 'assert';
import * as path from 'path';
import { loadNativeModule } from './utils';
const nativeName = process.platform === 'win32' ? 'conpty' : 'pty';
describe('utils', () => {
describe('loadNativeModule', () => {
afterEach(() => {
delete process.env.NODE_PTY_PREBUILT_PATH;
});
it('should load from NODE_PTY_PREBUILT_PATH when set to a valid path', () => {
const validPath = path.resolve(__dirname, '..', 'build', 'Release');
process.env.NODE_PTY_PREBUILT_PATH = validPath;
const result = loadNativeModule(nativeName);
assert.strictEqual(result.dir, validPath);
assert.ok(result.module);
});
it('should fall through to default paths when NODE_PTY_PREBUILT_PATH is invalid', () => {
process.env.NODE_PTY_PREBUILT_PATH = '/nonexistent/path';
const result = loadNativeModule(nativeName);
assert.ok(result.dir !== '/nonexistent/path');
assert.ok(result.module);
});
it('should load normally when NODE_PTY_PREBUILT_PATH is not set', () => {
delete process.env.NODE_PTY_PREBUILT_PATH;
const result = loadNativeModule(nativeName);
assert.ok(result.dir);
assert.ok(result.module);
});
it('should include NODE_PTY_PREBUILT_PATH in error message when all paths fail', () => {
process.env.NODE_PTY_PREBUILT_PATH = '/nonexistent/path';
assert.throws(
() => loadNativeModule('does-not-exist'),
(err: Error) => err.message.includes('/nonexistent/path')
);
});
});
});