this repo has no description
0
fork

Configure Feed

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

add tests

+192
+2
package.json
··· 38 38 "lint:fix": "npm run _eslint -- --fix", 39 39 "quality:check": "npm run format:check && npm run lint:check && npm run unused:check", 40 40 "quality:fix": "npm run format:fix && npm run lint:fix && npm run unused:fix", 41 + "test": "node --experimental-test-module-mocks --test", 42 + "test:coverage": "node --experimental-test-coverage --experimental-test-module-mocks --test", 41 43 "unused:check": "npm run _knip", 42 44 "unused:fix": "npm run _knip -- --fix" 43 45 },
+2
source/cli/actions/config/show.js
··· 1 + // eslint-disable-next-line n/prefer-global/console 2 + import console from 'node:console'; 1 3 import {styleText} from 'node:util'; 2 4 import {upperFirst} from 'es-toolkit/string'; 3 5 import {getConfig, modes} from '#library';
+71
test/config-set-mode.js
··· 1 + import {beforeEach, describe, it, mock} from 'node:test'; 2 + import assert from 'node:assert/strict'; 3 + 4 + const consola = {success: mock.fn()}; 5 + mock.module('consola', {namedExports: {consola}}); 6 + 7 + const macTerminal = {setTerminalProfile: mock.fn()}; 8 + mock.module('mac-terminal', {namedExports: macTerminal}); 9 + 10 + const config = {set: mock.fn()}; 11 + const library = { 12 + getCurrentMode: mock.fn(), 13 + getConfig: mock.fn(async () => config), 14 + }; 15 + mock.module('#library', {namedExports: library}); 16 + 17 + const {default: setMode} = 18 + await import('../source/cli/actions/config/set-mode.js'); 19 + 20 + describe('setMode', () => { 21 + beforeEach(() => { 22 + consola.success.mock.resetCalls(); 23 + macTerminal.setTerminalProfile.mock.resetCalls(); 24 + library.getCurrentMode.mock.resetCalls(); 25 + library.getConfig.mock.resetCalls(); 26 + config.set.mock.resetCalls(); 27 + }); 28 + 29 + it('saves the profile for the given mode', async () => { 30 + library.getCurrentMode.mock.mockImplementation(async () => 'light'); 31 + 32 + await setMode({mode: 'dark', profile: 'Profile'}); 33 + 34 + assert.equal(config.set.mock.calls[0].arguments[0], 'profiles.dark'); 35 + assert.equal(config.set.mock.calls[0].arguments[1], 'Profile'); 36 + }); 37 + 38 + it('logs a success message', async () => { 39 + library.getCurrentMode.mock.mockImplementation(async () => 'light'); 40 + 41 + await setMode({mode: 'dark', profile: 'Profile'}); 42 + 43 + assert.match( 44 + consola.success.mock.calls[0].arguments[0], 45 + /Saved configuration/v, 46 + ); 47 + }); 48 + 49 + it('updates terminal profile when mode matches current mode', async () => { 50 + library.getCurrentMode.mock.mockImplementation(async () => 'dark'); 51 + 52 + await setMode({mode: 'dark', profile: 'Profile'}); 53 + 54 + assert.equal(macTerminal.setTerminalProfile.mock.callCount(), 1); 55 + assert.deepEqual( 56 + macTerminal.setTerminalProfile.mock.calls[0].arguments[0], 57 + { 58 + profile: 'Profile', 59 + setDefault: true, 60 + }, 61 + ); 62 + }); 63 + 64 + it('does not update terminal profile when mode differs from current mode', async () => { 65 + library.getCurrentMode.mock.mockImplementation(async () => 'light'); 66 + 67 + await setMode({mode: 'dark', profile: 'Profile'}); 68 + 69 + assert.equal(macTerminal.setTerminalProfile.mock.callCount(), 0); 70 + }); 71 + });
+35
test/config-show.js
··· 1 + import {beforeEach, describe, it, mock} from 'node:test'; 2 + import assert from 'node:assert/strict'; 3 + 4 + const console = { 5 + log: mock.fn(), 6 + }; 7 + mock.module('node:console', {defaultExport: console}); 8 + 9 + const config = {get: mock.fn()}; 10 + const library = { 11 + getConfig: mock.fn(async () => config), 12 + modes: ['dark', 'light'], 13 + }; 14 + mock.module('#library', {namedExports: library}); 15 + 16 + const {default: show} = await import('../source/cli/actions/config/show.js'); 17 + 18 + describe('show', () => { 19 + beforeEach(() => { 20 + console.log.mock.resetCalls(); 21 + library.getConfig.mock.resetCalls(); 22 + config.get.mock.resetCalls(); 23 + }); 24 + 25 + it('logs each mode profile', async () => { 26 + config.get.mock.mockImplementation((key) => 27 + key === 'profiles.dark' ? 'Dark Profile' : 'Light Profile', 28 + ); 29 + 30 + await show(); 31 + 32 + assert.match(console.log.mock.calls[0].arguments[0], /Dark Profile/v); 33 + assert.match(console.log.mock.calls[1].arguments[0], /Light Profile/v); 34 + }); 35 + });
+26
test/get-current-mode.js
··· 1 + import {beforeEach, describe, it, mock} from 'node:test'; 2 + import assert from 'node:assert/strict'; 3 + 4 + const darkMode = {isEnabled: mock.fn()}; 5 + mock.module('dark-mode', {defaultExport: darkMode}); 6 + 7 + const {default: getCurrentMode} = 8 + await import('../source/library/get-current-mode.js'); 9 + 10 + describe('getCurrentMode', () => { 11 + beforeEach(() => { 12 + darkMode.isEnabled.mock.resetCalls(); 13 + }); 14 + 15 + it('returns dark when dark mode is enabled', async () => { 16 + darkMode.isEnabled.mock.mockImplementation(async () => true); 17 + 18 + assert.equal(await getCurrentMode(), 'dark'); 19 + }); 20 + 21 + it('returns light when dark mode is disabled', async () => { 22 + darkMode.isEnabled.mock.mockImplementation(async () => false); 23 + 24 + assert.equal(await getCurrentMode(), 'light'); 25 + }); 26 + });
+56
test/update.js
··· 1 + import {beforeEach, describe, it, mock} from 'node:test'; 2 + import assert from 'node:assert/strict'; 3 + 4 + const macTerminal = {setTerminalProfile: mock.fn()}; 5 + mock.module('mac-terminal', {namedExports: macTerminal}); 6 + 7 + const config = {get: mock.fn()}; 8 + const library = { 9 + getCurrentMode: mock.fn(), 10 + getConfig: mock.fn(async () => config), 11 + }; 12 + mock.module('#library', {namedExports: library}); 13 + 14 + const {default: update} = await import('../source/cli/actions/update.js'); 15 + 16 + describe('update', () => { 17 + beforeEach(() => { 18 + macTerminal.setTerminalProfile.mock.resetCalls(); 19 + library.getCurrentMode.mock.resetCalls(); 20 + library.getConfig.mock.resetCalls(); 21 + config.get.mock.resetCalls(); 22 + }); 23 + 24 + it('sets the terminal profile for the given mode', async () => { 25 + config.get.mock.mockImplementation(() => 'Profile'); 26 + 27 + await update({mode: 'dark'}); 28 + 29 + assert.equal(config.get.mock.calls[0].arguments[0], 'profiles.dark'); 30 + assert.deepEqual( 31 + macTerminal.setTerminalProfile.mock.calls[0].arguments[0], 32 + { 33 + profile: 'Profile', 34 + setDefault: true, 35 + }, 36 + ); 37 + }); 38 + 39 + it('uses current mode when mode is not provided', async () => { 40 + library.getCurrentMode.mock.mockImplementation(async () => 'light'); 41 + config.get.mock.mockImplementation(() => 'Profile'); 42 + 43 + await update({}); 44 + 45 + assert.equal(library.getCurrentMode.mock.callCount(), 1); 46 + assert.equal(config.get.mock.calls[0].arguments[0], 'profiles.light'); 47 + }); 48 + 49 + it('does not call getCurrentMode when mode is provided', async () => { 50 + config.get.mock.mockImplementation(() => 'Profile'); 51 + 52 + await update({mode: 'dark'}); 53 + 54 + assert.equal(library.getCurrentMode.mock.callCount(), 0); 55 + }); 56 + });