Welcome to Hello!
-Welcome to Hello!
- + " `; exports[`component should generate files with jest 2`] = ` "import { mount } from '@vue/test-utils'; -import Hello from '../hello.vue'; +import Hello from './hello.vue'; describe('Hello', () => { it('renders properly', () => { @@ -43,16 +37,10 @@ defineProps<{}>(); -Welcome to Hello!
-Welcome to Hello!
- + " `; @@ -60,7 +48,7 @@ exports[`component should generate files with vitest 2`] = ` "import { describe, it, expect } from 'vitest'; import { mount } from '@vue/test-utils'; -import Hello from '../hello.vue'; +import Hello from './hello.vue'; describe('Hello', () => { it('renders properly', () => { diff --git a/packages/vue/src/generators/component/component.spec.ts b/packages/vue/src/generators/component/component.spec.ts index c2c6c1ffed..6a1333d6fd 100644 --- a/packages/vue/src/generators/component/component.spec.ts +++ b/packages/vue/src/generators/component/component.spec.ts @@ -1,4 +1,4 @@ -import { logger, readJson, Tree } from '@nx/devkit'; +import { logger, Tree } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { componentGenerator } from './component'; import { createLib } from '../../utils/test-utils'; @@ -30,17 +30,14 @@ describe('component', () => { appTree.exists('my-lib/src/components/hello/hello.vue') ).toBeTruthy(); expect( - appTree.exists('my-lib/src/components/hello/__tests__/hello.spec.ts') + appTree.exists('my-lib/src/components/hello/hello.spec.ts') ).toBeTruthy(); expect( appTree.read('my-lib/src/components/hello/hello.vue', 'utf-8') ).toMatchSnapshot(); expect( - appTree.read( - 'my-lib/src/components/hello/__tests__/hello.spec.ts', - 'utf-8' - ) + appTree.read('my-lib/src/components/hello/hello.spec.ts', 'utf-8') ).toMatchSnapshot(); }); @@ -55,10 +52,7 @@ describe('component', () => { appTree.read('my-lib/src/components/hello/hello.vue', 'utf-8') ).toMatchSnapshot(); expect( - appTree.read( - 'my-lib/src/components/hello/__tests__/hello.spec.ts', - 'utf-8' - ) + appTree.read('my-lib/src/components/hello/hello.spec.ts', 'utf-8') ).toMatchSnapshot(); }); @@ -114,7 +108,7 @@ describe('component', () => { appTree.exists('my-lib/src/components/hello/Hello.vue') ).toBeTruthy(); expect( - appTree.exists('my-lib/src/components/hello/__tests__/Hello.spec.ts') + appTree.exists('my-lib/src/components/hello/Hello.spec.ts') ).toBeTruthy(); }); }); @@ -131,9 +125,7 @@ describe('component', () => { appTree.exists('my-lib/src/components/HelloWorld/HelloWorld.vue') ).toBeTruthy(); expect( - appTree.exists( - 'my-lib/src/components/HelloWorld/__tests__/HelloWorld.spec.ts' - ) + appTree.exists('my-lib/src/components/HelloWorld/HelloWorld.spec.ts') ).toBeTruthy(); }); }); diff --git a/packages/vue/src/generators/component/files/__tests__/__fileName__.spec.ts__tmpl__ b/packages/vue/src/generators/component/files/__fileName__.spec.ts__tmpl__ similarity index 85% rename from packages/vue/src/generators/component/files/__tests__/__fileName__.spec.ts__tmpl__ rename to packages/vue/src/generators/component/files/__fileName__.spec.ts__tmpl__ index ce03988f4e..4980177b0e 100644 --- a/packages/vue/src/generators/component/files/__tests__/__fileName__.spec.ts__tmpl__ +++ b/packages/vue/src/generators/component/files/__fileName__.spec.ts__tmpl__ @@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest' <% } %> import { mount } from '@vue/test-utils' -import <%= className %> from '../<%= fileName %>.vue'; +import <%= className %> from './<%= fileName %>.vue'; describe('<%= className %>', () => { it('renders properly', () => { diff --git a/packages/vue/src/generators/component/files/__fileName__.vue__tmpl__ b/packages/vue/src/generators/component/files/__fileName__.vue__tmpl__ index 08f17aeb6e..a8c6e6179a 100644 --- a/packages/vue/src/generators/component/files/__fileName__.vue__tmpl__ +++ b/packages/vue/src/generators/component/files/__fileName__.vue__tmpl__ @@ -3,13 +3,8 @@ defineProps<{}>() -Welcome to <%= className %>!
-Welcome to <%= className %>!
\ No newline at end of file + diff --git a/packages/vue/src/generators/library/library.spec.ts b/packages/vue/src/generators/library/library.spec.ts index 2521e2aea5..9d5d6bde90 100644 --- a/packages/vue/src/generators/library/library.spec.ts +++ b/packages/vue/src/generators/library/library.spec.ts @@ -163,9 +163,7 @@ describe('lib', () => { expect(tree.exists('my-lib/package.json')).toBeFalsy(); expect(tree.exists('my-lib/src/index.ts')).toBeTruthy(); expect(tree.exists('my-lib/src/components/my-lib.vue')).toBeTruthy(); - expect( - tree.exists('my-lib/src/components/__tests__/my-lib.spec.ts') - ).toBeTruthy(); + expect(tree.exists('my-lib/src/components/my-lib.spec.ts')).toBeTruthy(); const eslintJson = readJson(tree, 'my-lib/.eslintrc.json'); expect(eslintJson).toMatchSnapshot(); }); @@ -206,9 +204,7 @@ describe('lib', () => { tree.exists('my-dir/my-lib/src/components/my-dir-my-lib.vue') ).toBeTruthy(); expect( - tree.exists( - 'my-dir/my-lib/src/components/__tests__/my-dir-my-lib.spec.ts' - ) + tree.exists('my-dir/my-lib/src/components/my-dir-my-lib.spec.ts') ).toBeTruthy(); }); diff --git a/packages/vue/src/generators/stories/lib/component-story.spec.ts b/packages/vue/src/generators/stories/lib/component-story.spec.ts index 1a49bffbc0..e000fbaef9 100644 --- a/packages/vue/src/generators/stories/lib/component-story.spec.ts +++ b/packages/vue/src/generators/stories/lib/component-story.spec.ts @@ -44,15 +44,10 @@ describe('vue:component-story', () => { -Welcome to Vlv!
-Welcome to Vlv!
` ); @@ -88,15 +83,10 @@ describe('vue:component-story', () => { -Welcome to Vlv!
-Welcome to Vlv!
` ); diff --git a/packages/vue/src/generators/stories/stories.app.spec.ts b/packages/vue/src/generators/stories/stories.app.spec.ts index 5debc93bd1..b9a327d573 100644 --- a/packages/vue/src/generators/stories/stories.app.spec.ts +++ b/packages/vue/src/generators/stories/stories.app.spec.ts @@ -13,15 +13,10 @@ defineProps<{ -Welcome to Vlv!
-Welcome to Vlv!
`; @@ -44,7 +39,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.read('test-ui-app/src/components/NxWelcome.stories.ts', 'utf-8') + appTree.read('test-ui-app/src/app/NxWelcome.stories.ts', 'utf-8') ).toMatchSnapshot(); expect( appTree.read( @@ -61,7 +56,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.read('test-ui-app/src/components/NxWelcome.stories.ts', 'utf-8') + appTree.read('test-ui-app/src/app/NxWelcome.stories.ts', 'utf-8') ).toMatchSnapshot(); expect( appTree.read( @@ -73,7 +68,7 @@ describe('vue:stories for applications', () => { it('should not update existing stories', async () => { appTree.write( - 'test-ui-app/src/components/NxWelcome.stories.ts', + 'test-ui-app/src/app/NxWelcome.stories.ts', `import { ComponentStory, ComponentMeta } from '@storybook/vue3'` ); @@ -82,7 +77,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.read('test-ui-app/src/components/NxWelcome.stories.ts', 'utf-8') + appTree.read('test-ui-app/src/app/NxWelcome.stories.ts', 'utf-8') ).toMatchSnapshot(); }); @@ -104,7 +99,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.exists('test-ui-app/src/components/NxWelcome.stories.ts') + appTree.exists('test-ui-app/src/app/NxWelcome.stories.ts') ).toBeTruthy(); expect( appTree.exists( @@ -135,7 +130,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.exists('test-ui-app/src/components/NxWelcome.stories.ts') + appTree.exists('test-ui-app/src/app/NxWelcome.stories.ts') ).toBeTruthy(); expect( appTree.exists( @@ -166,7 +161,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.exists('test-ui-app/src/components/NxWelcome.stories.ts') + appTree.exists('test-ui-app/src/app/NxWelcome.stories.ts') ).toBeTruthy(); expect( appTree.exists( @@ -194,7 +189,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.exists('test-ui-app/src/components/NxWelcome.stories.ts') + appTree.exists('test-ui-app/src/app/NxWelcome.stories.ts') ).toBeTruthy(); expect( appTree.exists( @@ -229,7 +224,7 @@ describe('vue:stories for applications', () => { }); expect( - appTree.exists('test-ui-app/src/components/NxWelcome.stories.ts') + appTree.exists('test-ui-app/src/app/NxWelcome.stories.ts') ).toBeTruthy(); expect( appTree.exists( diff --git a/packages/vue/src/generators/stories/stories.lib.spec.ts b/packages/vue/src/generators/stories/stories.lib.spec.ts index 5b58dd3d40..d0b48c27fb 100644 --- a/packages/vue/src/generators/stories/stories.lib.spec.ts +++ b/packages/vue/src/generators/stories/stories.lib.spec.ts @@ -13,15 +13,10 @@ defineProps<{ -Welcome to Vlv!
-Welcome to Vlv!
`; diff --git a/packages/vue/src/generators/stories/stories.ts b/packages/vue/src/generators/stories/stories.ts index d33a04787a..89e66a10fc 100644 --- a/packages/vue/src/generators/stories/stories.ts +++ b/packages/vue/src/generators/stories/stories.ts @@ -12,9 +12,9 @@ import { visitNotIgnoredFiles, } from '@nx/devkit'; import { basename, join } from 'path'; -import minimatch = require('minimatch'); import { nxVersion } from '../../utils/versions'; import { createComponentStories } from './lib/component-story'; +import minimatch = require('minimatch'); export interface StorybookStoriesSchema { project: string; @@ -36,22 +36,28 @@ export async function createAllStories( ) { const { sourceRoot, root } = projectConfiguration; let componentPaths: string[] = []; - const projectPath = joinPathFragments(sourceRoot, 'components'); - visitNotIgnoredFiles(tree, projectPath, (path) => { - // Ignore private files starting with "_". - if (basename(path).startsWith('_')) return; - if (ignorePaths?.some((pattern) => minimatch(path, pattern))) return; - if (path.endsWith('.vue')) { - // Let's see if the .stories.* file exists - const ext = path.slice(path.lastIndexOf('.')); - const storyPathJs = `${path.split(ext)[0]}.stories.js`; - const storyPathTs = `${path.split(ext)[0]}.stories.ts`; + const pathsToCheck = [ + joinPathFragments(sourceRoot, 'app'), // Default component folder for apps + joinPathFragments(sourceRoot, 'components'), // Additional component folder + ]; - if (!tree.exists(storyPathJs) && !tree.exists(storyPathTs)) { - componentPaths.push(path); + for (const p of pathsToCheck) { + visitNotIgnoredFiles(tree, p, (path) => { + // Ignore private files starting with "_". + if (basename(path).startsWith('_')) return; + if (ignorePaths?.some((pattern) => minimatch(path, pattern))) return; + if (path.endsWith('.vue')) { + // Let's see if the .stories.* file exists + const ext = path.slice(path.lastIndexOf('.')); + const storyPathJs = `${path.split(ext)[0]}.stories.js`; + const storyPathTs = `${path.split(ext)[0]}.stories.ts`; + + if (!tree.exists(storyPathJs) && !tree.exists(storyPathTs)) { + componentPaths.push(path); + } } - } - }); + }); + } await Promise.all( componentPaths.map(async (componentPath) => { diff --git a/packages/vue/src/generators/storybook-configuration/configuration.spec.ts b/packages/vue/src/generators/storybook-configuration/configuration.spec.ts index 666e087816..2a45bcd245 100644 --- a/packages/vue/src/generators/storybook-configuration/configuration.spec.ts +++ b/packages/vue/src/generators/storybook-configuration/configuration.spec.ts @@ -22,15 +22,10 @@ defineProps<{ -Welcome to Vlv!
-Welcome to Vlv!
`;