Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/js/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1773,28 +1773,30 @@ describe('lib', () => {
});

describe('--testEnvironment', () => {
it('should generate a vite config with testEnvironment set to node', async () => {
it('should generate a vitest config with testEnvironment set to node', async () => {
await libraryGenerator(tree, {
...defaultOptions,
directory: 'my-node-lib',
unitTestRunner: 'vitest',
testEnvironment: 'node',
});

const content = tree.read('my-node-lib/vite.config.ts', 'utf-8');
expect(tree.exists('my-node-lib/vite.config.ts')).toBe(false);
const content = tree.read('my-node-lib/vitest.config.mts', 'utf-8');

expect(content).toContain(`environment: 'node'`);
});

it('should generate a vite config with testEnvironment set to jsdom by default', async () => {
it('should generate a vitest config with testEnvironment set to jsdom by default', async () => {
await libraryGenerator(tree, {
...defaultOptions,
directory: 'my-jsdom-lib',
unitTestRunner: 'vitest',
testEnvironment: undefined,
});

const content = tree.read('my-jsdom-lib/vite.config.ts', 'utf-8');
expect(tree.exists('my-jsdom-lib/vite.config.ts')).toBe(false);
const content = tree.read('my-jsdom-lib/vitest.config.mts', 'utf-8');

expect(content).toContain(`environment: 'jsdom'`);
});
Expand Down
11 changes: 0 additions & 11 deletions packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export async function libraryGeneratorInternal(
options.unitTestRunner === 'vitest' &&
options.bundler !== 'vite' // Test would have been set up already
) {
const { createOrEditViteConfig } = ensurePackage('@nx/vite', nxVersion);
ensurePackage('@nx/vitest', nxVersion);
// nx-ignore-next-line
const { configurationGenerator } = require('@nx/vitest/generators');
Expand All @@ -188,16 +187,6 @@ export async function libraryGeneratorInternal(
addPlugin: options.addPlugin,
});
tasks.push(vitestTask);
createOrEditViteConfig(
tree,
{
project: options.name,
includeLib: false,
includeVitest: true,
testEnvironment: options.testEnvironment,
},
true
);
}

if (!schema.skipTsConfig && !options.isUsingTsSolutionConfig) {
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin/src/generators/plugin/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('NxPlugin Plugin Generator', () => {
});

describe('vitest', () => {
it('should generate test files with vite.config.ts', async () => {
it('should generate test files with vitest.config.mts', async () => {
await pluginGenerator(
tree,
getSchema({
Expand All @@ -245,7 +245,8 @@ describe('NxPlugin Plugin Generator', () => {
})
);

['my-plugin/vite.config.ts'].forEach((path) =>
expect(tree.exists('my-plugin/vite.config.ts')).toBeFalsy();
['my-plugin/vitest.config.mts'].forEach((path) =>
expect(tree.exists(path)).toBeTruthy()
);

Expand Down
Loading