this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

restore argument validation

+300 -4
+230 -3
package-lock.json
··· 13 13 ], 14 14 "dependencies": { 15 15 "bplist-parser": "^0.3.2", 16 + "ow": "^3.1.1", 16 17 "run-applescript": "^7.0.0" 17 18 }, 18 19 "devDependencies": { ··· 1471 1472 "dev": true, 1472 1473 "license": "MIT" 1473 1474 }, 1475 + "node_modules/@sindresorhus/is": { 1476 + "version": "7.2.0", 1477 + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-7.2.0.tgz", 1478 + "integrity": "sha512-P1Cz1dWaFfR4IR+U13mqqiGsLFf1KbayybWwdd2vfctdV6hDpUkgCY0nKOLLTMSoRd/jJNjtbqzf13K8DCCXQw==", 1479 + "license": "MIT", 1480 + "engines": { 1481 + "node": ">=18" 1482 + }, 1483 + "funding": { 1484 + "url": "https://github.com/sindresorhus/is?sponsor=1" 1485 + } 1486 + }, 1474 1487 "node_modules/@sindresorhus/merge-streams": { 1475 1488 "version": "4.0.0", 1476 1489 "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-4.0.0.tgz", ··· 2685 2698 "dev": true, 2686 2699 "license": "MIT" 2687 2700 }, 2701 + "node_modules/convert-hrtime": { 2702 + "version": "5.0.0", 2703 + "resolved": "https://registry.npmjs.org/convert-hrtime/-/convert-hrtime-5.0.0.tgz", 2704 + "integrity": "sha512-lOETlkIeYSJWcbbcvjRKGxVMXJR+8+OQb/mTPbA4ObPMytYIsUbuOE0Jzy60hjARYszq1id0j8KgVhC+WGZVTg==", 2705 + "license": "MIT", 2706 + "engines": { 2707 + "node": ">=12" 2708 + }, 2709 + "funding": { 2710 + "url": "https://github.com/sponsors/sindresorhus" 2711 + } 2712 + }, 2688 2713 "node_modules/convert-source-map": { 2689 2714 "version": "2.0.0", 2690 2715 "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", ··· 2945 2970 "node": ">=0.10.0" 2946 2971 } 2947 2972 }, 2973 + "node_modules/dot-prop": { 2974 + "version": "10.1.0", 2975 + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-10.1.0.tgz", 2976 + "integrity": "sha512-MVUtAugQMOff5RnBy2d9N31iG0lNwg1qAoAOn7pOK5wf94WIaE3My2p3uwTQuvS2AcqchkcR3bHByjaM0mmi7Q==", 2977 + "license": "MIT", 2978 + "dependencies": { 2979 + "type-fest": "^5.0.0" 2980 + }, 2981 + "engines": { 2982 + "node": ">=20" 2983 + }, 2984 + "funding": { 2985 + "url": "https://github.com/sponsors/sindresorhus" 2986 + } 2987 + }, 2948 2988 "node_modules/dunder-proto": { 2949 2989 "version": "1.0.1", 2950 2990 "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", ··· 3031 3071 "version": "1.1.0", 3032 3072 "resolved": "https://registry.npmjs.org/environment/-/environment-1.1.0.tgz", 3033 3073 "integrity": "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==", 3034 - "dev": true, 3035 3074 "license": "MIT", 3036 3075 "engines": { 3037 3076 "node": ">=18" ··· 3956 3995 "dev": true, 3957 3996 "license": "Apache-2.0" 3958 3997 }, 3998 + "node_modules/fast-equals": { 3999 + "version": "5.4.0", 4000 + "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.4.0.tgz", 4001 + "integrity": "sha512-jt2DW/aNFNwke7AUd+Z+e6pz39KO5rzdbbFCg2sGafS4mk13MI7Z8O5z9cADNn5lhGODIgLwug6TZO2ctf7kcw==", 4002 + "license": "MIT", 4003 + "engines": { 4004 + "node": ">=6.0.0" 4005 + } 4006 + }, 3959 4007 "node_modules/fast-glob": { 3960 4008 "version": "3.3.3", 3961 4009 "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", ··· 4190 4238 "url": "https://github.com/sponsors/ljharb" 4191 4239 } 4192 4240 }, 4241 + "node_modules/function-timeout": { 4242 + "version": "1.0.2", 4243 + "resolved": "https://registry.npmjs.org/function-timeout/-/function-timeout-1.0.2.tgz", 4244 + "integrity": "sha512-939eZS4gJ3htTHAldmyyuzlrD58P03fHG49v2JfFXbV6OhvZKRC9j2yAtdHw/zrp2zXHuv05zMIy40F0ge7spA==", 4245 + "license": "MIT", 4246 + "engines": { 4247 + "node": ">=18" 4248 + }, 4249 + "funding": { 4250 + "url": "https://github.com/sponsors/sindresorhus" 4251 + } 4252 + }, 4193 4253 "node_modules/function.prototype.name": { 4194 4254 "version": "1.1.8", 4195 4255 "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.8.tgz", ··· 4589 4649 "node": ">=18.18.0" 4590 4650 } 4591 4651 }, 4652 + "node_modules/identifier-regex": { 4653 + "version": "1.0.1", 4654 + "resolved": "https://registry.npmjs.org/identifier-regex/-/identifier-regex-1.0.1.tgz", 4655 + "integrity": "sha512-ZrYyM0sozNPZlvBvE7Oq9Bn44n0qKGrYu5sQ0JzMUnjIhpgWYE2JB6aBoFwEYdPjqj7jPyxXTMJiHDOxDfd8yw==", 4656 + "license": "MIT", 4657 + "dependencies": { 4658 + "reserved-identifiers": "^1.0.0" 4659 + }, 4660 + "engines": { 4661 + "node": ">=18" 4662 + }, 4663 + "funding": { 4664 + "url": "https://github.com/sponsors/sindresorhus" 4665 + } 4666 + }, 4592 4667 "node_modules/ignore": { 4593 4668 "version": "5.3.2", 4594 4669 "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", ··· 4907 4982 "node": ">=0.10.0" 4908 4983 } 4909 4984 }, 4985 + "node_modules/is-identifier": { 4986 + "version": "1.0.1", 4987 + "resolved": "https://registry.npmjs.org/is-identifier/-/is-identifier-1.0.1.tgz", 4988 + "integrity": "sha512-HQ5v4rEJ7REUV54bCd2l5FaD299SGDEn2UPoVXaTHAyGviLq2menVUD2udi3trQ32uvB6LdAh/0ck2EuizrtpA==", 4989 + "license": "MIT", 4990 + "dependencies": { 4991 + "identifier-regex": "^1.0.0", 4992 + "super-regex": "^1.0.0" 4993 + }, 4994 + "engines": { 4995 + "node": ">=18" 4996 + }, 4997 + "funding": { 4998 + "url": "https://github.com/sponsors/sindresorhus" 4999 + } 5000 + }, 4910 5001 "node_modules/is-in-ssh": { 4911 5002 "version": "1.0.0", 4912 5003 "resolved": "https://registry.npmjs.org/is-in-ssh/-/is-in-ssh-1.0.0.tgz", ··· 5507 5598 "yallist": "^3.0.2" 5508 5599 } 5509 5600 }, 5601 + "node_modules/make-asynchronous": { 5602 + "version": "1.1.0", 5603 + "resolved": "https://registry.npmjs.org/make-asynchronous/-/make-asynchronous-1.1.0.tgz", 5604 + "integrity": "sha512-ayF7iT+44LXdxJLTrTd3TLQpFDDvPCBxXxbv+pMUSuHA5Q8zyAfwkRP6aHHwNVFBUFWtxAHqwNJxF8vMZLAbVg==", 5605 + "license": "MIT", 5606 + "dependencies": { 5607 + "p-event": "^6.0.0", 5608 + "type-fest": "^4.6.0", 5609 + "web-worker": "^1.5.0" 5610 + }, 5611 + "engines": { 5612 + "node": ">=18" 5613 + }, 5614 + "funding": { 5615 + "url": "https://github.com/sponsors/sindresorhus" 5616 + } 5617 + }, 5618 + "node_modules/make-asynchronous/node_modules/type-fest": { 5619 + "version": "4.41.0", 5620 + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", 5621 + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", 5622 + "license": "(MIT OR CC0-1.0)", 5623 + "engines": { 5624 + "node": ">=16" 5625 + }, 5626 + "funding": { 5627 + "url": "https://github.com/sponsors/sindresorhus" 5628 + } 5629 + }, 5510 5630 "node_modules/math-intrinsics": { 5511 5631 "version": "1.1.0", 5512 5632 "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", ··· 5889 6009 "node": ">= 0.8.0" 5890 6010 } 5891 6011 }, 6012 + "node_modules/ow": { 6013 + "version": "3.1.1", 6014 + "resolved": "https://registry.npmjs.org/ow/-/ow-3.1.1.tgz", 6015 + "integrity": "sha512-Hixi5roGFYZuiPV2pnnBi1hXdRG0uqifxE8rCCU6lKeCCQS+VGihuJnYxaJSffDz/clyH+xB2z1hXYRzeIcUMA==", 6016 + "license": "MIT", 6017 + "dependencies": { 6018 + "@sindresorhus/is": "^7.1.0", 6019 + "callsites": "^4.2.0", 6020 + "dot-prop": "^10.1.0", 6021 + "environment": "^1.1.0", 6022 + "fast-equals": "^5.3.2", 6023 + "is-identifier": "^1.0.1" 6024 + }, 6025 + "engines": { 6026 + "node": ">=20" 6027 + }, 6028 + "funding": { 6029 + "url": "https://github.com/sponsors/sindresorhus" 6030 + } 6031 + }, 6032 + "node_modules/ow/node_modules/callsites": { 6033 + "version": "4.2.0", 6034 + "resolved": "https://registry.npmjs.org/callsites/-/callsites-4.2.0.tgz", 6035 + "integrity": "sha512-kfzR4zzQtAE9PC7CzZsjl3aBNbXWuXiSeOCdLcPpBfGW8YuCqQHcRPFDbr/BPVmd3EEPVpuFzLyuT/cUhPr4OQ==", 6036 + "license": "MIT", 6037 + "engines": { 6038 + "node": ">=12.20" 6039 + }, 6040 + "funding": { 6041 + "url": "https://github.com/sponsors/sindresorhus" 6042 + } 6043 + }, 5892 6044 "node_modules/own-keys": { 5893 6045 "version": "1.0.1", 5894 6046 "resolved": "https://registry.npmjs.org/own-keys/-/own-keys-1.0.1.tgz", ··· 5977 6129 "@oxc-resolver/binding-win32-x64-msvc": "11.19.1" 5978 6130 } 5979 6131 }, 6132 + "node_modules/p-event": { 6133 + "version": "6.0.1", 6134 + "resolved": "https://registry.npmjs.org/p-event/-/p-event-6.0.1.tgz", 6135 + "integrity": "sha512-Q6Bekk5wpzW5qIyUP4gdMEujObYstZl6DMMOSenwBvV0BlE5LkDwkjs5yHbZmdCEq2o4RJx4tE1vwxFVf2FG1w==", 6136 + "license": "MIT", 6137 + "dependencies": { 6138 + "p-timeout": "^6.1.2" 6139 + }, 6140 + "engines": { 6141 + "node": ">=16.17" 6142 + }, 6143 + "funding": { 6144 + "url": "https://github.com/sponsors/sindresorhus" 6145 + } 6146 + }, 5980 6147 "node_modules/p-limit": { 5981 6148 "version": "3.1.0", 5982 6149 "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", ··· 6009 6176 "url": "https://github.com/sponsors/sindresorhus" 6010 6177 } 6011 6178 }, 6179 + "node_modules/p-timeout": { 6180 + "version": "6.1.4", 6181 + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-6.1.4.tgz", 6182 + "integrity": "sha512-MyIV3ZA/PmyBN/ud8vV9XzwTrNtR4jFrObymZYnZqMmW0zA8Z17vnT0rBgFE/TlohB+YCHqXMgZzb3Csp49vqg==", 6183 + "license": "MIT", 6184 + "engines": { 6185 + "node": ">=14.16" 6186 + }, 6187 + "funding": { 6188 + "url": "https://github.com/sponsors/sindresorhus" 6189 + } 6190 + }, 6012 6191 "node_modules/package-json-validator": { 6013 6192 "version": "1.3.1", 6014 6193 "resolved": "https://registry.npmjs.org/package-json-validator/-/package-json-validator-1.3.1.tgz", ··· 6351 6530 }, 6352 6531 "bin": { 6353 6532 "regjsparser": "bin/parser" 6533 + } 6534 + }, 6535 + "node_modules/reserved-identifiers": { 6536 + "version": "1.2.0", 6537 + "resolved": "https://registry.npmjs.org/reserved-identifiers/-/reserved-identifiers-1.2.0.tgz", 6538 + "integrity": "sha512-yE7KUfFvaBFzGPs5H3Ops1RevfUEsDc5Iz65rOwWg4lE8HJSYtle77uul3+573457oHvBKuHYDl/xqUkKpEEdw==", 6539 + "license": "MIT", 6540 + "engines": { 6541 + "node": ">=18" 6542 + }, 6543 + "funding": { 6544 + "url": "https://github.com/sponsors/sindresorhus" 6354 6545 } 6355 6546 }, 6356 6547 "node_modules/resolve": { ··· 6968 7159 "url": "https://github.com/sponsors/sindresorhus" 6969 7160 } 6970 7161 }, 7162 + "node_modules/super-regex": { 7163 + "version": "1.1.0", 7164 + "resolved": "https://registry.npmjs.org/super-regex/-/super-regex-1.1.0.tgz", 7165 + "integrity": "sha512-WHkws2ZflZe41zj6AolvvmaTrWds/VuyeYr9iPVv/oQeaIoVxMKaushfFWpOGDT+GuBrM/sVqF8KUCYQlSSTdQ==", 7166 + "license": "MIT", 7167 + "dependencies": { 7168 + "function-timeout": "^1.0.1", 7169 + "make-asynchronous": "^1.0.1", 7170 + "time-span": "^5.1.0" 7171 + }, 7172 + "engines": { 7173 + "node": ">=18" 7174 + }, 7175 + "funding": { 7176 + "url": "https://github.com/sponsors/sindresorhus" 7177 + } 7178 + }, 6971 7179 "node_modules/supports-color": { 6972 7180 "version": "10.2.2", 6973 7181 "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-10.2.2.tgz", ··· 7031 7239 "version": "1.0.0", 7032 7240 "resolved": "https://registry.npmjs.org/tagged-tag/-/tagged-tag-1.0.0.tgz", 7033 7241 "integrity": "sha512-yEFYrVhod+hdNyx7g5Bnkkb0G6si8HJurOoOEgC8B/O0uXLHlaey/65KRv6cuWBNhBgHKAROVpc7QyYqE5gFng==", 7034 - "dev": true, 7035 7242 "license": "MIT", 7036 7243 "engines": { 7037 7244 "node": ">=20" ··· 7054 7261 "url": "https://opencollective.com/webpack" 7055 7262 } 7056 7263 }, 7264 + "node_modules/time-span": { 7265 + "version": "5.1.0", 7266 + "resolved": "https://registry.npmjs.org/time-span/-/time-span-5.1.0.tgz", 7267 + "integrity": "sha512-75voc/9G4rDIJleOo4jPvN4/YC4GRZrY8yy1uU4lwrB3XEQbWve8zXoO5No4eFrGcTAMYyoY67p8jRQdtA1HbA==", 7268 + "license": "MIT", 7269 + "dependencies": { 7270 + "convert-hrtime": "^5.0.0" 7271 + }, 7272 + "engines": { 7273 + "node": ">=12" 7274 + }, 7275 + "funding": { 7276 + "url": "https://github.com/sponsors/sindresorhus" 7277 + } 7278 + }, 7057 7279 "node_modules/tinyglobby": { 7058 7280 "version": "0.2.16", 7059 7281 "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.16.tgz", ··· 7145 7367 "version": "5.5.0", 7146 7368 "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-5.5.0.tgz", 7147 7369 "integrity": "sha512-PlBfpQwiUvGViBNX84Yxwjsdhd1TUlXr6zjX7eoirtCPIr08NAmxwa+fcYBTeRQxHo9YC9wwF3m9i700sHma8g==", 7148 - "dev": true, 7149 7370 "license": "(MIT OR CC0-1.0)", 7150 7371 "dependencies": { 7151 7372 "tagged-tag": "^1.0.0" ··· 7421 7642 "engines": { 7422 7643 "node": "20 || >=22" 7423 7644 } 7645 + }, 7646 + "node_modules/web-worker": { 7647 + "version": "1.5.0", 7648 + "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.5.0.tgz", 7649 + "integrity": "sha512-RiMReJrTAiA+mBjGONMnjVDP2u3p9R1vkcGz6gDIrOMT3oGuYwX2WRMYI9ipkphSuE5XKEhydbhNEJh4NY9mlw==", 7650 + "license": "Apache-2.0" 7424 7651 }, 7425 7652 "node_modules/which": { 7426 7653 "version": "2.0.2",
+1
package.json
··· 32 32 }, 33 33 "dependencies": { 34 34 "bplist-parser": "^0.3.2", 35 + "ow": "^3.1.1", 35 36 "run-applescript": "^7.0.0" 36 37 }, 37 38 "devDependencies": {
+10
source/assert-terminal-profile.js
··· 1 + import ow from 'ow'; 2 + import getTerminalProfiles from './get-terminal-profiles.js'; 3 + 4 + /** 5 + * @param {string} profile 6 + * @return {Promise<void>} 7 + */ 8 + export default async function assertTerminalProfile(profile) { 9 + ow(profile, ow.string.oneOf(await getTerminalProfiles())); 10 + }
+3
source/set-terminal-default-profile.js
··· 1 1 import {execFile} from 'node:child_process'; 2 2 import {promisify} from 'node:util'; 3 3 import {runAppleScript} from 'run-applescript'; 4 + import assertTerminalProfile from './assert-terminal-profile.js'; 4 5 import isTerminalRunning from './is-terminal-running.js'; 5 6 6 7 const execute = promisify(execFile); ··· 12 13 * @return {Promise<void>} 13 14 */ 14 15 export default async function setTerminalDefaultProfile(profile) { 16 + await assertTerminalProfile(profile); 17 + 15 18 if (await isTerminalRunning()) { 16 19 await runAppleScript(`tell application "Terminal" 17 20 set default settings to settings set "${profile}"
+3
source/set-terminal-profile.js
··· 1 1 import {runAppleScript} from 'run-applescript'; 2 + import assertTerminalProfile from './assert-terminal-profile.js'; 2 3 import isTerminalRunning from './is-terminal-running.js'; 3 4 import setTerminalDefaultProfile from './set-terminal-default-profile.js'; 4 5 ··· 13 14 * @return {Promise<void>} 14 15 */ 15 16 export default async function setTerminalProfile({profile, setDefault}) { 17 + await assertTerminalProfile(profile); 18 + 16 19 if (await isTerminalRunning()) { 17 20 await runAppleScript(`tell application "Terminal" 18 21 set current settings of tabs of windows to settings set "${profile}"
+1
test/is-terminal-running.js
··· 32 32 ); 33 33 34 34 assert.equal(await isTerminalRunning(), false); 35 + }); 35 36 36 37 it('rethrows unexpected pgrep failures', async () => { 37 38 const error = new Error('spawn pgrep ENOENT');
+23
test/set-terminal-default-profile.js
··· 1 1 import {beforeEach, describe, it, mock} from 'node:test'; 2 2 import assert from 'node:assert/strict'; 3 + import {ArgumentError} from 'ow'; 3 4 4 5 const childProcess = {execFile: mock.fn()}; 5 6 mock.module('node:child_process', {namedExports: childProcess}); 6 7 7 8 const runAppleScript = mock.fn(); 8 9 mock.module('run-applescript', {namedExports: {runAppleScript}}); 10 + 11 + const assertTerminalProfile = mock.fn(); 12 + mock.module('../source/assert-terminal-profile.js', { 13 + defaultExport: assertTerminalProfile, 14 + }); 9 15 10 16 const isTerminalRunning = mock.fn(); 11 17 mock.module('../source/is-terminal-running.js', { ··· 19 25 beforeEach(() => { 20 26 childProcess.execFile.mock.resetCalls(); 21 27 runAppleScript.mock.resetCalls(); 28 + assertTerminalProfile.mock.resetCalls(); 22 29 isTerminalRunning.mock.resetCalls(); 23 30 }); 24 31 25 32 it('uses AppleScript when Terminal is running', async () => { 33 + assertTerminalProfile.mock.mockImplementation(async () => undefined); 26 34 isTerminalRunning.mock.mockImplementation(async () => true); 27 35 runAppleScript.mock.mockImplementation(async () => undefined); 28 36 ··· 39 47 }); 40 48 41 49 it('uses defaults command when Terminal is not running', async () => { 50 + assertTerminalProfile.mock.mockImplementation(async () => undefined); 42 51 isTerminalRunning.mock.mockImplementation(async () => false); 43 52 childProcess.execFile.mock.mockImplementation( 44 53 (_command, _args, callback) => { ··· 69 78 '-string', 70 79 'Profile', 71 80 ]); 81 + }); 82 + 83 + it('rejects an invalid profile before changing Terminal settings', async () => { 84 + const error = new ArgumentError( 85 + 'Expected string to be one of `["Profile"]`, got `Missing Profile`', 86 + ); 87 + assertTerminalProfile.mock.mockImplementation(async () => { 88 + throw error; 89 + }); 90 + 91 + await assert.rejects(setTerminalDefaultProfile('Missing Profile'), error); 92 + assert.equal(isTerminalRunning.mock.callCount(), 0); 93 + assert.equal(runAppleScript.mock.callCount(), 0); 94 + assert.equal(childProcess.execFile.mock.callCount(), 0); 72 95 }); 73 96 });
+29 -1
test/set-terminal-profile.js
··· 1 1 import {beforeEach, describe, it, mock} from 'node:test'; 2 2 import assert from 'node:assert/strict'; 3 + import {ArgumentError} from 'ow'; 3 4 4 5 const runAppleScript = mock.fn(); 5 6 mock.module('run-applescript', {namedExports: {runAppleScript}}); 7 + 8 + const assertTerminalProfile = mock.fn(); 9 + mock.module('../source/assert-terminal-profile.js', { 10 + defaultExport: assertTerminalProfile, 11 + }); 6 12 7 13 const isTerminalRunning = mock.fn(); 8 14 mock.module('../source/is-terminal-running.js', { ··· 20 26 describe('setTerminalProfile', () => { 21 27 beforeEach(() => { 22 28 runAppleScript.mock.resetCalls(); 29 + assertTerminalProfile.mock.resetCalls(); 23 30 isTerminalRunning.mock.resetCalls(); 24 31 setTerminalDefaultProfile.mock.resetCalls(); 25 32 }); 26 33 27 34 it('updates tabs via AppleScript when Terminal is running', async () => { 35 + assertTerminalProfile.mock.mockImplementation(async () => undefined); 28 36 isTerminalRunning.mock.mockImplementation(async () => true); 29 37 runAppleScript.mock.mockImplementation(async () => undefined); 30 38 ··· 41 49 }); 42 50 43 51 it('does not call AppleScript when Terminal is not running', async () => { 52 + assertTerminalProfile.mock.mockImplementation(async () => undefined); 44 53 isTerminalRunning.mock.mockImplementation(async () => false); 45 54 46 55 await setTerminalProfile({profile: 'Profile', setDefault: false}); ··· 49 58 }); 50 59 51 60 it('sets default profile when setDefault is true', async () => { 61 + assertTerminalProfile.mock.mockImplementation(async () => undefined); 52 62 isTerminalRunning.mock.mockImplementation(async () => false); 53 63 setTerminalDefaultProfile.mock.mockImplementation(async () => undefined); 54 64 55 65 await setTerminalProfile({profile: 'Profile', setDefault: true}); 56 66 57 - assert.equal(setTerminalDefaultProfile.mock.callCount(), 1); 67 + assert.ok(setTerminalDefaultProfile.mock.callCount() === 1); 58 68 assert.equal( 59 69 setTerminalDefaultProfile.mock.calls[0].arguments[0], 60 70 'Profile', ··· 62 72 }); 63 73 64 74 it('does not set default profile when setDefault is falsy', async () => { 75 + assertTerminalProfile.mock.mockImplementation(async () => undefined); 65 76 isTerminalRunning.mock.mockImplementation(async () => false); 66 77 67 78 await setTerminalProfile({profile: 'Profile', setDefault: false}); 68 79 80 + assert.equal(setTerminalDefaultProfile.mock.callCount(), 0); 81 + }); 82 + 83 + it('rejects an invalid profile before updating Terminal', async () => { 84 + const error = new ArgumentError( 85 + 'Expected string to be one of `["Profile"]`, got `Missing Profile`', 86 + ); 87 + assertTerminalProfile.mock.mockImplementation(async () => { 88 + throw error; 89 + }); 90 + 91 + await assert.rejects( 92 + setTerminalProfile({profile: 'Missing Profile', setDefault: true}), 93 + error, 94 + ); 95 + assert.equal(isTerminalRunning.mock.callCount(), 0); 96 + assert.equal(runAppleScript.mock.callCount(), 0); 69 97 assert.equal(setTerminalDefaultProfile.mock.callCount(), 0); 70 98 }); 71 99 });