question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(CLI 3.0 BETA) Allow option to place test files alongside source files instead of separate "tests/unit" folder

See original GitHub issue

What problem does this feature solve?

There are many advantages to having test files live alongside your source files instead of placing all test files in a separate folder. When creating a new Vue project via the CLI, it would be fantastic to be able to choose placing all unit tests inside of a separate “tests/unit” folder OR place unit test files alongside source in “src/**/*.spec.js”.

The “test” command in the package.json that is generated can be easily tweaked to make this work:

"test": "vue-cli-service test 'src/**/*.spec.js'"

This allows for a project structure like so:

./src ./src/components ./src/components/my-component.vue ./src/components/my-component.spec.js

What does the proposed API look like?

When running vue create, I’d imagine a question asking where you’d like your unit tests to live. Either a separate test folder, or alongside source.

Thanks for all the amazing work!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

31reactions
calebjacobcommented, May 10, 2018

Fair enough - thanks for the feedback!

For any others who might come across this in the future, here’s how you can move your unit tests to live alongside your source (the solution is different based on using Mocha vs. Jest):

Mocha

In your package.json file, modify the test script to be:

"vue-cli-service test 'src/**/*.spec.js'"

Then enable the mocha env in your root .eslintrc.js file:

env: {
  mocha: true
}

Jest

In your jest.config.js file, modify the testMatch config to be:

['<rootDir>/(src/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))']

Then enable the Jest env in your root .eslintrc.js file:

env: {
  jest: true
}
9reactions
NathanStrutzcommented, Jan 7, 2020

I have my configuration all in my package.json file. I changed my “jest” section to this and it looks like it’s working perfectly:

  "jest": {
    "preset": "@vue/cli-plugin-unit-jest",
    "testMatch": [
      "<rootDir>/src/**/*.(spec|test).(ts|js)"
    ]
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pros and cons of placing test files in the same folder as source ...
Option #2 is the way I'd go. When thinking about the Angular 2 components, I consider them to be a single entity, made...
Read more >
Organizing and testing projects with the .NET CLI - .NET
This tutorial explains how to organize and test .NET projects from the command line. ... Place the type files into the Models folder:....
Read more >
Unit test reports - GitLab Docs
First, GitLab Runner uploads all JUnit report format XML files as artifacts to ... the panel shows only the list of failed tests...
Read more >
Testing Guide - OWASP Foundation
BETA : “Beta Quality” book content is the next highest level. Content is still in development until the next publishing. RELEASE: “Release Quality”...
Read more >
How to perform Cypress Test Automation | BrowserStack
Cypress comes with Command line Interface aka Cypress CLI which ... Create the test file first-test.js inside the spec folder created in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found