Skip to content

Conversation

@jankuca
Copy link
Contributor

@jankuca jankuca commented Nov 15, 2015

This change adds support for whatever.spec.js test file names (in the context of prefixing test results by the CLI) which is a quite common practice really. The former logic which trims test- prefixes stays in place.

test-whatever.js => whatever
test-whatever.spec.js => test-whatever

It might even make sense to include support for the whateverSpec.js variation.

@sindresorhus
Copy link
Member

which is a quite common practice really

Never seen it before. Can you link to something that proves your point?

It might even make sense to include support for the whateverSpec.js variation.

👎

And where do you keep these *.spec.js files? In a test folder? In root?

@jankuca
Copy link
Contributor Author

jankuca commented Nov 15, 2015

A quick Google query popped out a few examples:

  1. http://backbone-testing.com/

Chapter 1: Setting up a Test Infrastructure

  • Trying out the test libraries: Some first basic unit tests using Mocha, Chai, and SinonJS.
    • hello.spec.js
  • Test Failures: Different types of test failures.
    • failure.spec.js
  • Test Timing: Tests that take different times, which Mocha annotates for "medium" and "slow" tests. Also has one test timeout failure.
    • timing.spec.js
  1. http://blog.revolunet.com/blog/2013/12/05/unit-testing-angularjs-directive/

Here’s our example “files” section :
files: [
...
"src/angular-stepper.js", <-- our component source code
"src/angular-stepper.spec.js" <-- our component test suite
]

  1. https://review.openstack.org/#/c/184543/28/openstack_dashboard/static/openstack-service-api/common-test.spec.js,unified

  2. The latter (whateverSpec.js) convention is used by jasmine-node for instance – https://github.com/mhevery/jasmine-node

Note: your specification files must be named as spec.js, spec.coffee or spec.litcoffee, which matches the regular expression /spec.(js|coffee|litcoffee)$/i; otherwise jasmine-node won't find them! For example, sampleSpecs.js is wrong, sampleSpec.js is right.

@jankuca
Copy link
Contributor Author

jankuca commented Nov 15, 2015

And where do you keep these *.spec.js files? In a test folder? In root?

I personally keep them in the test/ folder, yes.

@sindresorhus
Copy link
Member

I personally keep them in the test/ folder, yes.

Ok, so it seems it's for marking something as a test when you have both the test and the actual code in the same directory. Not saying we won't accept this PR, but you are not doing this, so you really don't need the .spec postfix in your case.

@jankuca
Copy link
Contributor Author

jankuca commented Nov 15, 2015

…when you have both the test and the actual code in the same directory

Yes, I've seen that a couple of times and even tried it. I've come to the conclusion that it is more practical to have spec files in a separate top-level folder.

The real reason I keep using the suffix is mostly because it is possible to determine the type of a file (implementation/spec/mock) from its basename.

screen shot 2015-11-15 at 9 34 03 pm

@schnittstabil
Copy link

I personally keep them in the test/ folder, yes.

@jankuca Aren't your test files run? I thought they should, because:

  Usage
    ava [<file|folder|glob> ...]
…
  Default patterns when no arguments:
  test.js test-*.js test/*.js

@jankuca
Copy link
Contributor Author

jankuca commented Nov 15, 2015

Aren't your test files run?

No, they are, everything's working fine. Only the result prefixes are wrong:

screen shot 2015-11-15 at 9 43 57 pm

Copy link
Contributor

Choose a reason for hiding this comment

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

to avoid the if condition, you could just do this:

.replace(/\.spec/, '')
.replace(/test\-/g, '')

@vadimdemedes
Copy link
Contributor

I am now wondering if it's not just easier to rename .spec suffix from file names. That way we won't tailor AVA to every possible use case out there.

@vadimdemedes
Copy link
Contributor

But for now, @sindresorhus and I think that this is an easy fix'n'win, so I guess we'll just merge this PR ;)

@vadimdemedes
Copy link
Contributor

@jankuca could you please fix the comments in this PR?

@vadimdemedes
Copy link
Contributor

@jankuca Never mind, I made the changes myself ;)

@jankuca
Copy link
Contributor Author

jankuca commented Nov 16, 2015

Thanks!

The reason I've put the if there was to handle a single spec file naming convention at once.

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.

4 participants