Skip to content

Commit 96d9b2f

Browse files
committed
CI
1 parent 4922d9c commit 96d9b2f

15 files changed

+170
-94
lines changed

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
name: Lint
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Use Node.js ${{ matrix.node_version }}
13+
uses: actions/setup-node@v2
14+
with:
15+
node-version: "22"
16+
- name: Prepare env
17+
run: yarn install --ignore-scripts --frozen-lockfile
18+
- name: Run linter
19+
run: yarn start lint
20+
21+
prettier:
22+
name: Prettier Check
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Use Node.js ${{ matrix.node_version }}
28+
uses: actions/setup-node@v2
29+
with:
30+
node-version: "22"
31+
- name: Prepare env
32+
run: yarn install --ignore-scripts --frozen-lockfile
33+
- name: Run prettier
34+
run: yarn start prettier
35+
36+
test:
37+
name: Unit Tests
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: Use Node.js ${{ matrix.node_version }}
43+
uses: actions/setup-node@v2
44+
with:
45+
node-version: "22"
46+
- name: Prepare env
47+
run: yarn install --ignore-scripts --frozen-lockfile
48+
- name: Run unit tests
49+
run: yarn start test
50+
- name: Run code coverage
51+
uses: codecov/[email protected]

.github/workflows/lock.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Lock Threads"
2+
3+
on:
4+
schedule:
5+
- cron: "0 * * * *"
6+
workflow_dispatch:
7+
8+
permissions:
9+
issues: write
10+
pull-requests: write
11+
12+
concurrency:
13+
group: lock
14+
15+
jobs:
16+
action:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: dessant/lock-threads@v3
20+
with:
21+
issue-inactive-days: "365"
22+
issue-lock-reason: "resolved"
23+
pr-inactive-days: "365"
24+
pr-lock-reason: "resolved"

package-scripts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ module.exports = {
5757
description: 'Generates table of contents in README',
5858
script: 'doctoc README.md'
5959
},
60+
prettier: {
61+
description: 'Runs prettier on everything',
62+
script: 'prettier --write "**/*.([jt]s*)"'
63+
},
6064
copyTypes: series('tsc --declaration --emitDeclarationOnly --outDir dist'),
6165
lint: {
6266
description: 'lint the entire project',

src/concat.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import concat from './concat'
2-
import { MutableState, Tools } from 'final-form'
2+
import { MutableState } from 'final-form'
3+
import { createMockTools } from './testUtils'
34

45
describe('concat', () => {
56
const getOp = (value: any) => {
@@ -11,7 +12,7 @@ describe('concat', () => {
1112
values: {}
1213
}
1314
} as any
14-
concat(['foo', value], mockState, { changeValue } as unknown as Tools<any>)
15+
concat(['foo', value], mockState, createMockTools({ changeValue }))
1516
return changeValue.mock.calls[0][2]
1617
}
1718

@@ -24,7 +25,7 @@ describe('concat', () => {
2425
values: {}
2526
}
2627
} as any
27-
const result = concat(['foo', ['bar', 'baz']], state, { changeValue } as unknown as Tools<any>)
28+
const result = concat(['foo', ['bar', 'baz']], state, createMockTools({ changeValue }))
2829
expect(result).toBeUndefined()
2930
expect(changeValue).toHaveBeenCalled()
3031
expect(changeValue).toHaveBeenCalledTimes(1)

src/insert.test.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import insert from './insert'
2-
import { getIn, setIn, MutableState, Tools } from 'final-form'
2+
import { getIn, setIn, MutableState } from 'final-form'
3+
import { createMockTools } from './testUtils'
34

45
describe('insert', () => {
56
const getOp = (index, value: any) => {
@@ -24,7 +25,7 @@ describe('insert', () => {
2425
} as any
2526
}
2627
}
27-
insert(['foo', index, value], state, { changeValue, resetFieldState } as unknown as Tools<any>)
28+
insert(['foo', index, value], state, createMockTools({ changeValue, resetFieldState }))
2829
return changeValue.mock.calls[0][2]
2930
}
3031

@@ -54,10 +55,7 @@ describe('insert', () => {
5455
}
5556
}
5657
}
57-
const result = insert(['foo', 0, 'bar'], state, {
58-
changeValue,
59-
resetFieldState
60-
} as unknown as Tools<any>)
58+
const result = insert(['foo', 0, 'bar'], state, createMockTools({ changeValue, resetFieldState }))
6159
expect(result).toBeUndefined()
6260
expect(changeValue).toHaveBeenCalled()
6361
expect(changeValue).toHaveBeenCalledTimes(1)
@@ -123,10 +121,7 @@ describe('insert', () => {
123121
} as any
124122
}
125123
}
126-
const returnValue = insert(['foo', 1, 'NEWVALUE'], state, {
127-
changeValue,
128-
resetFieldState
129-
} as unknown as Tools<any>)
124+
const returnValue = insert(['foo', 1, 'NEWVALUE'], state, createMockTools({ changeValue, resetFieldState }))
130125
expect(returnValue).toBeUndefined()
131126
expect(state.formState.values.foo).not.toBe(array) // copied
132127
expect(state).toEqual({
@@ -216,10 +211,7 @@ describe('insert', () => {
216211
} as any
217212
}
218213
}
219-
const returnValue = insert(['foo[0]', 1, 'NEWVALUE'], state, {
220-
changeValue,
221-
resetFieldState
222-
} as unknown as Tools<any>)
214+
const returnValue = insert(['foo[0]', 1, 'NEWVALUE'], state, createMockTools({ changeValue, resetFieldState }))
223215
expect(returnValue).toBeUndefined()
224216
expect(state.formState.values.foo).not.toBe(array) // copied
225217
expect(state).toEqual({

src/move.test.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import move from './move'
2-
import { getIn, setIn, MutableState, Tools } from 'final-form'
2+
import { getIn, setIn, MutableState } from 'final-form'
3+
import { createMockTools } from './testUtils'
34

45
describe('move', () => {
5-
const getOp = (from, to: any) => {
6+
const getOp = (from: any, to: any) => {
67
const changeValue = jest.fn()
7-
move(['foo', from, to], { fields: {} }, { changeValue } as unknown as Tools<any>)
8+
const mockTools = createMockTools({ changeValue })
9+
move(['foo', from, to], { fields: {} } as any, mockTools)
810
return changeValue.mock.calls[0][2]
911
}
1012

1113
it('should do nothing if from and to are equal', () => {
1214
const changeValue = jest.fn()
13-
const result = move(['foo', 1, 1], { fields: {} }, { changeValue } as unknown as Tools<any>)
15+
const mockTools = createMockTools({ changeValue })
16+
const result = move(['foo', 1, 1], { fields: {} } as any, mockTools)
1417
expect(result).toBeUndefined()
1518
expect(changeValue).not.toHaveBeenCalled()
1619
})
1720

1821
it('should call changeValue once', () => {
1922
const changeValue = jest.fn()
20-
const state: MutableState<any> = { fields: {} }
21-
const result = move(['foo', 0, 2], state, { changeValue } as unknown as Tools<any>)
23+
const state: MutableState<any> = { fields: {} } as any
24+
const mockTools = createMockTools({ changeValue })
25+
const result = move(['foo', 0, 2], state, mockTools)
2226
expect(result).toBeUndefined()
2327
expect(changeValue).toHaveBeenCalled()
2428
expect(changeValue).toHaveBeenCalledTimes(1)
@@ -85,7 +89,7 @@ describe('move', () => {
8589
}
8690
}
8791
}
88-
move(['foo', 0, 2], state, { changeValue } as unknown as Tools<any>)
92+
move(['foo', 0, 2], state, createMockTools({ changeValue }))
8993
expect(state).toEqual({
9094
formState: {
9195
values: {
@@ -161,7 +165,7 @@ describe('move', () => {
161165
}
162166
}
163167
}
164-
move(['foo', 2, 0], state, { changeValue } as unknown as Tools<any>)
168+
move(['foo', 2, 0], state, createMockTools({ changeValue }))
165169
expect(state).toEqual({
166170
formState: {
167171
values: {
@@ -258,7 +262,7 @@ describe('move', () => {
258262
} as any
259263
}
260264
}
261-
move(['foo', 0, 2], state, { changeValue } as unknown as Tools<any>)
265+
move(['foo', 0, 2], state, createMockTools({ changeValue }))
262266
expect(state).toMatchObject({
263267
formState: {
264268
values: {
@@ -379,7 +383,7 @@ describe('move', () => {
379383
} as any
380384
}
381385
}
382-
move(['foo', 2, 0], state, { changeValue } as unknown as Tools<any>)
386+
move(['foo', 2, 0], state, createMockTools({ changeValue }))
383387
expect(state).toMatchObject({
384388
formState: {
385389
values: {
@@ -471,7 +475,7 @@ describe('move', () => {
471475
} as any
472476
}
473477
}
474-
move(['foo', 0, 1], state, { changeValue } as unknown as Tools<any>)
478+
move(['foo', 0, 1], state, createMockTools({ changeValue }))
475479
expect(state).toMatchObject({
476480
formState: {
477481
values: {
@@ -510,8 +514,8 @@ describe('move', () => {
510514
const state: MutableState<any> = {
511515
formState: {
512516
values: {
513-
foo: [{ dog: 'apple dog', cat: 'apple cat', colors: [{ name: 'red'}, { name: 'blue'}], deep: { inside: { rock: 'black'}} },
514-
{ dog: 'banana dog', mouse: 'mickey', deep: { inside: { axe: 'golden' }} }]
517+
foo: [{ dog: 'apple dog', cat: 'apple cat', colors: [{ name: 'red' }, { name: 'blue' }], deep: { inside: { rock: 'black' } } },
518+
{ dog: 'banana dog', mouse: 'mickey', deep: { inside: { axe: 'golden' } } }]
515519
}
516520
},
517521
fields: {
@@ -557,12 +561,12 @@ describe('move', () => {
557561
} as any,
558562
}
559563
}
560-
move(['foo', 0, 1], state, { changeValue } as unknown as Tools<any>)
564+
move(['foo', 0, 1], state, createMockTools({ changeValue }))
561565
expect(state).toMatchObject({
562566
formState: {
563567
values: {
564-
foo: [{ dog: 'banana dog', mouse: 'mickey', deep: { inside: { axe: 'golden' }} },
565-
{ dog: 'apple dog', cat: 'apple cat', colors: [{ name: 'red'}, { name: 'blue'}], deep: { inside: { rock: 'black'}} }]
568+
foo: [{ dog: 'banana dog', mouse: 'mickey', deep: { inside: { axe: 'golden' } } },
569+
{ dog: 'apple dog', cat: 'apple cat', colors: [{ name: 'red' }, { name: 'blue' }], deep: { inside: { rock: 'black' } } }]
566570
}
567571
},
568572
fields: {
@@ -660,7 +664,7 @@ describe('move', () => {
660664
}
661665
}
662666
}
663-
move(['foo', 0, 2], state, { changeValue } as unknown as Tools<any>)
667+
move(['foo', 0, 2], state, createMockTools({ changeValue }))
664668
expect(state.fields['foo[0]'].change()).toBe('foo[0]')
665669
expect(state.fields['foo[1]'].change()).toBe('foo[1]')
666670
expect(state.fields['foo[2]'].change()).toBe('foo[2]')

src/pop.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pop from './pop'
2-
import { getIn, setIn, MutableState, Tools } from 'final-form'
2+
import { getIn, setIn, MutableState } from 'final-form'
3+
import { createMockTools } from './testUtils'
34

45
describe('pop', () => {
56
it('should call changeValue once', () => {
@@ -23,7 +24,7 @@ describe('pop', () => {
2324
} as any
2425
}
2526
}
26-
const result = pop(['foo'], state, { changeValue, getIn, setIn } as unknown as Tools<any>)
27+
const result = pop(['foo'], state, createMockTools({ changeValue, getIn, setIn }))
2728
expect(result).toBeUndefined()
2829
expect(changeValue).toHaveBeenCalled()
2930
expect(changeValue).toHaveBeenCalledTimes(1)
@@ -47,7 +48,7 @@ describe('pop', () => {
4748
},
4849
fields: {}
4950
} as any
50-
const returnValue = pop(['foo'], state, { changeValue, getIn, setIn } as unknown as Tools<any>)
51+
const returnValue = pop(['foo'], state, createMockTools({ changeValue, getIn, setIn }))
5152
expect(returnValue).toBeUndefined()
5253
const result = state.formState.foo
5354
expect(result).toBeUndefined()
@@ -68,7 +69,7 @@ describe('pop', () => {
6869
},
6970
fields: {}
7071
} as any
71-
const returnValue = pop(['foo'], state, { changeValue, getIn, setIn } as unknown as Tools<any>)
72+
const returnValue = pop(['foo'], state, createMockTools({ changeValue, getIn, setIn }))
7273
expect(returnValue).toBeUndefined()
7374
const result = state.formState.values.foo
7475
expect(Array.isArray(result)).toBe(true)
@@ -101,7 +102,7 @@ describe('pop', () => {
101102
} as any
102103
}
103104
}
104-
const returnValue = pop(['foo'], state, { changeValue, getIn, setIn } as unknown as Tools<any>)
105+
const returnValue = pop(['foo'], state, createMockTools({ changeValue, getIn, setIn }))
105106
const result = state.formState.values.foo
106107
expect(returnValue).toBe('c')
107108
expect(Array.isArray(result)).toBe(true)
@@ -150,7 +151,7 @@ describe('pop', () => {
150151
}
151152
}
152153
}
153-
const returnValue = pop(['foo'], state, { changeValue, getIn, setIn } as unknown as Tools<any>)
154+
const returnValue = pop(['foo'], state, createMockTools({ changeValue, getIn, setIn }))
154155
expect(returnValue).toBe('d')
155156
expect(Array.isArray(state.formState.values.foo)).toBe(true)
156157
expect(state.formState.values.foo).not.toBe(array) // copied
@@ -227,7 +228,7 @@ describe('pop', () => {
227228
}
228229
}
229230
}
230-
const returnValue = pop(['foo[0]'], state, { changeValue, getIn, setIn } as unknown as Tools<any>)
231+
const returnValue = pop(['foo[0]'], state, createMockTools({ changeValue, getIn, setIn }))
231232
expect(returnValue).toBe('d')
232233
expect(Array.isArray(state.formState.values.foo)).toBe(true)
233234
expect(state.formState.values.foo).not.toBe(array) // copied

src/push.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ describe('push', () => {
55
const getOp = (value: any) => {
66
const changeValue = jest.fn()
77
const mockState = createMockState()
8-
push(['foo', value], mockState, createMockTools({ changeValue }))
8+
const mockTools = createMockTools({ changeValue })
9+
push(['foo', value], mockState, mockTools)
910
return changeValue.mock.calls[0][2]
1011
}
1112

1213
it('should call changeValue once', () => {
1314
const changeValue = jest.fn()
1415
const state = createMockState()
15-
const result = push(['foo', 'bar'], state, createMockTools({ changeValue }))
16+
const tools = createMockTools({ changeValue })
17+
const result = push(['foo', 'bar'], state, tools)
1618
expect(result).toBeUndefined()
1719
expect(changeValue).toHaveBeenCalled()
1820
expect(changeValue).toHaveBeenCalledTimes(1)

0 commit comments

Comments
 (0)