Skip to content

Commit

Permalink
feat(vite): more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Nov 8, 2023
1 parent 276b959 commit f76740b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
71 changes: 64 additions & 7 deletions packages/vite/src/migrations/update-17-2-0/add-vite-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,74 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree } from '@nx/devkit';

import {
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
import update from './add-vite-plugin';
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
import { UserConfig } from 'vite';

describe('add-vite-plugin migration', () => {
describe('add-nx-cypress-plugin migration', () => {
let tree: Tree;
let tempFs: TempFs;

function mockViteConfig(configPath: string, config: UserConfig) {
jest.mock(
configPath,
() => ({
default: config,
}),
{
virtual: true,
}
);
}

beforeEach(async () => {
tempFs = new TempFs('test');
tree = createTreeWithEmptyWorkspace();
tree.root = tempFs.tempDir;
await tempFs.createFiles({
'my-app/vite.config.ts': '',
'my-app/project.json': '{ "name": "my-app" }',
});
tree.write('my-app/vite.config.ts', `console.log('hi');`);
});

beforeEach(() => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
afterEach(() => {
jest.resetModules();
tempFs.cleanup();
});

it('should run successfully', async () => {
it('should remove the serve target', async () => {
mockViteConfig('vite.config.ts', {});
updateProjectConfiguration(tree, 'my-app', {
root: 'my-app',
targets: {
serve: {
executor: '@nx/vite:dev-server',
defaultConfiguration: 'development',
options: {
buildTarget: 'my-app:build',
},
configurations: {
development: {
buildTarget: 'my-app:build:development',
hmr: true,
},
production: {
buildTarget: 'my-app:build:production',
hmr: false,
},
},
},
},
});

await update(tree);
// ... expect changes made

expect(
readProjectConfiguration(tree, 'my-app').targets.serve
).toBeUndefined();
});
});
2 changes: 1 addition & 1 deletion packages/vite/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CreateNodesContext } from '@nx/devkit';
import type { UserConfig } from 'vite';
import { createNodes } from './plugin';
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
import { join } from 'path';

describe('@nx/vite/plugin', () => {
let createNodesFunction = createNodes[1];
let context: CreateNodesContext;
Expand Down

0 comments on commit f76740b

Please sign in to comment.