UNPKG

@nx-plugins/vite

Version:

The Nx Plugin for Vite that contains executors, generators, and utilities for managing Vite applications and libraries within an Nx workspace.

136 lines 5.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const executor_1 = require("./executor"); const vite_1 = require("vite"); const vitest_1 = require("vitest"); vitest_1.vi.mock('vite', () => { return { createServer: vitest_1.vi.fn(() => ({ printUrls: vitest_1.vi.fn(), listen: vitest_1.vi.fn(() => Promise.resolve({ results: { success: true, }, })), })), }; }); const validateCreateServerViteCall = (options) => { expect(vite_1.createServer).toHaveBeenCalledWith({ configFile: options.viteConfig, server: { open: options.open, host: options.host, port: options.port, https: options.https, cors: options.cors, strictPort: options.strictPort, base: options.base, }, optimizeDeps: { force: options.force, }, logLevel: options.logLevel, clearScreen: options.clearScreen, mode: options.mode, }); }; const options = { viteConfig: 'proj/vite.config.js', }; describe('Build Executor', () => { it('should send appropriate options to vite', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when host is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', host: 'localhost', }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when port is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', port: 3000, }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when https is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', https: true, }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when open is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', open: 'path', }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when cors is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', cors: true, }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when strictPort is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', strictPort: true, }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when reporter is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', force: true, }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when base is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', base: 'base', }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); it('should send appropriate options when logLevel is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = { viteConfig: 'proj/vite.config.js', logLevel: 'info', }; yield (0, executor_1.default)(options).next(); validateCreateServerViteCall(options); })); // it('should send appropriate options when clearScreen is specified', async () => { // const options: ViteExecutorSchema = { // viteConfig: 'proj/vite.config.js', // clearScreen: true, // }; // await executor(options).next(); // validateCreateServerViteCall(options); // }); // it('should send appropriate options when mode is specified', async () => { // const options: ViteExecutorSchema = { // viteConfig: 'proj/vite.config.js', // mode: 'custom-mode', // }; // await executor(options).next(); // validateCreateServerViteCall(options); // }); }); //# sourceMappingURL=executor.spec.js.map