| 85 | // |
| 86 | |
| 87 | function run(name: string): void { |
| 88 | const md = new MDGator(); |
| 89 | |
| 90 | const raw = fs.readFileSync(path.join(__dirname, name + '.md')).toString(); |
| 91 | const groups = md.parse(raw); |
| 92 | |
| 93 | function runSingleTest( |
| 94 | location: string, ty: TestType, meta: Metadata, |
| 95 | input: string, expected: readonly (string | RegExp)[] |
| 96 | ): void { |
| 97 | test(`should pass for type="${ty}" (location=${location})`, { timeout: 60000 }, async () => { |
| 98 | const binary = await buildMode(ty, meta); |
| 99 | await binary.check(input, expected, { |
| 100 | noScan: meta.noScan === true, |
| 101 | }); |
| 102 | }); |
| 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'); |