Skip to content

Commit

Permalink
feat: use generated index to exclude from coverage
Browse files Browse the repository at this point in the history
Breaking Change

Not really, but it feels like a good thing to draw a line under
  • Loading branch information
Arcath committed Mar 23, 2023
1 parent 727647f commit 247c794
Show file tree
Hide file tree
Showing 41 changed files with 77 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ jobs:
path: lib
key: lib-${{github.sha}}

- name: 🧙‍♂️ Build Index
run: npm run build:index

- name: 🏗 TypeScript
run: npm run build

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
node_modules/
lib/
lib/
src/index.ts
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules kcd-scripts test --runInBand --detectOpenHandles",
"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"
Expand Down
31 changes: 31 additions & 0 deletions scripts/build.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path')
const fs = require('fs')

const FUNCTIONS = path.join(__dirname, '..', 'src', 'functions')
const CLASSES = path.join(__dirname, '..', 'src', 'classes')

const INDEX = path.join(__dirname, '..', 'src', 'index.ts')

const lines = [`// Automatically generated by ./scripts/build.cjs`, '']

fs.readdir(FUNCTIONS, (err, files) => {
files.forEach(file => {
if (file.match(`\.spec\.`)) {
return
}

lines.push(`export * from './functions/${file.replace('.ts', '')}'`)
})

fs.readdir(CLASSES, (err, files) => {
files.forEach(file => {
if (file.match(`\.spec\.`)) {
return
}

lines.push(`export * from './classes/${file.replace('.ts', '')}'`)
})

fs.writeFile(INDEX, lines.join(`\r\n`), err => {})
})
})
2 changes: 1 addition & 1 deletion src/classes/bit-mask.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {BitMask} from '../'
import {BitMask} from './bit-mask'

const READ = 'read'
const WRITE = 'write'
Expand Down
2 changes: 1 addition & 1 deletion src/classes/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// eslint-disable-next-line
import {jest} from '@jest/globals'

import {Logger} from '../'
import {Logger} from './logger'

describe('Logger', () => {
it('should log messages', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/address-object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {addressObject, testObjectAddress} from '../'
import {addressObject, testObjectAddress} from './address-object'

describe('Address Object', () => {
it('should address an object', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/array-move.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {arrayMove} from '../index'
import {arrayMove} from './array-move'

describe('Array Move', () => {
it('should move objects in an array', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/array-selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {randomEntry} from '../'
import {randomEntry} from './array-selectors'

describe('Array Selectors', () => {
it('should select a random entry', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/async-for-each.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {asyncForEach} from '../'
import {asyncForEach} from './async-for-each'

describe('Async For Each (in sequence)', () => {
it('should work async', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/async-map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {asyncMap} from '../'
import {asyncMap} from './async-map'

describe('Async Map', () => {
it('should work async', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/cache-for.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
cacheKey,
resetCache,
cacheKeyExists
} from '../'
} from './cache-for'

jest.setTimeout(20000)

Expand Down
2 changes: 1 addition & 1 deletion src/functions/clamp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {clamp} from '../'
import {clamp} from './clamp'

describe('clamp', () => {
it('should clamp values', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/create-map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createMap} from '../'
import {createMap} from './create-map'

describe('Create Map', () => {
it('should create a map', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
numberToRem,
numberToVh,
numberToVw
} from '../'
} from './css'

describe('CSS', () => {
it('should conver units to numbers', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/functions/dates.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {lastModifiedHeaderDate} from '../index'
import {lastModifiedHeaderDate} from './dates'

describe('Dates', () => {
it('should generate a last modified date', () => {
const timeString = "Wed Apr 6 2022 09:38:39 GMT+0100 (British Summer Time)"
it('should generate a last modified date', () => {
const timeString = 'Wed Apr 6 2022 09:38:39 GMT+0100 (British Summer Time)'

const lastModified = lastModifiedHeaderDate(timeString)

expect(lastModified).toBe('Wed, 06 Apr 2022 08:38:39 GMT')
})
})
})
2 changes: 1 addition & 1 deletion src/functions/deep-includes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {deepIncludesArray} from '../index'
import {deepIncludesArray} from './deep-includes'

describe('Deep Includes', () => {
test('it should return the correct value', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/defaults.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defaults} from '../'
import {defaults} from './defaults'

describe('Defaults', () => {
it('should set defaults', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/diff-array.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {diffArray} from '../'
import {diffArray} from './diff-array'

describe('diffArray', () => {
it('should diff arrays', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/diff-object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {diffObject} from '../'
import {diffObject} from './diff-object'

describe('Diff Object', () => {
it('should diff two objects', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/grouped-by.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {groupedBy} from '../'
import {groupedBy} from './grouped-by'

describe('Grouped By', () => {
it('should group items', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/if-fn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ifFn} from '../index'
import {ifFn} from './if-fn'
import {hasDevDependency} from './package'

describe('If FN', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/increment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {increment, decrement} from '../index'
import {increment, decrement} from './increment'

describe('Increment', () => {
it('should increment', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/indexed-by.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {indexedBy} from '../'
import {indexedBy} from './indexed-by'

describe('Indexed By', () => {
it('should produce an index', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/invariant.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expectTypeOf} from 'expect-type'

import {invariant} from '../'
import {invariant} from './invariant'

describe('invariant', () => {
it('should throw errors', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/is-env.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isEnv} from '../'
import {isEnv} from './is-env'

describe('isEnv', () => {
it('should get the env', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/keys.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {keys, keyValue} from '../'
import {keys, keyValue} from './keys'

describe('Keys', () => {
it('should return an array of keys', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/map-property.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {mapProperty} from '../'
import {mapProperty} from './map-property'

describe('Map Property', () => {
it('should map properties', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/network.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {parseCDIR} from '../index'
import {parseCDIR} from './network'

describe('Network', () => {
it('should parse', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/nl2br.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {nl2br} from '../'
import {nl2br} from './nl2br'

describe('NL2BR', () => {
it('should add line breaks', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/parameterize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {parameterize} from '../'
import {parameterize} from './parameterize'

describe('Parameterize', () => {
it('should make strings safe for urls', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/pick.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {pick, omit} from '../'
import {pick, omit} from './pick'

describe('Pick & Omit', () => {
it('should pick elements', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/range-as-string.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {rangeAsString, rangeAsArray} from '../'
import {rangeAsString, rangeAsArray} from './range-as-string'

describe('Range As String', () => {
it('should create strings', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/reduce.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line
import {jest} from '@jest/globals'

import {reduceTruthy, reduceFalsy, reducio} from '../index'
import {reduceTruthy, reduceFalsy, reducio} from './reduce'

describe('Reduce Functions', () => {
it('should reduce truthy', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/replace-property.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {replaceProperty} from '../index'
import {replaceProperty} from './replace-property'

describe('Replace Property', () => {
it('should replace a property', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {propIs, propIsNot} from '../'
import {propIs, propIsNot} from './selectors'

describe('Selectors', () => {
it('should select items', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/time.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
HOUR_IN_MINUTES,
HOUR_IN_SECONDS,
HOUR_IN_MS
} from '../'
} from './time'

describe('Time FNS', () => {
it('should calculate values', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/times.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {times, asyncTimes} from '../'
import {times, asyncTimes} from './times'

describe('Times', () => {
it('should interate', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/unique.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {unique} from '../'
import {unique} from './unique'

describe('Unique', () => {
it('should find unique values', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/value-or.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {valueOr} from '../'
import {valueOr} from './value-or'

describe('ValueOr', () => {
it('should work', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/wait-for.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {waitFor} from '../'
import {waitFor} from './wait-for'

describe('waitFor', () => {
it('should return T', async () => {
Expand Down

0 comments on commit 247c794

Please sign in to comment.