( fixture: TestFixture, compilerVersion: number, shouldLog: boolean, includeEvaluator: boolean, )
| 164 | } |
| 165 | |
| 166 | export async function transformFixture( |
| 167 | fixture: TestFixture, |
| 168 | compilerVersion: number, |
| 169 | shouldLog: boolean, |
| 170 | includeEvaluator: boolean, |
| 171 | ): Promise<TestResult> { |
| 172 | const {input, snapshot: expected, snapshotPath: outputPath} = fixture; |
| 173 | const basename = getBasename(fixture); |
| 174 | const expectError = isExpectError(fixture); |
| 175 | |
| 176 | // Input will be null if the input file did not exist, in which case the output file |
| 177 | // is stale |
| 178 | if (input === null) { |
| 179 | return { |
| 180 | outputPath, |
| 181 | actual: null, |
| 182 | expected, |
| 183 | unexpectedError: null, |
| 184 | }; |
| 185 | } |
| 186 | const {compileResult, error} = await compile( |
| 187 | input, |
| 188 | fixture.fixturePath, |
| 189 | compilerVersion, |
| 190 | shouldLog, |
| 191 | includeEvaluator, |
| 192 | ); |
| 193 | |
| 194 | let unexpectedError: string | null = null; |
| 195 | if (expectError) { |
| 196 | if (error === null) { |
| 197 | unexpectedError = `Expected an error to be thrown for fixture: \`${basename}\`, remove the 'error.' prefix if an error is not expected.`; |
| 198 | } |
| 199 | } else { |
| 200 | if (error !== null) { |
| 201 | unexpectedError = `Expected fixture \`${basename}\` to succeed but it failed with error:\n\n${error}`; |
| 202 | } else if (compileResult == null) { |
| 203 | unexpectedError = `Expected output for fixture \`${basename}\`.`; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | const snapOutput: string | null = compileResult?.forgetOutput ?? null; |
| 208 | let sproutOutput: string | null = null; |
| 209 | if (compileResult?.evaluatorCode != null) { |
| 210 | const sproutResult = runSprout( |
| 211 | compileResult.evaluatorCode.original, |
| 212 | compileResult.evaluatorCode.forget, |
| 213 | ); |
| 214 | if (sproutResult.kind === 'invalid') { |
| 215 | unexpectedError ??= ''; |
| 216 | unexpectedError += `\n\n${sproutResult.value}`; |
| 217 | } else { |
| 218 | sproutOutput = sproutResult.value; |
| 219 | } |
| 220 | } else if (!includeEvaluator && expected != null) { |
| 221 | sproutOutput = expected.split('\n### Eval output\n')[1]; |
| 222 | } |
| 223 |
nothing calls this directly
no test coverage detected