Skip to content

Commit

Permalink
Created our own log-symbols ❇️
Browse files Browse the repository at this point in the history
- This means we don't have two modules for setting colours.
- Ability to customise symbols.
  • Loading branch information
01taylop committed Oct 26, 2024
1 parent 7261d16 commit 570e293
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 20 deletions.
5 changes: 0 additions & 5 deletions jest-config/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
* MOCKS AND SPIES
*/

jest.mock('log-symbols', () => ({
warning: '!',
error: 'X',
}))

jest.spyOn(process, 'exit').mockImplementation(code => {
throw new Error(`process.exit(${code})`)
})
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const config: JestConfigWithTsJest = {
'^.+\\.(js|ts)$': 'babel-jest',
},
transformIgnorePatterns: [
'./node_modules/(?!(chalk)/)',
'./node_modules/(?!(chalk|is-unicode-supported)/)',
],
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"eslint-plugin-sort-destructure-keys": "2.0.0",
"eslint-plugin-sort-exports": "0.9.1",
"glob": "10.4.5",
"log-symbols": "6.0.0",
"is-unicode-supported": "2.1.0",
"markdownlint": "0.35.0",
"markdownlint-rule-helpers": "0.26.0",
"node-notifier": "10.0.1",
Expand Down
38 changes: 38 additions & 0 deletions src/utils/__tests__/log-symbols.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import isUnicodeSupported from 'is-unicode-supported'

jest.mock('is-unicode-supported')

describe('logSymbols', () => {

afterEach(() => {
jest.resetModules()
})

it('returns Unicode symbols when supported', () => {
(isUnicodeSupported as jest.Mock).mockReturnValue(true)

const logSymbols = require('../log-symbols').default

expect(logSymbols).toEqual({
error: '✗',
info: 'ℹ',
success: '✓',
tipEmoji: '💡',
warning: '⚠',
})
})

it('returns fallback symbols when Unicode is not supported', () => {
(isUnicodeSupported as jest.Mock).mockReturnValue(false)

const logSymbols = require('../log-symbols').default

expect(logSymbols).toEqual({
error: '×',
info: '[i]',
success: '√',
tipEmoji: 'TIP:',
warning: '‼',
})
})
})
17 changes: 17 additions & 0 deletions src/utils/log-symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import isUnicodeSupported from 'is-unicode-supported'

const _isUnicodeSupported = isUnicodeSupported()

const error = _isUnicodeSupported ? '✗' : '×'
const info = _isUnicodeSupported ? 'ℹ' : '[i]'
const success = _isUnicodeSupported ? '✓' : '√'
const tipEmoji = _isUnicodeSupported ? '💡' : 'TIP:'
const warning = _isUnicodeSupported ? '⚠' : '‼'

export default {
error,
info,
success,
tipEmoji,
warning,
}
18 changes: 5 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ [email protected], chalk@^4.0.0, chalk@^4.0.2:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

[email protected], chalk@^5.3.0:
[email protected]:
version "5.3.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385"
integrity sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==
Expand Down Expand Up @@ -3461,10 +3461,10 @@ is-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077"
integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==

is-unicode-supported@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz#d824984b616c292a2e198207d4a609983842f714"
integrity sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==
is-unicode-supported@2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-2.1.0.tgz#09f0ab0de6d3744d48d265ebb98f65d11f2a9b3a"
integrity sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==

is-wsl@^2.2.0:
version "2.2.0"
Expand Down Expand Up @@ -4072,14 +4072,6 @@ lodash.truncate@^4.4.2:
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
integrity sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==

[email protected]:
version "6.0.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-6.0.0.tgz#bb95e5f05322651cac30c0feb6404f9f2a8a9439"
integrity sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==
dependencies:
chalk "^5.3.0"
is-unicode-supported "^1.3.0"

lru-cache@^10.2.0:
version "10.2.2"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.2.tgz#48206bc114c1252940c41b25b41af5b545aca878"
Expand Down

0 comments on commit 570e293

Please sign in to comment.