-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External macros are not transformed with power-assert #25
Comments
Yes this is definitely an oversight with how we built macros. @avajs/core / @twada I assume we treat any Perhaps we could add an |
Yes
Correct, mostly because we don't yet transpile imported files. Maybe we could come up with a naming convention for macros so we would know to transpile and power-assert'ify them, kinda like helper files → avajs/ava#720.
Can you provide an example of how it would be used? For now, we should at least find a way to be able to power-assert macros defined in the same file. That's the most common use-case. @twada Any ideas? |
I think macros in the same file (assume you mean test file) are already |
We could assume helper files contain macros? Intercept the
// my-macro.js
import macro from 'ava/macro'
export myMacro = macro((t, one, two) => {
t.true(one === two)
}) // ava/macro.js
export default function (macro) {
const source = macro.toString()
return applyPowerAssertAndEvaluate(source)
} In other words we can get the function source and transpile it on the fly, then evaluate using the |
👍
That could work, but I would very much prefer something that just works, like now, than having to have a separate macro function. |
Yea, I'm just trying to think about how to distribute macros via npm. I suppose you could distribute version compiled with |
Thank you for working on this. I'm following this thread as I have several macros in my project that I want to reuse in different test files. |
@novemberborn I agree that for distributable macros, |
Have there been any recent developments to this issue with the release of AVA 3? Does anyone have a preferred workaround for adding power-assert support with imported macros? (Right now for Some additional detail: I'm not importing macros from an external project, I'm simply exporting a macro from a single local "test helper" file, and importing it for use in 5-10 other test files within the same project. The If it's possible to instrument for that scenario – rather than needing to instrument all imported files as mentioned above – or provide some manual way of enabling support for a single file, that would solve my use-case. |
@bitjson not specifically, except that power-assert now requires the external
Hmm, I can't immediately think of why that would be. We still compile everything when you debug. Could you share a reproduction? This may we worthy of a new issue though. |
Ah, sorry, I thought I was seeing the results of I was actually noticing a difference between when I run all tests (from an independent terminal) and when I debug a single test file in VSCode. In the second case, I don't see any error output from failing macros unless I pass in an assertion message parameter. (I haven't figured out why yet.) |
Description
External AVA macros are not transformed with power-assert.
Expected
Macros in the same file as the tests (internal macros) should have the same behaviour as those imported from an external file.
Both tests should output the same style of error:
Actual
External macros are not transformed with power-assert and so display standard errors.
Test Source
Full example: https://github.com/MethodGrab/ava-power-assert-external-macro-test-case
test.js:
macros.js:
Error Message & Stack Trace
Config
{ "ava": {} }
Command-Line Arguments
Relevant Links
Environment
The text was updated successfully, but these errors were encountered: