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

Add Nuxt.js recipe #2092

Closed
wants to merge 9 commits into from
Closed

Add Nuxt.js recipe #2092

wants to merge 9 commits into from

Conversation

vinayakkulkarni
Copy link

Fixes #2063

  • Boilerplate for new user of Nuxt as well as Ava could be found here

@sindresorhus sindresorhus changed the title [docs] Added Nuxt.js recipe Add Nuxt.js recipe Apr 19, 2019
@vinayakkulkarni
Copy link
Author

bump

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

Hey @vinayakkulkarni thanks for the PR. I've been focusing on getting the 2.0 beta release out so unfortunately this fell by the wayside. Overall, and note that I'm not familiar with Vue & Nuxt, it's unclear why this requires Babel. Some other setup seems like it may be your preference rather than strictly necessary for testing with AVA. See my comments below. Let me know what you think, thanks.

docs/recipes/nuxt.md Outdated Show resolved Hide resolved
docs/recipes/nuxt.md Outdated Show resolved Hide resolved
docs/recipes/nuxt.md Show resolved Hide resolved
hooks(['vue', 'js']).exclude(({filename}) => filename.match(/\/node_modules\//)).plugin('babel').push();
```

**`.babelrc`:**
Copy link
Member

Choose a reason for hiding this comment

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

I believe Babel is recommending the config goes into babel.config.js files these days. Why does this require Babel at all?

Copy link
Author

Choose a reason for hiding this comment

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

  • Mostly for the module-resolver

Copy link
Author

@vinayakkulkarni vinayakkulkarni May 20, 2019

Choose a reason for hiding this comment

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

],
"alias": {
"@": ".",
"~": "."
Copy link
Member

Choose a reason for hiding this comment

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

Are these typical aliases for Vue projects? It seems irrelevant for this recipe.

Copy link
Author

Choose a reason for hiding this comment

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

Nuxt also has aliases which are helpful when writing Vue components in Nuxt apps.

Ref: https://nuxtjs.org/guide/directory-structure/#aliases

Copy link
Author

Choose a reason for hiding this comment

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

Are these typical aliases for Vue projects? It seems irrelevant for this recipe.

Yes, There can be components deep inside directories and test directory ideally also imitate the project structure (snapshots looks really seksy), so having ../../../../../pages/dashboard/sidebar/nav/logout.vue would be very ugly inside the test which lies inside /test/pages/dashboard/sidebar/nav/logout.spec.js. Hence the alias!

docs/recipes/nuxt.md Outdated Show resolved Hide resolved
Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

Thanks for updating this @vinayakkulkarni. I think some of the setup could still be simplified, and I just noticed that the wrapper variable is reused between tests which won't always work. Could you have another look at this?

```js
import {mount, createLocalVue} from '@vue/test-utils';
import test from 'ava';
import Index from '@/pages/index.vue';
Copy link
Member

Choose a reason for hiding this comment

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

Given that this is an example, maybe we could simplify it by removing the @ resolver? It'll be easier to understand the test example.

You could still document how to hook up Babel so it processes .vue files.

const localVue = createLocalVue();

test.beforeEach(() => {
wrapper = mount(Index, {
Copy link
Member

Choose a reason for hiding this comment

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

You cannot use a shared variable in a beforeEach() hook. It works in this example, because the tests are synchronous. But if you had asynchronous tests then the beforeEach hooks would run and change the wrapper value.

If it can be shared, use test.before(). But perhaps better yet is to assign it to the context:

test.beforeEach(t => {
  t.context.wrapper = mount(Index, { localVue })
})

test('is a Vue instance', t => {
  t.true(t.context.wrapper.isVueInstance())
})

@novemberborn
Copy link
Member

Closing due to inactivity.

@vinayakkulkarni vinayakkulkarni deleted the add-nuxt-recipe branch March 29, 2020 13:52
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.

NuxtJS/VueJS recipe for ava
3 participants