Skip to content

Conversation

@sotojuan
Copy link
Contributor

@sotojuan sotojuan commented Feb 9, 2016

This fixes #534. Of course, it requires everyone to be on board with the idea of moving files to api.run() instead of the constructor. In case everyone agrees, then this should help. Let me know if I missed anything.

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @novemberborn, @ariporad and @jokeyrhyme to be potential reviewers

@novemberborn
Copy link
Member

Sadly this breaks --watch. To be fair there is no actual integration test from cli.js with --watch so you wouldn't have noticed. The test for lib/watcher stubs all its dependencies. I've opened #537.

files and excludePatterns were assigned so lib/watcher.js could reference them. You'll have to pass them to start() now so the watcher can run the initial tests or specific tests. This probably means defining the defaults in cli.js or perhaps as an export from api.js for programatic convenience. They no longer need to be stored on the API instance. (Looks like it'd be valid to retain the excludePatterns definition in the API constructor though).

explicitTitles is there so the watcher can force a test title prefix even when running a single test. Your change makes it so test titles are always prefixed. If we're willing to go with that we can clean up the code. Otherwise run() should take a second forcePrefixTestTitles argument the watcher can use.

@sotojuan
Copy link
Contributor Author

sotojuan commented Feb 9, 2016

Exporting files and excludePatterns could work but it'd require a big change in a lot of files (I think), so we'd have to get permission from the powers that be (@sindresorhus @jamestalmage).

Some more exploration/updates:

This makes the watcher work:

watcher.js

exports.start = function (logger, api, files, excludePatterns, sources, stdin) {
  var isTest = makeTestMatcher(files, excludePatterns);
  var patterns = getChokidarPatterns(sources, files);
  ...
}

cli.js

var files = cli.input.length ? cli.input : arrify(conf.files);

if (files.length === 0) {
  files = [
    'test.js',
    'test-*.js',
    'test'
  ];
}

var excludePatterns = [
  '!**/node_modules/**',
  '!**/fixtures/**',
   '!**/helpers/**'
];

...

watcher.start(logger, api, files, excludePatterns, arrify(cli.flags.source), process.stdin);

Again, just exploring/messing around. It "works" but the tests for watcher still fail. Will look into it this night.

@novemberborn
Copy link
Member

Exporting files and excludePatterns could work but it'd require a big change in a lot of files (I think), so we'd have to get permission from the powers that be

Those patterns where hidden away inside a function before --watch landed so it should be OK. Real question is where they should be defined such that programmatic usage of the API is still possible even if the patterns are provided when instantiating the API or running the tests.

Again, just exploring/messing around. It "works" but the tests for watcher still fail. Will look into it this night.

Yup that should do it. Just need to provide compatible values in https://github.com/sindresorhus/ava/blob/bdb8b6ebaa05f1dc31cdab7c84aed7d92317b8ed/test/watcher.js#L23 and https://github.com/sindresorhus/ava/blob/bdb8b6ebaa05f1dc31cdab7c84aed7d92317b8ed/test/watcher.js#L95.

@sotojuan
Copy link
Contributor Author

In test/watcher.js:

files = [
  'test.js',
  'test-*.js',
  'test'
];

excludePatterns = [
  '!**/node_modules/**',
  '!**/fixtures/**',
  '!**/helpers/**'
];

...

var start = function (sources) {
  subject.start(logger, api, files, excludePatterns, sources || [], stdin);
};

Under the "Chokidar is installed tests" I get not ok test unfinished for any I try:

test/watcher.js ....................................... 2/4
  chokidar is installed > watches for default source file changes, as well as test files
  not ok test unfinished: watches for default source file changes, as well as test files
    at:
      line: 128
      column: 19
      file: test/watcher.js
      function: test
    source: |
      pending.push(_t.test(name, fn));

  not ok missing plan
    results:
      ok: false
      count: 1
      pass: 1

@novemberborn
Copy link
Member

@sotojuan hard to say. Could you push some code so I can debug it here?

@sotojuan
Copy link
Contributor Author

Done, let me know if you can help!

@novemberborn
Copy link
Member

@sotojuan just had to declare the variables and update more api.files and api.excludePatterns references: https://github.com/novemberborn/ava/commit/aa4e211268bff3ed386ce5c4579c0624ff3c4358.

@novemberborn
Copy link
Member

I think you should keep the default excludePatterns in the API constructor. It only needs to be defined once since it's used for every run. Then the watcher can simply access it like before.

Still need to resolve whether we always want to prefix test titles (even if there's only a single test file) or only when tests are rerun via the watcher. How about making it an option on the API itself, and if --watch is enabled set it to true? That way the watcher output is consistent but regular output is still minimal, and we won't need a second argument to run() in order to differentiate.

@sotojuan
Copy link
Contributor Author

I think you should keep the default excludePatterns in the API constructor. It only needs to be defined once since it's used for every run. Then the watcher can simply access it like before.

Sure, that makes sense.

Still need to resolve whether we always want to prefix test titles (even if there's only a single test file) or only when tests are rerun via the watcher. How about making it an option on the API itself, and if --watch is enabled set it to true? That way the watcher output is consistent but regular output is still minimal, and we won't need a second argument to run() in order to differentiate.

Also makes sense to me, doesn't seem that hard to implement. I'm interested in what the other mantainers think though. If they're on board with it, I'll work on it tonight.

// @sindresorhus @jamestalmage @vdemedes

@sindresorhus
Copy link
Member

👍 Sounds good. I would still want minimal output in non-watch mode.

@sotojuan
Copy link
Contributor Author

All right, I think I got it but I feel like I am missing something. Let me know!

api.js Outdated
this[key] = this[key].bind(this);
}, this);

this._reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the overall diff you'll see that these lines were moved above this.excludePatterns. Would be nice to leave them undisturbed.

@novemberborn
Copy link
Member

All right, I think I got it but I feel like I am missing something. Let me know!

Getting close! The code is now doing a little bit of the old behavior, and a little bit of the new behavior.

cli.js should control the default files patterns. Api#run() should assume it's called with patterns and not force defaults. That means the watcher should call Api#run() with the files argument it received from cli.js.

explicitTitles is either on or off, it doesn't need to change based on the arguments to Api#run(). It's configured correctly by cli.js based on the --watch flag.

@sotojuan
Copy link
Contributor Author

Okay, I'll give these a shot throughout the day. One thing I am confused about though, look at this test. Supposedly it's testing for prefixes, but it's a single file, so it fails with the changes since by default there's no explicit titles for just one file. Should I update the test so it sets the explicitTitles option? Or is it a problem with my changes?

It's the same case with a couple of the tests in api.js. I added explicitTitles: true to those that were failing and the changes you mentioned above and all tests are passing, but I'd like to know before pushing!

@novemberborn
Copy link
Member

Should I update the test so it sets the explicitTitles option?

Yes.

It's the same case with a couple of the tests in api.js. I added explicitTitles: true to those that were failing and the changes you mentioned above and all tests are passing, but I'd like to know before pushing!

Push away! :)

@sotojuan
Copy link
Contributor Author

Builds and tests pass fine in my Macbook, not sure what's up with AppVeyor.

test/watcher.js Outdated

try {
subject.start({}, {files: [], excludePatterns: []}, []);
subject.start({}, {}, [], []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to keep {exludePatterns: []} here, even though the test doesn't fail without it.

@sotojuan
Copy link
Contributor Author

OK, well for now I fixed all the small stuff. Like I mentioned earlier, the test for failFast does need explicitTitles to be set to true as the output it tests for has prefixes.

I'm not very experienced with conflicts so any instructions on how to deal with that would be great!

@novemberborn
Copy link
Member

Like I mentioned earlier, the test for failFast does need explicitTitles to be set to true as the output it tests for has prefixes.

Yes but if you check the full diff you'll notice you added those prefixes in this PR ;-)

test/watcher.js Outdated
'!**/node_modules/**',
'!**/fixtures/**',
'!**/helpers/**'
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this now.

@novemberborn
Copy link
Member

I'm not very experienced with conflicts so any instructions on how to deal with that would be great!

https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line/ may help.

This will pull in the new watcher test in test/cli.js, so don't forget about https://github.com/novemberborn/ava/commit/651343f9d864b45aae187bad0958a908546a23f8 ;-)

@sotojuan
Copy link
Contributor Author

Yes but if you check the full diff you'll notice you added those prefixes in this PR ;-)

Haha I totally forgot I did that! It's been a while!

@sotojuan
Copy link
Contributor Author

@novemberborn When you are not busy, can you review? Thanks!

@novemberborn
Copy link
Member

When you are not busy, can you review? Thanks!

Oh didn't notice you fixed the merge conflict. Next time ping me more explicitly when you've updated the PR 😄

The watcher test in test/cli.js is failing. The solution is in https://github.com/novemberborn/ava/commit/651343f9d864b45aae187bad0958a908546a23f8 (minus the console.error call I left in by mistake).

@novemberborn
Copy link
Member

LGTM otherwise.

@sotojuan
Copy link
Contributor Author

Thanks, um should I just copy what's in that commit you linked me to or is that something that will be merged?

@novemberborn
Copy link
Member

@sotojuan copy yea. It only lives within my fork :)

@novemberborn
Copy link
Member

@sotojuan are you running all tests?

@sotojuan
Copy link
Contributor Author

I had some stuff I hadn't merged with master yet, should be good now.

@sotojuan
Copy link
Contributor Author

Phew, all green on Travis (AppVeyor will take longer), finally!

@novemberborn
Copy link
Member

Great! :shipit: ❗ 🎉

@sindresorhus
Copy link
Member

LGTM

@vadimdemedes
Copy link
Contributor

LGTM!

@novemberborn
Copy link
Member

Thanks @sotojuan!

@sindresorhus
Copy link
Member

Thank you @sotojuan! Good work as usual.

pine added a commit to taskrjs/fly-ava that referenced this pull request Mar 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider moving files patterns from API constructor to run() method

5 participants