-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow tests files to have any extension (i.e. .jsx
, .ts
)
#631
Comments
Personally I'd argue that there's no point in using |
Extensions provide hints to the IDE as to which language features should be enabled. My question is, do we just make a special exception for
Would enable |
I think ideally ava would accept any extension, as long as there is a register hook to get the file to vanilla javascript. I believe this would also fix issue #521. |
I like that thinking. The only difficulty is that we can't know the list of registered extensions in the parent process, we process require hooks in the child. |
I think we can support Accepting any extension is trickier. We might have to swap out the compiler. #577 discusses this with regards to source files but the same would apply here. I suspect we might solve that with an explicit extension registry, not just accepting whatever is matched by the glob patterns. |
Why is matching the glob string problematic? If they explicitly define an extension just trust the user will add the require hook themselves (perhaps a helpful message if they don't). |
👍 |
Yes, but this is the part we're currently missing. You can't swap out the Babel precompiler. Adding |
So, we agreed to accept |
You can by combining {
"ava": {
"require": "coffee-script/register",
"babel": false,
"files": "test/**/*.coffee"
}
} JSX should be like this: {
"ava": {
"babel": "inherit" // with .jsx support setup correction in .babelrc,
"files": "test/**/*.{js,jsx}"
}
}
I would just as soon not hard code non-standard extensions into AVA if we can avoid it (which I think we can fairly easily in this case). |
We are currently hard coding for |
That's because we want |
@sindresorhus so remove code that restricts test files to |
I think what @sindresorhus is getting at is the following. If the glob pattern matches a directory explicitly: $ ava tests/some-dir What the user almost certainly meant was: $ ava test/some-dir/*.js So we help them out and do that automagically. If the users glob pattern is specific about extensions: $ ava test/some-dir/*.jsx Then we take them at their word. In the above example, $ ava test/some-dir/*.{js,jsx} So basically, we should be using strict glob pattern matching except in the case where they explicitly match a directory. |
Yes, that's what I meant, and much clearer :) Nitpick, but it's recursive: |
Without getting into #229 territory we can quite easily support |
I know that some people use |
@kentcdodds happy to accept a PR that adds React's test naming convention, if that removes a step. I don't think we should apply the |
There are many of these. Not really React specific. Definitely preference based. I definitely don't believe that we should arbitrarily add plugins and presets to AVA's built-in config. I just mean that if there is an existing Maybe having an |
Well you got
Yea. Still,
👍 |
Ah, I think I misunderstood you. You mean so I don't have to do:
But instead I can:
That'd be awesome! I'll look into making a PR for that :-)
Also misunderstood you on this one as well. You're totally right. If they're using |
@sindresorhus @jamestalmage @vdemedes what's your stance on supporting |
Also, while we could support alternative extensions they'll still be treated as JavaScript. IMO that has less value than supporting |
@novemberborn What about those using JSX and React with a |
Awesome! If you do |
Good point. We should make sure to retain compatibility with the current use of the |
An easy preliminary solution would be to introduce a property |
Also turn off .jsx for use with AVA avajs/ava#631
I'd like to see this so that // test.mjs
import test from "ava"
import foo from "../esm.mjs"
test(t => {
t.is(foo(), 2)
})
// esm.mjs
export default function foo() {
return 2
}
// package.json
{
"ava": {
"require": ["@std/esm"]
}
} Given that |
@Jamesernator there's an ongoing discussion around |
This will become even more important once babel 7 is released, which has the ability to parse and remove the type annotations from Typescript files. |
Hello, I want to use ava for server-side(Coffee-Script) testing, I want to write tests also in Coffee. Based on my searching around, I see that there are ways to achieve this. Some posts suggest to use
Is this still relevant? I tried to do something like this and was unsuccesful. Can someone please tell me if what I am trying to do is possible and point me in the right direction if it is possible. Thanks. |
@vanga AVA performs some transpilations on the test files. These assume the test files contain JavaScript. Until those transpilations can be disabled we cannot support arbitrary file extensions, or indeed support non-JavaScript test files. |
Thanks @novemberborn |
Makes sense. But why can't
cc @jdalton |
@feross I think we could recognize |
@novemberborn That's great to hear! I was just investigating porting tests from |
Our globbing is quite broken but after I land #1608 I intend to implement |
@novemberborn Do we have an update on this issue? |
@Jaden-Giordano I've been focused on landing other improvements and breaking changes in preparation for a 1.0 release. That said we have enough pieces in place for |
@novemberborn So really the only issue is that ava is filtering based on the extensions hard coded: Edit:
I'm going to make the pull request so we can fine tune it there. |
@Jaden-Giordano it's not that easy I'm afraid. We need to hook this up to our Babel pipeline, and separately our compiled enhancements. (Though currently those are implemented using the Babel pipeline, say when we bring in TypeScript we may have a TypeScript-specific implementation.) So We need this refinement so you can specify |
So basically Edit: |
Yes, albeit with the nuance that the
The test files may not even need precompiling, or alternatively you might use use something like |
To help those looking for what you need to change now this issue is closed: With AVA version
Thanks @novemberborn and @Jaden-Giordano for getting this working! |
If anybody's game for updating the TypeScript recipe that'd be great. See #1822 ❤️ |
With the latest release(0.13) and the ability to support jsx; I would like the ability to write my test that contains jsx with a jsx extension. However ava is filtering only for files with .js extensions. I'm a little confused as to why ava allows for a glob pattern in the cli but then only filters down to .js files.
I can make a PR if this is something worthwhile to the maintainers.
See conclusion here: #631 (comment)
The text was updated successfully, but these errors were encountered: