-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ses-ava): use causal console if possible
- Loading branch information
Showing
13 changed files
with
434 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// This file does not start with "test-" because it is useful as an | ||
// automated test. Rather, its purpose is just to run it to see what a | ||
// deep stack looks like. | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { test } from './prepare-test-env-ava.js'; | ||
|
||
import { E } from './get-hp.js'; | ||
|
||
const { freeze } = Object; | ||
|
||
const carol = freeze({ | ||
bar: () => assert.fail('Wut?'), | ||
}); | ||
|
||
const bob = freeze({ | ||
foo: carolP => E(carolP).bar(), | ||
}); | ||
|
||
const alice = freeze({ | ||
test: () => E(bob).foo(carol), | ||
}); | ||
|
||
test('deep-stacks E ses-ava', t => { | ||
const q = alice.test(); | ||
return q.catch(reason => { | ||
t.assert(reason instanceof Error); | ||
t.log('expected failure', reason); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This file does not start with "test-" because it is useful as an | ||
// automated test. Rather, its purpose is just to run it to see what a | ||
// deep stack looks like. | ||
|
||
import { test } from './prepare-test-env-ava.js'; | ||
|
||
import { E } from './get-hp.js'; | ||
|
||
test('deep-stacks when ses-ava', t => { | ||
let r; | ||
const p = new Promise(res => (r = res)); | ||
const q = E.when(p, v1 => E.when(v1 + 1, v2 => assert.equal(v2, 22))); | ||
r(33); | ||
return q.catch(reason => { | ||
t.assert(reason instanceof Error); | ||
t.log('expected failure', reason); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Avoid importing from @endo/errors to avoid more dependence cycles | ||
const { error: makeError, details: X, quote: q } = assert; | ||
|
||
const { freeze } = Object; | ||
|
||
export const exampleProblem = label => { | ||
const subError = makeError(X`nested ${q(label)} ${'REDACTED'}`); | ||
|
||
return makeError(X`${q(label)} ${'NOTICE ME'} nest ${subError}`); | ||
}; | ||
freeze(exampleProblem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,38 @@ | ||
import 'ses'; | ||
import test from 'ava'; | ||
import { exampleProblem } from './example-problem.js'; | ||
|
||
lockdown({ | ||
// Comment or uncomment each of these switches to see variations of the | ||
// output shown below. When all the switches are uncommented, you should | ||
// see that output. | ||
// | ||
stackFiltering: 'verbose', // Exclude `assert` infrastructure | ||
consoleTaming: 'unsafe', // Doesn't make a difference here | ||
errorTaming: 'unsafe', // Redacts entire `error.stack` | ||
// Commenting out all settings for a given switch defaults to using | ||
// the current relevant environment variable setting. To get results | ||
// independent of that, always uncomment one setting for each switch. | ||
// | ||
stackFiltering: 'concise', // Default. Hide infrastructure, shorten paths | ||
// stackFiltering: 'verbose', // Include `assert` infrastructure | ||
consoleTaming: 'safe', // Default. Console with access to redacted info | ||
// consoleTaming: 'unsafe', // Console without access to redacted info | ||
errorTaming: 'safe', // Default. Hide redacted info on error | ||
// errorTaming: 'unsafe', // Disclose redacted info on error | ||
}); | ||
|
||
test('raw ava reject console output', t => { | ||
t.assert(true); | ||
// Uncomment this to see something like the text in the extended comment below | ||
|
||
/* | ||
t.log('t.log1:', exampleProblem('t.log1')); | ||
console.log('console.log2:', exampleProblem('console.log2')); | ||
|
||
return Promise.resolve(null) | ||
.then(v => v) | ||
.then(v => v) | ||
.then(_ => { | ||
assert.typeof(88, 'string', assert.details`msg ${'NOTICE ME'}`); | ||
t.log('t.log3:', exampleProblem('t.log3')); | ||
console.log('console.log4:', exampleProblem('console.log4')); | ||
|
||
// Uncomment to see something how this test case fails | ||
// throw exampleProblem('throw5'); | ||
}); | ||
*/ | ||
}); | ||
|
||
/* | ||
Uncommenting the test code above should produce something like the following. | ||
This output is all from ava. The stack-like display comes from ava's direct | ||
use of the `error.stack` property. Ava bypasses the normal `console`. | ||
For the error message, ava has access only to the `message` string carried | ||
by the error instance, which would normally be redacted to | ||
`'msg (a string)'`. But `errorTaming: 'unsafe'` suppresses that redaction along | ||
with suppressing the redaction of the stack, so the console blabs | ||
`'msg "NOTICE ME"'` instead. | ||
``` | ||
raw ava reject console output | ||
Rejected promise returned by test. Reason: | ||
TypeError { | ||
message: 'msg "NOTICE ME"', | ||
} | ||
› makeError (file:///Users/markmiller/src/ongithub/agoric/SES-shim/packages/ses/src/error/assert.js:141:17) | ||
› fail (file:///Users/markmiller/src/ongithub/agoric/SES-shim/packages/ses/src/error/assert.js:260:20) | ||
› baseAssert (file:///Users/markmiller/src/ongithub/agoric/SES-shim/packages/ses/src/error/assert.js:278:13) | ||
› equal (file:///Users/markmiller/src/ongithub/agoric/SES-shim/packages/ses/src/error/assert.js:289:5) | ||
› Function.assertTypeof [as typeof] (file:///Users/markmiller/src/ongithub/agoric/SES-shim/packages/ses/src/error/assert.js:308:5) | ||
› file://test/test-raw-ava-reject.js:22:20 | ||
─ | ||
1 test failed | ||
``` | ||
*/ |
Oops, something went wrong.