Skip to content

Commit

Permalink
feat: don't compile to esm, swap to vitest
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
Arcath committed Apr 4, 2024
1 parent 26bbcac commit bd4a94d
Show file tree
Hide file tree
Showing 46 changed files with 3,021 additions and 716 deletions.
17 changes: 0 additions & 17 deletions jest.config.js

This file was deleted.

3,593 changes: 2,933 additions & 660 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
"main": "lib/index.js",
"sideEffects": false,
"scripts": {
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules kcd-scripts test --runInBand --detectOpenHandles",
"test": "vitest",
"lint": "kcd-scripts lint",
"build": "tsc",
"build:index": "node ./scripts/build.cjs",
"document": "typedoc --out ./docs --entryPoints src/index.ts --name Utils --readme Readme.md && echo utils.arcath.net > ./docs/CNAME",
"validate": "kcd-scripts validate",
"format": "kcd-scripts format"
},
"type": "module",
"author": "Adam Laycock <adam@arcath.net>",
"author": "Adam Laycock <adam@alaycock.co.uk>",
"license": "MIT",
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.5",
"cross-env": "^7.0.3",
"@vitest/coverage-istanbul": "^1.4.0",
"expect-type": "^0.15.0",
"jest": "^29.5.0",
"kcd-scripts": "^13.0.0",
"prettier": "^2.8.6",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typedoc": "^0.23.28",
"typescript": "^5.0.2"
"typescript": "^5.0.2",
"vitest": "^1.4.0"
},
"dependencies": {
"read-pkg-up": "^9.1.0"
Expand Down
6 changes: 3 additions & 3 deletions src/classes/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint no-control-regex:off */
// eslint-disable-next-line
import {jest} from '@jest/globals'
import {expect, it, describe, vi} from 'vitest'

import {Logger} from './logger'

describe('Logger', () => {
it('should log messages', () => {
console.log = jest.fn()
console.log = vi.fn()

const logger = new Logger()

Expand Down Expand Up @@ -35,7 +35,7 @@ describe('Logger', () => {
})

it('should set a service name', () => {
console.log = jest.fn()
console.log = vi.fn()

const testLogger = new Logger('Service')

Expand Down
3 changes: 2 additions & 1 deletion src/functions/address-object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {expect, test, describe} from 'vitest'
import {addressObject, testObjectAddress} from './address-object'

describe('Address Object', () => {
it('should address an object', () => {
test('should address an object', () => {
const object = {
level1: {
level2: {
Expand Down
3 changes: 2 additions & 1 deletion src/functions/array-move.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {expect, test, describe} from 'vitest'
import {arrayMove} from './array-move'

describe('Array Move', () => {
it('should move objects in an array', () => {
test('should move objects in an array', () => {
const a = [1, 2, 3, 4, 5, 6]

const b = arrayMove(a, 1, 2)
Expand Down
3 changes: 2 additions & 1 deletion src/functions/array-selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {expect, test, describe} from 'vitest'
import {randomEntry} from './array-selectors'

describe('Array Selectors', () => {
it('should select a random entry', () => {
test('should select a random entry', () => {
const array = [1, 2, 3, 4]

const random = randomEntry(array)
Expand Down
1 change: 1 addition & 0 deletions src/functions/async-for-each.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {asyncForEach} from './async-for-each'

describe('Async For Each (in sequence)', () => {
Expand Down
8 changes: 5 additions & 3 deletions src/functions/async-for-each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export const asyncForEach = async <T>(
array: T[],
itterator: (value: T, index: number, array: T[]) => Promise<void>
): Promise<void> => {
const promises = array.map((value, index, arr) =>
itterator(value, index, arr)
)
const promises = array.map((value, index, arr) => {
const promise = itterator(value, index, arr)

return promise
})

await Promise.all(promises)
}
Expand Down
3 changes: 2 additions & 1 deletion src/functions/async-map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {expect, test, describe} from 'vitest'
import {asyncMap} from './async-map'

describe('Async Map', () => {
it('should work async', async () => {
test('should work async', async () => {
const array = [1, 2, 3]

const newArray = await asyncMap(array, n => {
Expand Down
7 changes: 4 additions & 3 deletions src/functions/bit-mask.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, test, describe} from 'vitest'
import {bitMask} from './bit-mask'

const READ = 'read'
Expand All @@ -9,7 +10,7 @@ type Permission = typeof EXECUTE | typeof READ | typeof WRITE
const Bits: Permission[] = [READ, WRITE, EXECUTE]

describe('BitMask', () => {
it('should set values', () => {
test('should set values', () => {
const mask = bitMask(0, Bits)

expect(mask.get(READ)).toBe(false)
Expand All @@ -25,7 +26,7 @@ describe('BitMask', () => {
expect(mask.get(READ)).toBe(false)
})

it('should work with arrays', () => {
test('should work with arrays', () => {
const mask = bitMask(0, Bits)

expect(mask.asArray()).toHaveLength(0)
Expand All @@ -43,7 +44,7 @@ describe('BitMask', () => {
expect(mask2.get(READ)).toBe(false)
})

it('should have default values', () => {
test('should have default values', () => {
const mask = bitMask()

expect(mask.value()).toBe(0)
Expand Down
17 changes: 7 additions & 10 deletions src/functions/cache-for.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line
import {jest} from '@jest/globals'
import {expect, test, describe, vi} from 'vitest'

import {
cacheForSync,
Expand All @@ -10,10 +9,8 @@ import {
cacheKeyExists
} from './cache-for'

jest.setTimeout(20000)

describe('Cache For', () => {
it('should cache a value syncronously', async () => {
test('should cache a value syncronously', async () => {
const key = 'test'
let n = 1

Expand Down Expand Up @@ -43,7 +40,7 @@ describe('Cache For', () => {
})
})

it('should cache a value asyncrousnly', async () => {
test('should cache a value asyncrousnly', async () => {
const key = 'testing'
let n = 1

Expand Down Expand Up @@ -73,13 +70,13 @@ describe('Cache For', () => {
})
})

it('should accept a default duration', () => {
test('should accept a default duration', () => {
const value = cacheForSync({key: 'tested'}, () => 'test')

expect(value).toBe('test')
})

it('should support durationless caching', () => {
test('should support durationless caching', () => {
const value = () => {
return Math.random()
}
Expand All @@ -99,8 +96,8 @@ describe('Cache For', () => {
expect(cacheKeyExists('no-duration')).toBe(false)
})

it('should only run the function once', () => {
const mockFn = jest.fn().mockReturnValue(10)
test('should only run the function once', () => {
const mockFn = vi.fn().mockReturnValue(10)

cacheKey('no-calls', () => mockFn())

Expand Down
1 change: 1 addition & 0 deletions src/functions/clamp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {clamp} from './clamp'

describe('clamp', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/create-map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {createMap} from './create-map'

describe('Create Map', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/css.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {
pxToNumber,
emToNumber,
Expand Down
1 change: 1 addition & 0 deletions src/functions/dates.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {lastModifiedHeaderDate} from './dates'

describe('Dates', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/functions/deep-includes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {expect, it, describe} from 'vitest'
import {deepIncludesArray} from './deep-includes'

describe('Deep Includes', () => {
test('it should return the correct value', () => {
it('should return the correct value', () => {
const array = [
[1, 'two', 3],
[4, 'five', 6],
Expand Down
1 change: 1 addition & 0 deletions src/functions/defaults.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {defaults} from './defaults'

describe('Defaults', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/diff-array.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {diffArray} from './diff-array'

describe('diffArray', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/diff-object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {diffObject} from './diff-object'

describe('Diff Object', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/grouped-by.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {groupedBy} from './grouped-by'

describe('Grouped By', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/if-fn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {ifFn} from './if-fn'
import {hasDevDependency} from './package'

Expand Down
1 change: 1 addition & 0 deletions src/functions/increment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint jest/no-conditional-in-test:off */
/* eslint jest/no-conditional-expect:off */

import {expect, it, describe} from 'vitest'
import {increment, decrement} from './increment'

describe('Increment', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/indexed-by.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {indexedBy} from './indexed-by'

describe('Indexed By', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/invariant.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {expectTypeOf} from 'expect-type'

import {invariant} from './invariant'
Expand Down
1 change: 1 addition & 0 deletions src/functions/is-env.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {isEnv} from './is-env'

describe('isEnv', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/keys.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {keys, keyValue} from './keys'

describe('Keys', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/map-property.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {mapProperty} from './map-property'

describe('Map Property', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/network.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {parseCDIR} from './network'

describe('Network', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/nl2br.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {nl2br} from './nl2br'

describe('NL2BR', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/functions/package.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint @typescript-eslint/no-shadow:off */
import path from 'path'

import {expect, it, describe} from 'vitest'

import {
getPackage,
hasDependency,
Expand Down Expand Up @@ -36,9 +38,9 @@ describe('Package Fns', () => {

expect(hasDependency('read-pkg-up')).toBeTruthy()
expect(hasDependency('electron')).toBeFalsy()
expect(hasDevDependency('jest')).toBeTruthy()
expect(hasDevDependency('vitest')).toBeTruthy()
expect(hasPeerDependency('esbuild')).toBeFalsy()
expect(hasAnyDependency('jest')).toBeTruthy()
expect(hasAnyDependency('vitest')).toBeTruthy()
expect(ifDependency('read-pkg-up', 'pass', 'fail')).toBe('pass')
expect(ifDevDependency('read-pkg-up', 'pass', 'fail')).toBe('fail')
expect(ifPeerDependency('read-pkg-up', 'pass', 'fail')).toBe('fail')
Expand Down
1 change: 1 addition & 0 deletions src/functions/parameterize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {parameterize} from './parameterize'

describe('Parameterize', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/pick.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {pick, omit} from './pick'

describe('Pick & Omit', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/range-as-string.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {rangeAsString, rangeAsArray} from './range-as-string'

describe('Range As String', () => {
Expand Down
9 changes: 5 additions & 4 deletions src/functions/reduce.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// eslint-disable-next-line
import {jest} from '@jest/globals'

import {expect, it, describe, vi} from 'vitest'
import {reduceTruthy, reduceFalsy, reducio} from './reduce'

describe('Reduce Functions', () => {
const returnInput = (e: boolean) => e

it('should reduce truthy', () => {
expect(reduceTruthy([true, true, false, true], e => e)).toBeFalsy()
expect(reduceTruthy([true, true, true, true], e => e)).toBeTruthy()
Expand All @@ -12,7 +13,7 @@ describe('Reduce Functions', () => {

it('should only call the check function until it hits a false', () => {
// eslint-disable-next-line
const check = jest.fn<(e: boolean) => boolean>(e => e)
const check = vi.fn().mockImplementation(returnInput)

reduceTruthy([true, true, false, true, true, true, false, true], check)

Expand All @@ -32,7 +33,7 @@ describe('Reduce Functions', () => {
).toBeFalsy()

// eslint-disable-next-line
const check = jest.fn<(e: boolean) => boolean>(e => e)
const check = vi.fn().mockImplementation(returnInput)

expect(reducio([true, true, false, false, true], check)).toBeTruthy()

Expand Down
1 change: 1 addition & 0 deletions src/functions/replace-property.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {replaceProperty} from './replace-property'

describe('Replace Property', () => {
Expand Down
1 change: 1 addition & 0 deletions src/functions/selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect, it, describe} from 'vitest'
import {propIs, propIsNot} from './selectors'

describe('Selectors', () => {
Expand Down
Loading

0 comments on commit bd4a94d

Please sign in to comment.