MCPcopy Index your code
hub / github.com/nodejs/llhttp / runTest

Function runTest

test/md-test.ts:105–211  ·  view source on GitHub ↗
(test: Test)

Source from the content-addressed store, hash-verified

103 }
104
105 function runTest(test: Test) {
106 describe(test.name + ` at ${name}.md:${test.line + 1}`, () => {
107 const location = `${name}.md:${test.line + 1}`
108
109 let types: TestType[] = [];
110
111 const isURL = test.values.has('url');
112 const inputKey = isURL ? 'url' : 'http';
113
114 assert(test.values.has(inputKey),
115 `Missing "${inputKey}" code in md file`);
116 assert.strictEqual(test.values.get(inputKey)!.length, 1,
117 `Expected just one "${inputKey}" input`);
118
119 let meta: Metadata;
120 if (test.meta.has(inputKey)) {
121 meta = test.meta.get(inputKey)![0]!;
122 } else {
123 assert(isURL, 'Missing required http metadata');
124 meta = {};
125 }
126
127 if (isURL) {
128 types = [ 'url' ];
129 } else {
130 assert(Object.prototype.hasOwnProperty.call(meta, 'type'), 'Missing required `type` metadata');
131
132 if (meta.type) {
133 if (!allowedTypes.includes(meta.type)) {
134 throw new Error(`Invalid value of \`type\` metadata: "${meta.type}"`);
135 }
136
137 types.push(meta.type);
138 }
139 }
140
141 assert(test.values.has('log'), 'Missing `log` code in md file');
142
143 assert.strictEqual(test.values.get('log')!.length, 1,
144 'Expected just one output');
145
146 let input: string = test.values.get(inputKey)![0];
147 let expected: string = test.values.get('log')![0];
148
149 // Remove trailing newline
150 input = input.replace(/\n$/, '');
151
152 // Remove escaped newlines
153 input = input.replace(/\\(\r\n|\r|\n)/g, '');
154
155 // Normalize all newlines
156 input = input.replace(/\r\n|\r|\n/g, '\r\n');
157
158 // Replace escaped CRLF, tabs, form-feed
159 input = input.replace(/\\r/g, '\r');
160 input = input.replace(/\\n/g, '\n');
161 input = input.replace(/\\t/g, '\t');
162 input = input.replace(/\\f/g, '\f');

Callers 1

runGroupFunction · 0.85

Calls 1

runSingleTestFunction · 0.85

Tested by

no test coverage detected