From 576fa9b15ddd9ef36282e5e20daac2acc4f4a114 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 5 Mar 2021 20:25:05 -0800 Subject: [PATCH] feat(ses-ava): Wrap ava test function to log failures to actual console (#555) Co-authored-by: Dan Connolly Co-authored-by: Kris Kowal --- package.json | 1 + packages/ses-ava/.prettierrc.json | 4 + packages/ses-ava/LICENSE | 201 +++++++++++++++++++ packages/ses-ava/NEWS.md | 0 packages/ses-ava/README.md | 0 packages/ses-ava/exported.js | 1 + packages/ses-ava/jsconfig.json | 11 + packages/ses-ava/package.json | 60 ++++++ packages/ses-ava/rollup.config.js | 44 ++++ packages/ses-ava/src/main.js | 1 + packages/ses-ava/src/ses-ava-test.js | 124 ++++++++++++ packages/ses-ava/src/types.js | 67 +++++++ packages/ses-ava/test/test-raw-ava-reject.js | 54 +++++ packages/ses-ava/test/test-raw-ava-throw.js | 49 +++++ packages/ses-ava/test/test-ses-ava-reject.js | 57 ++++++ packages/ses-ava/test/test-ses-ava-throw.js | 51 +++++ 16 files changed, 725 insertions(+) create mode 100644 packages/ses-ava/.prettierrc.json create mode 100644 packages/ses-ava/LICENSE create mode 100644 packages/ses-ava/NEWS.md create mode 100644 packages/ses-ava/README.md create mode 100644 packages/ses-ava/exported.js create mode 100644 packages/ses-ava/jsconfig.json create mode 100644 packages/ses-ava/package.json create mode 100644 packages/ses-ava/rollup.config.js create mode 100644 packages/ses-ava/src/main.js create mode 100644 packages/ses-ava/src/ses-ava-test.js create mode 100644 packages/ses-ava/src/types.js create mode 100644 packages/ses-ava/test/test-raw-ava-reject.js create mode 100644 packages/ses-ava/test/test-raw-ava-throw.js create mode 100644 packages/ses-ava/test/test-ses-ava-reject.js create mode 100644 packages/ses-ava/test/test-ses-ava-throw.js diff --git a/package.json b/package.json index 614649a039..eb610b693f 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "packages/make-importer", "packages/make-simple-evaluate", "packages/ses", + "packages/ses-ava", "packages/ses-integration-test", "packages/test262-runner", "packages/transform-module" diff --git a/packages/ses-ava/.prettierrc.json b/packages/ses-ava/.prettierrc.json new file mode 100644 index 0000000000..6e778b4fb9 --- /dev/null +++ b/packages/ses-ava/.prettierrc.json @@ -0,0 +1,4 @@ +{ + "trailingComma": "all", + "singleQuote": true +} diff --git a/packages/ses-ava/LICENSE b/packages/ses-ava/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/packages/ses-ava/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/ses-ava/NEWS.md b/packages/ses-ava/NEWS.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/ses-ava/README.md b/packages/ses-ava/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/ses-ava/exported.js b/packages/ses-ava/exported.js new file mode 100644 index 0000000000..bc6da56dd1 --- /dev/null +++ b/packages/ses-ava/exported.js @@ -0,0 +1 @@ +import './src/types'; diff --git a/packages/ses-ava/jsconfig.json b/packages/ses-ava/jsconfig.json new file mode 100644 index 0000000000..5cdef0d4ed --- /dev/null +++ b/packages/ses-ava/jsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es2020", + "module": "esnext", + "noEmit": true, + "downlevelIteration": true, + "strictNullChecks": true, + "moduleResolution": "node" + }, + "include": ["src/**/*.js"] +} diff --git a/packages/ses-ava/package.json b/packages/ses-ava/package.json new file mode 100644 index 0000000000..06fe509d99 --- /dev/null +++ b/packages/ses-ava/package.json @@ -0,0 +1,60 @@ +{ + "name": "@agoric/ses-ava", + "version": "0.0.0+1-dev", + "description": "Virtualize Ava's test to work better under SES.", + "author": "Agoric", + "license": "Apache-2.0", + "type": "module", + "main": "./dist/ses-ava.cjs", + "module": "./src/main.js", + "browser": "./dist/ses-ava.umd.js", + "unpkg": "./dist/ses-ava.umd.js", + "exports": { + "import": "./src/main.js", + "require": "./dist/ses-ava.cjs", + "browser": "./dist/ses-ava.umd.js" + }, + "scripts": { + "build": "rollup --config rollup.config.js", + "clean": "rm -rf dist", + "lint": "yarn lint:types && yarn lint:js", + "lint:types": "tsc --build jsconfig.json", + "lint:js": "eslint '**/*.js'", + "lint-fix": "eslint --fix '**/*.js'", + "prepublish": "yarn clean && yarn build", + "test": "yarn ava" + }, + "dependencies": { + "ses": "^0.12.3" + }, + "devDependencies": { + "ava": "^3.12.1", + "@rollup/plugin-commonjs": "^13.0.0", + "@rollup/plugin-node-resolve": "^6.1.0", + "@rollup/plugin-json": "^4.1.0", + "@agoric/eslint-config": "^0.1.0", + "prettier": "^1.19.1", + "rollup-plugin-terser": "^5.1.3" + }, + "ava": { + "files": [ + "*test*/**/test-*.js" + ], + "require": [] + }, + "eslintConfig": { + "extends": [ + "@agoric" + ] + }, + "prettier": { + "trailingComma": "all", + "singleQuote": true + }, + "files": [ + "LICENSE*", + "dist", + "src", + "exported.js" + ] +} diff --git a/packages/ses-ava/rollup.config.js b/packages/ses-ava/rollup.config.js new file mode 100644 index 0000000000..56ccc16b75 --- /dev/null +++ b/packages/ses-ava/rollup.config.js @@ -0,0 +1,44 @@ +import resolve from '@rollup/plugin-node-resolve'; +import { terser } from 'rollup-plugin-terser'; +import commonjs from '@rollup/plugin-commonjs'; +import fs from 'fs'; + +const metaPath = new URL('package.json', import.meta.url).pathname; +const meta = JSON.parse(fs.readFileSync(metaPath, 'utf-8')); +const name = meta.name.split('/').pop(); +const umd = meta.umd || name; + +export default [ + { + input: 'src/main.js', + output: [ + { + file: `dist/${name}.mjs`, + format: 'esm', + }, + { + file: `dist/${name}.cjs`, + format: 'cjs', + }, + ], + plugins: [resolve(), commonjs()], + }, + { + input: 'src/main.js', + output: { + file: `dist/${name}.umd.js`, + format: 'umd', + name: umd, + }, + plugins: [resolve(), commonjs()], + }, + { + input: 'src/main.js', + output: { + file: `dist/${name}.umd.min.js`, + format: 'umd', + name: umd, + }, + plugins: [resolve(), commonjs(), terser()], + }, +]; diff --git a/packages/ses-ava/src/main.js b/packages/ses-ava/src/main.js new file mode 100644 index 0000000000..86836f4938 --- /dev/null +++ b/packages/ses-ava/src/main.js @@ -0,0 +1 @@ +export { wrapTest } from './ses-ava-test'; diff --git a/packages/ses-ava/src/ses-ava-test.js b/packages/ses-ava/src/ses-ava-test.js new file mode 100644 index 0000000000..ee552a5593 --- /dev/null +++ b/packages/ses-ava/src/ses-ava-test.js @@ -0,0 +1,124 @@ +// @ts-check +import 'ses'; +import './types.js'; + +const { apply } = Reflect; + +/** + * Just forwards to global `console.error`. + * + * @type {Logger} + */ +const defaultLogger = (...args) => { + console.error(...args); +}; + +/** + * Determine if the argument is a Promise. + * (Approximately copied from promiseKit.js) + * + * @param {unknown} maybePromise The value to examine + * @returns {maybePromise is Promise} Whether it is a promise + */ +const isPromise = maybePromise => + Promise.resolve(maybePromise) === maybePromise; + +/** + * @type {LogCallError} + */ +const logErrorFirst = (func, args, name, logger = defaultLogger) => { + let result; + try { + result = apply(func, undefined, args); + } catch (err) { + logger(`THROWN from ${name}:`, err); + throw err; + } + if (isPromise(result)) { + return result.then( + v => v, + reason => { + logger(`REJECTED from ${name}:`, reason); + return result; + }, + ); + } else { + return result; + } +}; + +const testerMethodsWhitelist = [ + 'after', + 'afterEach', + 'before', + 'beforeEach', + 'cb', + 'failing', + 'serial', + 'only', + 'skip', +]; + +/** + * @param {TesterFunc} testerFunc + * @param {Logger} [logger] + * @returns {TesterFunc} Not yet frozen! + */ +const wrapTester = (testerFunc, logger = defaultLogger) => { + /** @type {TesterFunc} */ + const testerWrapper = (title, implFunc) => { + /** @type {ImplFunc} */ + const testFuncWrapper = t => { + harden(t); + return logErrorFirst(implFunc, [t], 'ava test', logger); + }; + return testerFunc(title, testFuncWrapper); + }; + return testerWrapper; +}; + +/** + * The ava `test` function takes a callback argument of the form + * `t => {...}`. If the outcome of this function indicates an error, either + * by throwing or by eventually rejecting a returned promise, ava does its + * own peculiar console-like display of this error and its stacktrace. + * However, it does not use the ses `console` and so bypasses all the fancy + * diagnostics provided by the ses `console`. + * + * To use this package, a test file replaces the line + * ```js + * import test from 'ava'; + * ``` + * with + * ```js + * import { wrapTest } from '@agoric/ses-ava'; + * import rawTest from 'ava'; + * + * const test = wrapTest(rawTest); + * ``` + * Then the calls to `test` in the rest of the test file will act like they + * used to, except that, if a test fails because the test function (the + * callback argument to `test`) throws or returns a promise + * that eventually rejects, the error is first sent to the `console` before + * propagating into `rawTest`. + * + * @param {TesterInterface} avaTest + * @param {Logger} [logger] + * @returns {TesterInterface} + */ +const wrapTest = (avaTest, logger = defaultLogger) => { + /** @type {TesterInterface} */ + const testerWrapper = wrapTester(avaTest, logger); + for (const methodName of testerMethodsWhitelist) { + if (methodName in avaTest) { + /** @type {TesterFunc} */ + const testerMethod = (title, implFunc) => + avaTest[methodName](title, implFunc); + testerWrapper[methodName] = wrapTester(testerMethod); + } + } + harden(testerWrapper); + return testerWrapper; +}; +// harden(wrapTest); +export { wrapTest }; diff --git a/packages/ses-ava/src/types.js b/packages/ses-ava/src/types.js new file mode 100644 index 0000000000..f85f107bcf --- /dev/null +++ b/packages/ses-ava/src/types.js @@ -0,0 +1,67 @@ +// @ts-check + +/** + * @typedef {(...args: unknown[]) => void} Logger + */ + +/** + * @callback LogCallError + * + * Calls `thunk()` passing back approximately its outcome, but first + * logging any erroneous outcome to the `logger`, which defaults to + * `console.log`. + * + * If thunk returns a non-promise, silently return it. + * If thunk throws, log what was thrown and then rethrow it. + * If thunk returns a promise, immediately return a new unresolved promise. + * If the first promise fulfills, silently fulfill the returned promise even if + * the fulfillment was an error. + * If the first promise rejects, log the rejection reason and then reject the + * returned promise with the same reason. + * The delayed rejection of the returned promise is an observable difference + * from directly calling `thunk()` but will be equivalent enough for most + * purposes. + * + * TODO This function is useful independent of ava, so consider moving it + * somewhere and exporting it for general reuse. + * + * @param {(...unknown) => unknown} func + * @param {unknown[]} args + * @param {string} name + * @param {Logger=} logger + */ + +/** + * Simplified form of ava's types. + * TODO perhaps just import ava's type declarations instead + * TODO reconcile also with types and API defined in avaAssertXS.js + * + * @typedef {Object} Assertions + * @property {(actual: unknown, message?: string) => void} assert + * // TODO is, deepEqual, truthy, falsy, etc... + */ + +/** + * @callback ImplFunc + * This is the function that invariably starts `t => {`. + * Ava's types call this `Implementation`, but that's just too confusing. + * + * @param {Assertions} t + * @returns {unknown} + * + * @callback TesterFunc + * @param {string} title + * @param {ImplFunc} implFunc + * @returns {void} + * + * @typedef {TesterFunc} TesterInterface + * @property {TesterFunc} after + * @property {TesterFunc} afterEach + * @property {TesterFunc} before + * @property {TesterFunc} beforeEach + * @property {TesterFunc} cb + * @property {TesterFunc} failing + * @property {TesterFunc} serial + * @property {TesterFunc} only + * @property {TesterFunc} skip + */ diff --git a/packages/ses-ava/test/test-raw-ava-reject.js b/packages/ses-ava/test/test-raw-ava-reject.js new file mode 100644 index 0000000000..990f0df613 --- /dev/null +++ b/packages/ses-ava/test/test-raw-ava-reject.js @@ -0,0 +1,54 @@ +import 'ses'; +import test from 'ava'; + +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` +}); + +test('raw ava reject console output', t => { + t.assert(true); + // Uncomment this to see something like the text in the extended comment below + + /* + return Promise.resolve(null) + .then(v => v) + .then(v => v) + .then(_ => { + assert.typeof(88, 'string', assert.details`msg ${'NOTICE ME'}`); + }); + */ +}); + +/* +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 no access to the non-disclosed +`'NOTICE ME'`, only the redacted `'(a string)'. +``` + raw ava reject console output + + Rejected promise returned by test. Reason: + + TypeError { + message: 'msg (a string)', + } + + › 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 +``` +*/ diff --git a/packages/ses-ava/test/test-raw-ava-throw.js b/packages/ses-ava/test/test-raw-ava-throw.js new file mode 100644 index 0000000000..b3ddc71432 --- /dev/null +++ b/packages/ses-ava/test/test-raw-ava-throw.js @@ -0,0 +1,49 @@ +import 'ses'; +import test from 'ava'; + +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` +}); + +test('raw ava throw console output', t => { + t.assert(true); + // Uncomment this to see something like the text in the extended comment below + + /* + assert.typeof(88, 'string', assert.details`msg ${'NOTICE ME'}`); + */ +}); + +/* +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 no access to the non-disclosed +`'NOTICE ME'`, only the redacted `'(a string)'. +``` + raw ava throw console output + + Error thrown in test: + + TypeError { + message: 'msg (a string)', + } + + › makeError (file:///Users/alice/agoric/SES-shim/packages/ses/src/error/assert.js:141:17) + › fail (file:///Users/alice/agoric/SES-shim/packages/ses/src/error/assert.js:260:20) + › baseAssert (file:///Users/alice/agoric/SES-shim/packages/ses/src/error/assert.js:278:13) + › equal (file:///Users/alice/agoric/SES-shim/packages/ses/src/error/assert.js:289:5) + › Function.assertTypeof [as typeof] (file:///Users/alice/agoric/SES-shim/packages/ses/src/error/assert.js:308:5) + › file://test/test-raw-ava-throw.js:17:16 + + ─ + + 1 test failed +``` +*/ diff --git a/packages/ses-ava/test/test-ses-ava-reject.js b/packages/ses-ava/test/test-ses-ava-reject.js new file mode 100644 index 0000000000..005f96d980 --- /dev/null +++ b/packages/ses-ava/test/test-ses-ava-reject.js @@ -0,0 +1,57 @@ +import 'ses'; +import rawTest from 'ava'; +import { wrapTest } from '../src/ses-ava-test.js'; + +lockdown({ + // Comment or uncomment each of these switches to see variations of the + // output shown below. When all the switches are commented, you should + // see that output. + // + // stackFiltering: 'verbose', // Include `assert` infrastructure + // consoleTaming: 'unsafe', // console without access to redacted info + // errorTaming: 'unsafe', // Disclose `error.stack` to ava +}); + +const test = wrapTest(rawTest); + +test('ses-ava reject console output', t => { + t.assert(true); + // Uncomment this to see something like the text in the extended comment below + + /* + return Promise.resolve(null) + .then(v => v) + .then(v => v) + .then(_ => { + assert.typeof(88, 'string', assert.details`msg ${'NOTICE ME'}`); + }); + */ +}); + +/* +Uncommenting the test code above should produce something like the following. +Some of this output still comes from ava. The stack-like display comes from +the SES `console`, which shows the detailed error message including the +redacted `'NOTICE ME'` that ava has no access to. + +We will revisit this example in `@agoric/eventual-send` using `E.when` instead +of `then` to show deep stacks across multiple turns. +``` +REJECTED from ava test: (TypeError#1) +TypeError#1: msg NOTICE ME + + at packages/ses-ava/test/test-ses-ava-reject.js:26:20 + + ses-ava reject console output + + Rejected promise returned by test. Reason: + + TypeError { + message: 'msg (a string)', + } + + ─ + + 1 test failed +``` +*/ diff --git a/packages/ses-ava/test/test-ses-ava-throw.js b/packages/ses-ava/test/test-ses-ava-throw.js new file mode 100644 index 0000000000..c7483f4bc5 --- /dev/null +++ b/packages/ses-ava/test/test-ses-ava-throw.js @@ -0,0 +1,51 @@ +import 'ses'; +import rawTest from 'ava'; +import { wrapTest } from '../src/ses-ava-test.js'; + +lockdown({ + // Comment or uncomment each of these switches to see variations of the + // output shown below. When all the switches are commented, you should + // see that output. + // + // stackFiltering: 'verbose', // Include `assert` infrastructure + // consoleTaming: 'unsafe', // console without access to redacted info + // errorTaming: 'unsafe', // Disclose `error.stack` to ava +}); + +const test = wrapTest(rawTest); + +test('ses-ava throw console output', t => { + t.assert(true); + // Uncomment this to see something like the text in the extended comment below + + /* + assert.typeof(88, 'string', assert.details`msg ${'NOTICE ME'}`); + */ +}); + +/* +Uncommenting the test code above should produce something like the following. +Some of this output still comes from ava. The stack-like display comes from +the SES `console`, which shows the detailed error message including the +redacted `'NOTICE ME'` that ava has no access to. +``` +THROWN from ava test: (TypeError#1) +TypeError#1: msg NOTICE ME + + at packages/ses-ava/test/test-ses-ava-throw.js:21:16 + at logErrorFirst (packages/ses-ava/src/ses-ava-test.js:32:14) + at testFuncWrapper (packages/ses-ava/src/ses-ava-test.js:73:14) + + ses-ava throw console output + + Error thrown in test: + + TypeError { + message: 'msg (a string)', + } + + ─ + + 1 test failed +``` +*/