Skip to content

Commit 11f6bcf

Browse files
committed
Merge branch 'main' of github.com:formkit/jsonreader
2 parents acf68ca + 041a615 commit 11f6bcf

File tree

4 files changed

+282
-1
lines changed

4 files changed

+282
-1
lines changed

.github/workflows/tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 18
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v2
23+
with:
24+
version: latest
25+
run_install: false
26+
27+
- name: Get pnpm store directory
28+
id: pnpm-cache
29+
shell: bash
30+
run: |
31+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
32+
33+
- name: Setup pnpm cache
34+
uses: actions/cache@v3
35+
with:
36+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
37+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38+
restore-keys: |
39+
${{ runner.os }}-pnpm-store-
40+
41+
- name: Install dependencies
42+
run: pnpm install
43+
44+
- name: Run linting
45+
run: pnpm lint
46+
47+
- name: Run type checking
48+
run: pnpm --filter jsonreader typecheck
49+
50+
- name: Run tests
51+
run: pnpm test

packages/jsonreader/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"build": "tsup",
2424
"lint": "eslint src",
2525
"typecheck": "tsc --noEmit",
26-
"test": "vitest run"
26+
"test": "vitest run",
27+
"test:watch": "vitest",
28+
"test:coverage": "vitest run --coverage"
2729
},
2830
"keywords": [
2931
"json",
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`streaming json > can have required properties that are nested 1`] = `
4+
[
5+
{
6+
"foo": {
7+
"bim": "here",
8+
},
9+
},
10+
{
11+
"foo": {
12+
"baz": 1,
13+
"bim": "here",
14+
},
15+
},
16+
{
17+
"foo": {
18+
"baz": 12,
19+
"bim": "here",
20+
},
21+
},
22+
{
23+
"foo": {
24+
"baz": 123,
25+
"bim": "here",
26+
},
27+
},
28+
{
29+
"foo": {
30+
"baz": 123,
31+
"bim": "here",
32+
},
33+
"hello": "",
34+
},
35+
{
36+
"foo": {
37+
"baz": 123,
38+
"bim": "here",
39+
},
40+
"hello": "w",
41+
},
42+
{
43+
"foo": {
44+
"baz": 123,
45+
"bim": "here",
46+
},
47+
"hello": "wo",
48+
},
49+
{
50+
"foo": {
51+
"baz": 123,
52+
"bim": "here",
53+
},
54+
"hello": "wor",
55+
},
56+
{
57+
"foo": {
58+
"baz": 123,
59+
"bim": "here",
60+
},
61+
"hello": "worl",
62+
},
63+
{
64+
"foo": {
65+
"baz": 123,
66+
"bim": "here",
67+
},
68+
"hello": "world",
69+
},
70+
]
71+
`;
72+
73+
exports[`streaming json > can yield array property values 1`] = `
74+
[
75+
{
76+
"foo": [],
77+
},
78+
{
79+
"foo": [
80+
"",
81+
],
82+
},
83+
{
84+
"foo": [
85+
"o",
86+
],
87+
},
88+
{
89+
"foo": [
90+
"on",
91+
],
92+
},
93+
{
94+
"foo": [
95+
"one",
96+
],
97+
},
98+
{
99+
"foo": [
100+
"one",
101+
"",
102+
],
103+
},
104+
{
105+
"foo": [
106+
"one",
107+
"t",
108+
],
109+
},
110+
{
111+
"foo": [
112+
"one",
113+
"tw",
114+
],
115+
},
116+
{
117+
"foo": [
118+
"one",
119+
"two",
120+
],
121+
},
122+
{
123+
"foo": [
124+
"one",
125+
"two",
126+
1,
127+
],
128+
},
129+
{
130+
"foo": [
131+
"one",
132+
"two",
133+
12,
134+
],
135+
},
136+
{
137+
"foo": [
138+
"one",
139+
"two",
140+
123,
141+
],
142+
},
143+
{
144+
"baz": [],
145+
"foo": [
146+
"one",
147+
"two",
148+
123,
149+
],
150+
},
151+
{
152+
"baz": [
153+
1,
154+
],
155+
"foo": [
156+
"one",
157+
"two",
158+
123,
159+
],
160+
},
161+
{
162+
"baz": [
163+
12,
164+
],
165+
"foo": [
166+
"one",
167+
"two",
168+
123,
169+
],
170+
},
171+
{
172+
"baz": [
173+
123,
174+
],
175+
"foo": [
176+
"one",
177+
"two",
178+
123,
179+
],
180+
},
181+
]
182+
`;
183+
184+
exports[`streaming json > does not return early when dealing with nested strings of json 1`] = `
185+
[
186+
{
187+
"response": {},
188+
},
189+
{
190+
"response": {
191+
"routes": [],
192+
},
193+
},
194+
{
195+
"response": {
196+
"routes": [
197+
{
198+
"arguments_for_prompt": [
199+
{
200+
"key": "rewritten_prompt",
201+
"value": "Translate this input to German",
202+
},
203+
{
204+
"key": "rewritten_input",
205+
"value": "{"type":"page_break","idx":"1","key":"fvumampbuem","content":"$: \\"User Login\\""}",
206+
},
207+
],
208+
"instructions_for_prompt": "Translate this input to German",
209+
"prompt_name": "routeEditInput",
210+
},
211+
],
212+
},
213+
},
214+
]
215+
`;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
environment: 'node',
6+
include: ['tests/**/*.spec.ts'],
7+
coverage: {
8+
reporter: ['text', 'json', 'html'],
9+
exclude: ['**/node_modules/**', '**/dist/**', '**/tests/helpers/**']
10+
},
11+
globals: true,
12+
},
13+
})

0 commit comments

Comments
 (0)