@usebruno/filestore 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/workers/worker-script.js +1 -1
- package/dist/cjs/workers/worker-script.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/workers/worker-script.js +1 -1
- package/dist/esm/workers/worker-script.js.map +1 -1
- package/dist/formats/bru/utils/redact-large-text-blocks.d.ts.map +1 -1
- package/dist/formats/yml/common/omit-headers.d.ts +3 -0
- package/dist/formats/yml/common/omit-headers.d.ts.map +1 -0
- package/dist/formats/yml/common/scripts.d.ts +3 -5
- package/dist/formats/yml/common/scripts.d.ts.map +1 -1
- package/dist/formats/yml/items/parseGrpcRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/parseHttpRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyGrpcRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyHttpRequest.d.ts.map +1 -1
- package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts.map +1 -1
- package/dist/formats/yml/parseCollection.d.ts.map +1 -1
- package/dist/formats/yml/parseEnvironment.d.ts.map +1 -1
- package/dist/formats/yml/stringifyCollection.d.ts.map +1 -1
- package/dist/formats/yml/stringifyEnvironment.d.ts.map +1 -1
- package/dist/formats/yml/stringifyFolder.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/formats/bru/tests/redact-large-text-blocks.spec.js +60 -0
- package/src/formats/bru/utils/redact-large-text-blocks.ts +4 -0
- package/src/formats/yml/common/omit-headers.spec.ts +16 -0
- package/src/formats/yml/common/omit-headers.ts +12 -0
- package/src/formats/yml/common/scripts.spec.ts +155 -0
- package/src/formats/yml/common/scripts.ts +55 -29
- package/src/formats/yml/grpc-round-trip.spec.ts +110 -0
- package/src/formats/yml/items/parseGraphQLRequest.ts +2 -2
- package/src/formats/yml/items/parseGrpcRequest.ts +14 -6
- package/src/formats/yml/items/parseHttpRequest.ts +8 -2
- package/src/formats/yml/items/stringifyGraphQLRequest.ts +5 -9
- package/src/formats/yml/items/stringifyGrpcRequest.ts +2 -1
- package/src/formats/yml/items/stringifyHttpRequest.ts +11 -9
- package/src/formats/yml/items/stringifyWebsocketRequest.ts +3 -1
- package/src/formats/yml/parseCollection.ts +5 -9
- package/src/formats/yml/parseEnvironment.spec.ts +49 -0
- package/src/formats/yml/parseEnvironment.ts +6 -0
- package/src/formats/yml/script.spec.ts +159 -0
- package/src/formats/yml/stringifyCollection.ts +7 -10
- package/src/formats/yml/stringifyEnvironment.spec.ts +58 -0
- package/src/formats/yml/stringifyEnvironment.ts +6 -0
- package/src/formats/yml/stringifyFolder.ts +3 -1
- package/src/maxRedirects.spec.ts +144 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { parseRequest, stringifyRequest } from './index';
|
|
2
|
+
import { DEFAULT_MAX_REDIRECTS } from '@usebruno/common/utils';
|
|
3
|
+
import type { CollectionFormat } from './types';
|
|
4
|
+
|
|
5
|
+
const FORMATS: CollectionFormat[] = ['bru', 'yml'];
|
|
6
|
+
|
|
7
|
+
const requestWithMaxRedirects = (maxRedirects: number) => ({
|
|
8
|
+
uid: 'req-uid',
|
|
9
|
+
name: 'Get Users',
|
|
10
|
+
type: 'http-request',
|
|
11
|
+
seq: 1,
|
|
12
|
+
request: {
|
|
13
|
+
url: 'https://restcountries.com/v2/alpha/in',
|
|
14
|
+
method: 'GET',
|
|
15
|
+
headers: [],
|
|
16
|
+
params: [],
|
|
17
|
+
body: { mode: 'none' },
|
|
18
|
+
auth: { mode: 'none' },
|
|
19
|
+
script: {},
|
|
20
|
+
vars: {},
|
|
21
|
+
assertions: [],
|
|
22
|
+
tests: ''
|
|
23
|
+
},
|
|
24
|
+
settings: { maxRedirects }
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Serializes with Bruno's own writer and reads back, covering the write side too.
|
|
28
|
+
const roundTripRequest = (maxRedirects: number, format: CollectionFormat) =>
|
|
29
|
+
parseRequest(stringifyRequest(requestWithMaxRedirects(maxRedirects) as any, { format }), { format })
|
|
30
|
+
.settings.maxRedirects;
|
|
31
|
+
|
|
32
|
+
const HAND_EDITED_DOCUMENTS: Record<CollectionFormat, (rawValue: string) => string> = {
|
|
33
|
+
bru: (rawValue) => `meta {
|
|
34
|
+
name: Get Users
|
|
35
|
+
type: http
|
|
36
|
+
seq: 1
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get {
|
|
40
|
+
url: https://restcountries.com/v2/alpha/in
|
|
41
|
+
body: none
|
|
42
|
+
auth: none
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
settings {
|
|
46
|
+
maxRedirects: ${rawValue}
|
|
47
|
+
}
|
|
48
|
+
`,
|
|
49
|
+
yml: (rawValue) => `info:
|
|
50
|
+
name: Get Users
|
|
51
|
+
type: http
|
|
52
|
+
seq: 1
|
|
53
|
+
|
|
54
|
+
http:
|
|
55
|
+
method: GET
|
|
56
|
+
url: https://restcountries.com/v2/alpha/in
|
|
57
|
+
|
|
58
|
+
settings:
|
|
59
|
+
maxRedirects: ${rawValue}
|
|
60
|
+
`
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Parses a document stated byte-for-byte, for values Bruno's writer would never produce
|
|
64
|
+
// (.inf, blank, quoted). Returns what the parser stored, so assertions can distinguish a
|
|
65
|
+
// dropped value from one the parser replaced with the default.
|
|
66
|
+
const parseHandEditedValue = (rawValue: string, format: CollectionFormat) =>
|
|
67
|
+
parseRequest(HAND_EDITED_DOCUMENTS[format](rawValue), { format }).settings.maxRedirects;
|
|
68
|
+
|
|
69
|
+
describe('maxRedirects on-disk round trip', () => {
|
|
70
|
+
describe.each(FORMATS)('%s format', (format) => {
|
|
71
|
+
// The formats agree on the enforced ceiling but not on what they store for an unusable value:
|
|
72
|
+
// bru omits the setting, yml writes the default in its place.
|
|
73
|
+
const storedWhenUnusable = format === 'bru' ? undefined : DEFAULT_MAX_REDIRECTS;
|
|
74
|
+
|
|
75
|
+
it.each([0, 5, 50, 51, 1000, Number.MAX_SAFE_INTEGER])(
|
|
76
|
+
'preserves a maxRedirects of %p',
|
|
77
|
+
(maxRedirects) => {
|
|
78
|
+
expect(roundTripRequest(maxRedirects, format)).toBe(maxRedirects);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// parseInt stops at the exponent, so a ceiling Bruno writes as 1e+31 reads back as 1.
|
|
83
|
+
it.each([1e21, 1e31, 9.999999999998865e21])(
|
|
84
|
+
'preserves an exponentially serialized maxRedirects of %p',
|
|
85
|
+
(maxRedirects) => {
|
|
86
|
+
expect(roundTripRequest(maxRedirects, format)).toBe(maxRedirects);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// Files written before any change to the writer's number formatting keep these exact bytes,
|
|
91
|
+
// so the literal exponent form must parse regardless of what the writer emits today.
|
|
92
|
+
it.each([
|
|
93
|
+
['1e+21', 1e21],
|
|
94
|
+
['9.999999999998865e+21', 9.999999999998865e21]
|
|
95
|
+
])('reads an on-disk exponent literal %s in full', (rawValue, expected) => {
|
|
96
|
+
expect(parseHandEditedValue(rawValue, format)).toBe(expected);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it.each(['1e309', '-1e309', '1' + '0'.repeat(400)])(
|
|
100
|
+
'does not store an on-disk %s that overflows to a non-finite number',
|
|
101
|
+
(rawValue) => {
|
|
102
|
+
expect(parseHandEditedValue(rawValue, format)).toBe(storedWhenUnusable);
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
it('clamps an on-disk value beyond MAX_SAFE_INTEGER to the nearest representable integer', () => {
|
|
107
|
+
expect(parseHandEditedValue('9007199254740993', format)).toBe(9007199254740992);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it.each(['', ' ', ' '])('does not store a blank on-disk value %p', (rawValue) => {
|
|
111
|
+
expect(parseHandEditedValue(rawValue, format)).toBe(storedWhenUnusable);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it.each(['-1', '-3', '-0.5'])('does not store a negative on-disk value of %s', (rawValue) => {
|
|
115
|
+
expect(parseHandEditedValue(rawValue, format)).toBe(storedWhenUnusable);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Copying a request from a bru collection into a yml one adds a maxRedirects the author never
|
|
120
|
+
// set, since yml materializes the default where bru left the setting out.
|
|
121
|
+
it('stores an unusable value differently per format', () => {
|
|
122
|
+
expect(parseHandEditedValue('abc', 'bru')).toBeUndefined();
|
|
123
|
+
expect(parseHandEditedValue('abc', 'yml')).toBe(DEFAULT_MAX_REDIRECTS);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('truncates a fractional maxRedirects identically in both formats', () => {
|
|
127
|
+
expect(roundTripRequest(3.5, 'bru')).toBe(3);
|
|
128
|
+
expect(roundTripRequest(3.5, 'yml')).toBe(3);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it.each(['Infinity', '-Infinity', 'NaN'])('does not store a hand-edited bru maxRedirects of %s', (rawValue) => {
|
|
132
|
+
expect(parseHandEditedValue(rawValue, 'bru')).toBeUndefined();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it.each(['.inf', '-.inf', '.nan'])('replaces a hand-edited yml maxRedirects of %s with the default', (rawValue) => {
|
|
136
|
+
expect(parseHandEditedValue(rawValue, 'yml')).toBe(DEFAULT_MAX_REDIRECTS);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('does not honour a quoted yml count, but reads a plain count in both formats', () => {
|
|
140
|
+
expect(parseHandEditedValue('"10"', 'yml')).toBe(DEFAULT_MAX_REDIRECTS);
|
|
141
|
+
expect(parseHandEditedValue('10', 'yml')).toBe(10);
|
|
142
|
+
expect(parseHandEditedValue('10', 'bru')).toBe(10);
|
|
143
|
+
});
|
|
144
|
+
});
|