Precompile helpers #1078

Merged
merged 2 commits into from Jan 7, 2017

Projects

None yet

4 participants

@vadimdemedes
Member
vadimdemedes commented Oct 15, 2016 edited

Fixes #720 and potentially #1049.

Lack of this feature has been bugging me for a long time, glad I've finally found a time to fix it. It's still WIP, need to:

  • Submit a PR to ava-files to support findHelpers() (currently named as findTestDependencies()).
  • Fix tests.
  • Write new tests.

As for #1049 (external macros are not precompiled), we could add a special glob for that, like **/macros/** to precompile those files as well.

@novemberborn
Member

Good start! This compiles the helpers as if they were test files, right? That seems correct to me.

Let's see where that gets us before doing anything else for macros.

@vadimdemedes
Member

This compiles the helpers as if they were test files, right? That seems correct to me.

Yep, exactly.

Let's see where that gets us before doing anything else for macros.

Yes for sure, that is unrelated to this PR.

api.js
+
+ return new AvaFiles({cwd: this.options.resolveTestsFrom})
+ .findTestDependencies()
+ .map(function (file) { // eslint-disable-line array-callback-return
@sindresorhus
sindresorhus Oct 22, 2016 Member

Why use .map if you're not actually going to map anything?

@vadimdemedes
vadimdemedes Oct 22, 2016 Member

I was using it as a way to async iterate the items. Is there another bluebird method that does that?

@vadimdemedes vadimdemedes referenced this pull request in avajs/ava-files Oct 23, 2016
Merged

Add findTestHelpers() to find helpers and fixtures #8

@novemberborn

Do we foresee people wanting to disable this behavior?

test/api.js
@@ -705,9 +705,16 @@ function generateTests(prefix, apiCreator) {
test(prefix + 'caching is enabled by default', function (t) {
t.plan(3);
rimraf.sync(path.join(__dirname, 'fixture/caching/node_modules'));
+
+ var prevCwd = process.cwd();
+ process.chdir(path.join(__dirname, 'fixture/caching'));
@novemberborn
novemberborn Oct 23, 2016 Member

Why this change?

@vadimdemedes
vadimdemedes Oct 24, 2016 Member

Tests are being run from the root, so AVA finds and precompiles helpers and fixtures from the test folder (e.g. test/fixture/ignored-dirs/helpers/test.js).

That's why I change the cwd to make it look like the tests are being executed from that dir. I think it's actually what each test should do.

@novemberborn
novemberborn Oct 30, 2016 Member

The pkgDir and resolveTestsFrom directories can be passed to Api though. That's how its meant to be used, implicit defaults aside. We shouldn't need to change the working directory of the tap process.

@vadimdemedes
vadimdemedes Nov 6, 2016 Member

Thanks for the tip!

@novemberborn
Member

Do we foresee people wanting to disable this behavior?

Specifically transpiling fixtures seems fraught.

@vadimdemedes
Member

Specifically transpiling fixtures seems fraught.

Could you elaborate on this? I don't quite understand the reasoning.

@novemberborn
Member

Helpers should contain logic to make it easier to write test. Fixtures contain all sorts of files that relate to your test. If you're testing a Babel plugin you may write .js fixtures that you're using to exercise your tests. Those should not be transpiled.

@sindresorhus
Member

@vdemedes What's your use-case for transpiling fixtures? I'm leaning towards @novemberborn's argument.

@vadimdemedes
Member

My thinking was that everything that resides under test/ belongs to AVA, so it should take care of those files and provide its features (power-assert, ES6, etc) to them as well.

However, @novemberborn's reasoning about fixtures relation to tests does make sense to me now. I will correct this PR and the one in ava-files as well.

@vadimdemedes vadimdemedes changed the title from [WIP] Precompile helpers and fixtures to Precompile helpers and fixtures Dec 12, 2016
@vadimdemedes vadimdemedes changed the title from Precompile helpers and fixtures to Precompile helpers Dec 12, 2016
@Snugug
Snugug commented Dec 16, 2016

w/r/t #1049, I've just installed this branch and ran against an external macro, and it did not appear to resolve the issue that powerAssert is not applied to those tests

@vadimdemedes
Member

@Snugug only files with names starting with _ and located in helpers/ folders get transpiled in this PR. In the issue you mentioned the files are located in macros/ folder, right?

@sindresorhus
Member

Code looks good to me, but needs to be added to the readme.

@vadimdemedes vadimdemedes precompile helpers and fixtures
c3fe5ec
@sindresorhus sindresorhus Update readme.md
1e90484
@sindresorhus sindresorhus merged commit 410cb8d into master Jan 7, 2017

5 of 6 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.08%) to 97.06%
Details
dependency-ci Dependencies checked
Details
@sindresorhus sindresorhus deleted the precompile-helpers-fixtures branch Jan 7, 2017
@sindresorhus
Member
sindresorhus commented Jan 7, 2017 edited

Yay! This one is going to be super useful 💃

Thanks for finishing this up Vadim 👌

@zcei zcei referenced this pull request in sotojuan/redux-ava Jan 17, 2017
Closed

So whats the power-assert problem? #16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment