Skip to content

Commit 07525ee

Browse files
committed
first batch
1 parent 79c16a1 commit 07525ee

19 files changed

Lines changed: 695 additions & 9 deletions

AGENTS.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@
4141
- File naming: `.ts` files must be `kebab-case`, `.tsx` must be `CAMEL_CASE`.
4242
- Semicolons are disabled (Prettier). Single quotes preferred.
4343

44-
## Type definition workflow
45-
46-
1. Edit `files/index.d.ts`.
47-
2. Add type test in `source/*-spec.ts`.
48-
3. Verify with `yarn test:typings`.
49-
4. Use `// @ts-expect-error` for tests expected to fail.
50-
5144
## Build note
5245

5346
`yarn out` requires `rambda-scripts` cloned as a sibling directory (`../rambda-scripts`). Without it, `populatedocs`, `populatereadme`, and `create-docsify` will fail.

files/DEV_NOTES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
your task is big so 1. build a plan with todo in refactor.md 2. each "next" from dev will perform 10% of the task. 3. task is to move tests from foo.spec.js to foo-spec.ts 3.1 include test testing if foo-spec.ts exists 4. verify that it works with running node node_modules/vitest/
2+
dist/cli.js run --config vitest.typings.config.js source/foo.spec.ts
3+
4+
Goal: migrate runtime source/*.spec.js tests and source/*-spec.ts to source/*.spec.ts form
5+
1. Write refactor.md at repo root listing every method that has either *.spec.js or *-spec.ts file(or both), grouped into 10 batches of ~10% each, in dependency order.
6+
2. Each dev next completes one batch: create foo.spec.js using foo-spec.ts(if exists) and foo.spec.js(if exists)
7+
2.1 Extend TS tests to assert also final result(which is missing in -spec.ts files)
8+
2.2 If there is error on TS types after moving *.spec.js file, use `any` to make TS happy
9+
2.3 don't delete the old files.
10+
3. While running the batch, work file by file because you need to verify new file is correct with "node node_modules/vitest/
11+
dist/cli.js run --config vitest.typings.config.js source/foo.spec.ts" and "bun lint:typings"
12+
===
113
https://github.com/radashi-org/radashi/pull/425/changes
214

315

list_specs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
import os
3+
4+
os.chdir(os.path.join(os.path.dirname(__file__), 'source'))
5+
spec_js = {f.replace('.spec.js','') for f in os.listdir() if f.endswith('.spec.js')}
6+
spec_ts = {f.replace('-spec.ts','') for f in os.listdir() if f.endswith('-spec.ts')}
7+
exclude = {'radashi-comparison','remeda-comparison','convertToType','transformPropObject','_playground'}
8+
spec_js.difference_update(exclude)
9+
spec_ts.difference_update(exclude)
10+
both = sorted(spec_js & spec_ts)
11+
only_js = sorted(spec_js - spec_ts)
12+
only_ts = sorted(spec_ts - spec_js)
13+
14+
all_methods = sorted(spec_js | spec_ts)
15+
print('Total methods:', len(all_methods))
16+
print()
17+
print('=== Both (%d) ===' % len(both))
18+
for b in both: print(b)
19+
print()
20+
print('=== Only .spec.js (%d) ===' % len(only_js))
21+
for b in only_js: print(b)
22+
print()
23+
print('=== Only -spec.ts (%d) ===' % len(only_ts))
24+
for b in only_ts: print(b)
25+
print()
26+
# Print all methods for the refactor.md
27+
print('=== ALL METHODS (alphabetical) ===')
28+
for m in all_methods: print(m)

refactor.md

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# Spec file migration: `*.spec.js` + `*-spec.ts``*.spec.ts`
2+
3+
## ORIGINAL PROMPT
4+
5+
Goal: migrate runtime source/*.spec.js tests and source/*-spec.ts to source/*.spec.ts form
6+
1. Write refactor.md at repo root listing every method that has either *.spec.js or *-spec.ts file(or both), grouped into 10 batches of ~10% each, in dependency order.
7+
2. Each dev next completes one batch: create foo.spec.js using foo-spec.ts(if exists) and foo.spec.js(if exists)
8+
2.1 Extend TS tests to assert also final result(which is missing in -spec.ts files)
9+
2.2 If there is error on TS types after moving *.spec.js file, use `any` to make TS happy
10+
2.3 don't delete the old files.
11+
3. While running the batch, work file by file because you need to verify new file is correct with "node node_modules/vitest/
12+
dist/cli.js run --config vitest.typings.config.js source/foo.spec.ts" and "bun lint:typings"
13+
14+
## Current state
15+
16+
| Category | Count |
17+
|---|---|
18+
| Methods with both `*.spec.js` and `*-spec.ts` | 100 |
19+
| Methods with only `*.spec.js` | 26 |
20+
| Methods with only `*-spec.ts` | 5 |
21+
| **Total methods to migrate** | **131** |
22+
23+
## Goal per method
24+
25+
Create `source/foo.spec.ts` that combines:
26+
1. **Runtime tests** from `source/foo.spec.js``test(...)` / `expect(...)` calls
27+
2. **Type tests** from `source/foo-spec.ts``expectTypeOf(...)` calls
28+
3. **Extend** type tests to assert the **final runtime result value** (current `-spec.ts` files only check types, not values)
29+
4. If TypeScript complains about types from the JS runtime test code, use `any` to suppress
30+
5. **Do NOT delete** old `*.spec.js` or `*-spec.ts` files
31+
32+
33+
## Verification per file
34+
35+
```bash
36+
node node_modules/vitest/dist/cli.js source/foo.spec.ts
37+
bun lint:typings
38+
```
39+
40+
## EXAMPLE TARGET
41+
42+
```
43+
import { addProp, pipe } from 'rambda'
44+
import { test, expect, expectTypeOf } from 'vitest';
45+
46+
test('happy', () => {
47+
const result = addProp('a', 1)({ b: 2 })
48+
const expected = { a: 1, b: 2 }
49+
50+
expect(result).toEqual(expected)
51+
})
52+
53+
test('type test', () => {
54+
const result = pipe({ a: 1, b: 'foo' }, addProp('c', 3))
55+
expectTypeOf(result.a).toEqualTypeOf<number>()
56+
expectTypeOf(result.b).toEqualTypeOf<string>()
57+
expectTypeOf(result.c).toEqualTypeOf<number>()
58+
expect(result).toEqual({ a: 1, b: 'foo', c: 3 })
59+
})
60+
```
61+
62+
PLEASE NOTE THAT IMPORT ARE IN PLACE AND METHODS ARE IMPORTED `from 'rambda'`
63+
64+
---
65+
66+
## Batches (~13 files each, alphabetical)
67+
68+
### Batch 1 (13)
69+
addProp, addPropToObjects, all, allPass, any, anyPass, append, ascend, assertType, checkObjectWithSpec, combinations, compact, complement
70+
71+
| Method | `.spec.js` | `-spec.ts` |
72+
|---|---|---|
73+
| addProp |||
74+
| addPropToObjects |||
75+
| all |||
76+
| allPass |||
77+
| any |||
78+
| anyPass |||
79+
| append |||
80+
| ascend |||
81+
| assertType |||
82+
| checkObjectWithSpec |||
83+
| combinations |||
84+
| compact |||
85+
| complement |||
86+
87+
### Batch 2 (13)
88+
concat, count, countBy, createObjectFromKeys, defaultTo, difference, drop, dropLast, dropLastWhile, dropWhile, duplicateBy, eqBy, eqProps
89+
90+
| Method | `.spec.js` | `-spec.ts` |
91+
|---|---|---|
92+
| concat |||
93+
| count |||
94+
| countBy |||
95+
| createObjectFromKeys |||
96+
| defaultTo |||
97+
| difference |||
98+
| drop |||
99+
| dropLast |||
100+
| dropLastWhile |||
101+
| dropWhile |||
102+
| duplicateBy |||
103+
| eqBy |||
104+
| eqProps |||
105+
106+
### Batch 3 (13)
107+
equals, evolve, excludes, exists, filter, filterAsync, filterMap, filterObject, find, findIndex, findLastIndex, findNth, flatMap
108+
109+
| Method | `.spec.js` | `-spec.ts` |
110+
|---|---|---|
111+
| equals |||
112+
| evolve |||
113+
| excludes |||
114+
| exists |||
115+
| filter |||
116+
| filterAsync |||
117+
| filterMap |||
118+
| filterObject |||
119+
| find |||
120+
| findIndex |||
121+
| findLastIndex |||
122+
| findNth |||
123+
| flatMap |||
124+
125+
### Batch 4 (13)
126+
flatten, flattenObject, groupBy, head, includes, indexBy, indexOf, init, interpolate, intersection, intersectionWith, intersperse, isValid
127+
128+
| Method | `.spec.js` | `-spec.ts` |
129+
|---|---|---|
130+
| flatten |||
131+
| flattenObject |||
132+
| groupBy |||
133+
| head |||
134+
| includes |||
135+
| indexBy |||
136+
| indexOf |||
137+
| init |||
138+
| interpolate |||
139+
| intersection |||
140+
| intersectionWith |||
141+
| intersperse |||
142+
| isValid |||
143+
144+
### Batch 5 (13)
145+
join, last, lastIndexOf, map, mapAsync, mapChain, mapKeys, mapObject, mapObjectAsync, mapParallelAsync, mapPropObject, match, maxBy
146+
147+
| Method | `.spec.js` | `-spec.ts` |
148+
|---|---|---|
149+
| join |||
150+
| last |||
151+
| lastIndexOf |||
152+
| map |||
153+
| mapAsync |||
154+
| mapChain |||
155+
| mapKeys |||
156+
| mapObject |||
157+
| mapObjectAsync |||
158+
| mapParallelAsync |||
159+
| mapPropObject |||
160+
| match |||
161+
| maxBy |||
162+
163+
### Batch 6 (13)
164+
merge, mergeDeep, middle, minBy, modifyItemAtIndex, modifyPath, modifyProp, none, objOf, objectIncludes, omit, partition, partitionObject
165+
166+
| Method | `.spec.js` | `-spec.ts` |
167+
|---|---|---|
168+
| merge |||
169+
| mergeDeep |||
170+
| middle |||
171+
| minBy |||
172+
| modifyItemAtIndex |||
173+
| modifyPath |||
174+
| modifyProp |||
175+
| none |||
176+
| objOf |||
177+
| objectIncludes |||
178+
| omit |||
179+
| partition |||
180+
| partitionObject |||
181+
182+
### Batch 7 (13)
183+
path, pathSatisfies, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, random, range
184+
185+
| Method | `.spec.js` | `-spec.ts` |
186+
|---|---|---|
187+
| path |||
188+
| pathSatisfies |||
189+
| pick |||
190+
| pipe |||
191+
| pipeAsync |||
192+
| pluck |||
193+
| prepend |||
194+
| prop |||
195+
| propEq |||
196+
| propOr |||
197+
| propSatisfies |||
198+
| random |||
199+
| range |||
200+
201+
### Batch 8 (13)
202+
rangeDescending, reduce, reject, rejectObject, remove, replace, replaceAll, shuffle, sort, sortBy, sortByDescending, sortByPath, sortByPathDescending
203+
204+
| Method | `.spec.js` | `-spec.ts` |
205+
|---|---|---|
206+
| rangeDescending |||
207+
| reduce |||
208+
| reject |||
209+
| rejectObject |||
210+
| remove |||
211+
| replace |||
212+
| replaceAll |||
213+
| shuffle |||
214+
| sort |||
215+
| sortBy |||
216+
| sortByDescending |||
217+
| sortByPath |||
218+
| sortByPathDescending |||
219+
220+
### Batch 9 (13)
221+
sortByProps, sortObject, sortWith, splitEvery, splitEveryStrict, sum, switcher, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile
222+
223+
| Method | `.spec.js` | `-spec.ts` |
224+
|---|---|---|
225+
| sortByProps |||
226+
| sortObject |||
227+
| sortWith |||
228+
| splitEvery |||
229+
| splitEveryStrict |||
230+
| sum |||
231+
| switcher |||
232+
| symmetricDifference |||
233+
| tail |||
234+
| take |||
235+
| takeLast |||
236+
| takeLastWhile |||
237+
| takeWhile |||
238+
239+
### Batch 10 (14)
240+
test, tryCatch, type, union, unionWith, uniq, uniqBy, uniqWith, unless, unwind, update, when, zip, zipWith
241+
242+
| Method | `.spec.js` | `-spec.ts` |
243+
|---|---|---|
244+
| test |||
245+
| tryCatch |||
246+
| type |||
247+
| union |||
248+
| unionWith |||
249+
| uniq |||
250+
| uniqBy |||
251+
| uniqWith |||
252+
| unless |||
253+
| unwind |||
254+
| update |||
255+
| when |||
256+
| zip |||
257+
| zipWith |||

source/addProp.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { addProp } from './addProp'
2+
import { pipe } from './pipe'
3+
import { test, expect, expectTypeOf } from 'vitest';
4+
5+
test('happy', () => {
6+
const result = addProp('a', 1)({ b: 2 })
7+
const expected = { a: 1, b: 2 }
8+
9+
expect(result).toEqual(expected)
10+
})
11+
12+
test('type test', () => {
13+
const result = pipe({ a: 1, b: 'foo' }, addProp('c', 3))
14+
expectTypeOf(result.a).toEqualTypeOf<number>()
15+
expectTypeOf(result.b).toEqualTypeOf<string>()
16+
expectTypeOf(result.c).toEqualTypeOf<number>()
17+
expect(result).toEqual({ a: 1, b: 'foo', c: 3 })
18+
})

source/addPropToObjects.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { pipe } from './pipe'
2+
import { addPropToObjects } from './addPropToObjects'
3+
4+
test('R.addPropToObjects', () => {
5+
let result = pipe(
6+
[
7+
{a: 1, b: 2},
8+
{a: 3, b: 4},
9+
],
10+
addPropToObjects(
11+
'c',
12+
(x: { a: number; b: number }) => String(x.a + x.b),
13+
)
14+
)
15+
expectTypeOf(result).toEqualTypeOf<{ a: number; b: number; c: string }[]>()
16+
expect(result).toEqual([
17+
{ a: 1, b: 2, c: '3' },
18+
{ a: 3, b: 4, c: '7' },
19+
])
20+
})

source/all.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { all } from './all.js'
2+
import { pipe } from './pipe.js'
3+
4+
const list = [0, 1, 2, 3, 4]
5+
6+
test('when true', () => {
7+
const fn = (x: number) => x > -1
8+
9+
expect(all(fn)(list)).toBeTruthy()
10+
})
11+
12+
test('when false', () => {
13+
const fn = (x: number) => x > 2
14+
15+
expect(all(fn)(list)).toBeFalsy()
16+
})
17+
18+
test('type test', () => {
19+
const result = pipe(
20+
[1, 2, 3],
21+
all((x: number) => {
22+
expectTypeOf(x).toEqualTypeOf<number>()
23+
return x > 0
24+
}),
25+
)
26+
expectTypeOf(result).toEqualTypeOf<boolean>()
27+
expect(result).toBe(true)
28+
})

0 commit comments

Comments
 (0)