nx/e2e/vue/src/vue-ts-solution.test.ts
Leosvel Pérez Espinosa ada8be473d
fix(misc): fix misc issues in project generators for the ts solution setup (#30111)
The following are the main changes in the context of the TS solution
setup:

- Ensure `name` in `package.json` files is set to the import path for
all projects
- Set `nx.name` in `package.json` files when the user provides a name
different than the package name (import path)
- Clean up project generators so they don't set the `nx` property in
`package.json` files unless strictly needed
- Fix `@nx/vue:application` generator so it creates the Nx config in a
`package.json` file for e2e projects
- Ensure `@types/node` is installed in `vitest` generator
- Fix generated Vite config typing error (surfaced with Vite 6)
- Ensure `jsonc-eslint-parser` is installed when the
`@nx/dependency-checks` rule is added to the ESLint config
- Misc minor alignment changes

## Current Behavior

## Expected Behavior

## Related Issue(s)

Fixes #
2025-03-05 20:08:10 -05:00

86 lines
2.3 KiB
TypeScript

import {
cleanupProject,
newProject,
readJson,
runCLI,
uniq,
updateFile,
} from '@nx/e2e/utils';
describe('Vue (TS solution)', () => {
let proj: string;
beforeAll(() => {
proj = newProject({
packages: ['@nx/vue'],
preset: 'ts',
});
});
afterAll(() => cleanupProject());
it('should serve application in dev mode', async () => {
const app = uniq('app');
const lib = uniq('lib');
runCLI(
`generate @nx/vue:app apps/${app} --unitTestRunner=vitest --e2eTestRunner=playwright --linter=eslint`
);
runCLI(
`generate @nx/vue:lib packages/${lib} --bundler=vite --unitTestRunner=vitest --linter=eslint`
);
// app and lib generators don't have specs by default, add some stubs
updateFile(
`apps/${app}/src/foo.spec.ts`,
`
test('it should run', () => {
expect(true).toBeTruthy();
});
`
);
updateFile(
`packages/${lib}/src/foo.spec.ts`,
`
test('it should run', () => {
expect(true).toBeTruthy();
});
`
);
expect(() => runCLI(`lint @proj/${app}`)).not.toThrow();
expect(() => runCLI(`test @proj/${app}`)).not.toThrow();
expect(() => runCLI(`build @proj/${app}`)).not.toThrow();
expect(() => runCLI(`lint @proj/${lib}`)).not.toThrow();
expect(() => runCLI(`test @proj/${lib}`)).not.toThrow();
expect(() => runCLI(`build @proj/${lib}`)).not.toThrow();
}, 300_000);
it('should respect and support generating libraries with a name different than the import path', async () => {
const lib = uniq('lib');
runCLI(
`generate @nx/vue:library packages/${lib} --name=${lib} --bundler=vite --unitTestRunner=vitest`
);
// lib generator doesn't generate specs, add one
updateFile(
`packages/${lib}/src/foo.spec.ts`,
`test('it should run', () => {
expect(true).toBeTruthy();
});`
);
const packageJson = readJson(`packages/${lib}/package.json`);
expect(packageJson.nx.name).toBe(lib);
expect(runCLI(`build ${lib}`)).toContain(
`Successfully ran target build for project ${lib}`
);
expect(runCLI(`typecheck ${lib}`)).toContain(
`Successfully ran target typecheck for project ${lib}`
);
expect(runCLI(`test ${lib}`)).toContain(
`Successfully ran target test for project ${lib}`
);
}, 300_000);
});