feat: allow for dynamic hints (#44279)

pull/44286/head
Oliver Eyton-Williams 2021-11-25 16:10:01 +01:00 committed by GitHub
parent 63f6d9d3f2
commit 260f945de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View File

@ -98,9 +98,15 @@ async function initTestFrame(e = { code: {} }) {
console.error(err);
}
// to provide useful debugging information when debugging the tests, we
// have to extract the message and stack before returning
// have to extract the message, stack and, if they exist, expected and
// actual before returning
return {
err: { message: err.message, stack: err.stack }
err: {
message: err.message,
stack: err.stack,
expected: err.expected,
actual: err.actual
}
};
}
};

View File

@ -167,7 +167,11 @@ function* executeTests(testRunner, tests, testTimeout = 5000) {
throw err;
}
} catch (err) {
newTest.message = text;
const { actual, expected } = err;
newTest.message = text
.replace('--fcc-expected--', expected)
.replace('--fcc-actual--', actual);
if (err === 'timeout') {
newTest.err = 'Test timed out';
newTest.message = `${newTest.message} (${newTest.err})`;

View File

@ -64,10 +64,13 @@ Tests to run against user code, in pairs of markdown text and code block test co
Code for test one
```
More instructions in markdown syntax
If you want dynamic output based on the user's code, --fcc-expected-- and --fcc-actual-- will be replaced with the expected and actual values of the test's assertion:
```js
More code
assert.equal(
'this will replace --fcc-actual--',
'this will replace --fcc-expected--'
);
```
# --seed--