snapshot of c000b74a5b09c433f96a69fa102c5c8f6583dff0 Annotations about the code that implements koment.

integrations/editors/vscode/binary.test.js

1 'use strict';
2
3 const assert = require('node:assert');
4 const path = require('node:path');
5 const { test } = require('node:test');
6 const { bundledBinary, ensureExecutable, resolveBinary } = require('./binary');
7
8 const never = () => false;
9 const always = () => true;
10
11 test('an explicit setting wins over the bundled binary', () => {
12 const resolved = resolveBinary({
13 configured: '/opt/koment/koment',
14 extensionPath: '/ext',
15 platform: 'linux',
16 exists: always
17 });
18 assert.deepStrictEqual(resolved, { command: '/opt/koment/koment', source: 'configured' });
19 });
20
21 test('a blank setting is not a path', () => {
22 for (const configured of ['', ' ', undefined, null]) {
23 const resolved = resolveBinary({ configured, extensionPath: '/ext', platform: 'linux', exists: always });
24 assert.strictEqual(resolved.source, 'bundled', `${JSON.stringify(configured)} should not be taken as a path`);
25 }
26 });
27
28 test('the bundled binary is used when the extension carries one', () => {
29 const resolved = resolveBinary({ extensionPath: '/ext', platform: 'linux', exists: always });
30 assert.deepStrictEqual(resolved, { command: path.join('/ext', 'bin', 'koment'), source: 'bundled' });
31 });
32
33 test('the universal package falls back to PATH', () => {
34 const resolved = resolveBinary({ extensionPath: '/ext', platform: 'linux', exists: never });
35 assert.deepStrictEqual(resolved, { command: 'koment', source: 'path' });
36 });
37
38 test('windows carries the executable suffix', () => {
39 assert.strictEqual(bundledBinary('/ext', 'win32'), path.join('/ext', 'bin', 'koment.exe'));
40 assert.strictEqual(bundledBinary('/ext', 'darwin'), path.join('/ext', 'bin', 'koment'));
41 });
42
43 test('a bundled binary without the executable bit is repaired', () => {
44 const chmodded = [];
45 const repaired = ensureExecutable('/ext/bin/koment', {
46 platform: 'linux',
47 stat: () => ({ mode: 0o644 }),
48 chmod: (file, mode) => chmodded.push([file, mode])
49 });
50 assert.strictEqual(repaired, true);
51 assert.deepStrictEqual(chmodded, [['/ext/bin/koment', 0o755]]);
52 });
53
54 test('an already executable binary is left alone', () => {
55 const repaired = ensureExecutable('/ext/bin/koment', {
56 platform: 'linux',
57 stat: () => ({ mode: 0o755 }),
58 chmod: () => assert.fail('should not chmod an executable file')
59 });
60 assert.strictEqual(repaired, false);
61 });
62
63 test('windows has no executable bit to repair', () => {
64 const repaired = ensureExecutable('C:\\ext\\bin\\koment.exe', {
65 platform: 'win32',
66 stat: () => assert.fail('should not stat on windows'),
67 chmod: () => assert.fail('should not chmod on windows')
68 });
69 assert.strictEqual(repaired, false);
70 });
71
72 test('a chmod failure is not swallowed', () => {
73 assert.throws(
74 () =>
75 ensureExecutable('/ext/bin/koment', {
76 platform: 'linux',
77 stat: () => ({ mode: 0o644 }),
78 chmod: () => {
79 throw new Error('read-only file system');
80 }
81 }),
82 /read-only file system/
83 );
84 });

Find an annotation

Search file paths, rationale, kinds, and authors.

moveEnter openEsc close