Skip to content
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

feat: resolve rootDir #107

Merged
merged 4 commits into from
Apr 8, 2021
Merged

feat: resolve rootDir #107

merged 4 commits into from
Apr 8, 2021

Conversation

ricardogobbosouza
Copy link
Collaborator

@ricardogobbosouza ricardogobbosouza commented Mar 31, 2021

Resolves #346, #279

@ricardogobbosouza ricardogobbosouza requested a review from pi0 March 31, 2021 21:35
@mrazauskas
Copy link

For apps it might be better to set options.fixture = process.cwd() instead of options.rootDir = process.cwd(). The app is the fixture in this case. So obvious, but took me few days to understand.

If the app is at /the-app folder and options.fixture = process.cwd() is set loadNuxtConfig is called with:

testDir: /the-app/test
rootDir: /the-app
buildDir: /the-app/.nuxt/<randomID>

Seems perfect for app testing or I missed something? If I get it right loadFixture function simply overwrites anything what was set in options.rootDir. To avoid calling loadFixture one could pass options.fixture = false.

Another thing – how do we know if an app or a module is under test? It might be I found a solution. Playing with working prototype right now. Will send in a PR in few days.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

  • Value of rootDir, can be determined by searching in an array of [options.rootDir, resolve(options.testDir, options.fixture), process.cwd()]
    • We have a match if dir exists and dir/pages or dir/nuxt.config exists
    • If non of array items do match, we should throw an error asking to explicitly set options.rootDir pointing to a valid nuxt app

@pi0 pi0 changed the title fix: define rootDir feat: resolve rootDir Apr 1, 2021
@mrazauskas
Copy link

What if dir/pages is found, but these are just some pages, but not Nuxt routes? Don’t get me wrong, I agree that it would be very smart to do this check. At the same time dir/pages is so generic.

Might work, of course. But in some case it will fail. Perhaps it would be helpful to console.info why the algorithm made one or another assumption. One could see what the app was trying to do and then it is easier to debug.

@ricardogobbosouza ricardogobbosouza requested a review from pi0 April 1, 2021 16:02
src/nuxt.ts Outdated Show resolved Hide resolved
@ricardogobbosouza ricardogobbosouza requested a review from pi0 April 1, 2021 16:59
@pi0 pi0 merged commit f604dff into main Apr 8, 2021
@pi0 pi0 deleted the fix-define-rootDir branch April 8, 2021 12:59
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.

Detect rootDir if not defined
3 participants