@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.
196 lines • 8.18 kB
JavaScript
;
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 {
build: vitest_1.vi.fn(() => Promise.resolve({
results: {
success: true,
},
})),
};
});
const validateBuildViteCall = (options) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
expect(vite_1.build).toHaveBeenCalledWith({
configFile: options.viteConfig,
server: {
base: options.base,
},
build: {
target: (_a = options.target) !== null && _a !== void 0 ? _a : 'modules',
outDir: (_b = options.outDir) !== null && _b !== void 0 ? _b : 'dist/temp-vite',
assetsDir: (_c = options.assetsDir) !== null && _c !== void 0 ? _c : 'assets',
assetsInlineLimit: (_d = options.assetsInlineLimit) !== null && _d !== void 0 ? _d : 4096,
ssr: options.ssr,
sourcemap: (_e = options.sourcemap) !== null && _e !== void 0 ? _e : false,
minify: (_f = options.minify) !== null && _f !== void 0 ? _f : 'esbuild',
manifest: (_g = options.manifest) !== null && _g !== void 0 ? _g : false,
ssrManifest: (_h = options.ssrManifest) !== null && _h !== void 0 ? _h : false,
},
optimizeDeps: {
force: options.force,
},
logLevel: (_j = options.logLevel) !== null && _j !== void 0 ? _j : 'info',
clearScreen: (_k = options.clearScreen) !== null && _k !== void 0 ? _k : true,
mode: (_l = options.mode) !== null && _l !== void 0 ? _l : 'production',
});
};
const options = {
viteConfig: 'proj/vite.config.js',
};
describe('Build Executor', () => {
let mockContext;
beforeEach(() => {
mockContext = {
root: '/root',
projectName: 'proj',
workspace: {
version: 2,
projects: {
proj: {
root: 'proj',
targets: {
build: {
executor: '@nx-plugins/vite:build',
},
},
},
},
},
target: {
executor: '@nx-plugins/vite:build',
},
cwd: '/root',
isVerbose: true,
};
});
it('should send appropriate options to vite', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when target is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
target: 'modules',
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when outDir is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
outDir: '/out',
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when assetsDir is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
assetsDir: '/assets',
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when assetsInlineLimit is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
assetsInlineLimit: 3000,
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when ssr is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
ssr: true,
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when sourcemap is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
sourcemap: true,
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when minify is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
minify: 'esbuild',
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when manifest is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
manifest: 'manifest.json',
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when ssrManifest is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
ssrManifest: 'ssrManifest.json',
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
it('should send appropriate options when force 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);
validateBuildViteCall(options);
}));
it('should send appropriate options when emptyOutputDir is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
emptyOutputDir: true,
};
yield (0, executor_1.default)(options);
validateBuildViteCall(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);
validateBuildViteCall(options);
}));
it('should send appropriate options when clearScreen is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
clearScreen: true,
};
yield (0, executor_1.default)(options);
validateBuildViteCall(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);
validateBuildViteCall(options);
}));
it('should send appropriate options when mode is specified', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const options = {
viteConfig: 'proj/vite.config.js',
mode: 'dev',
};
yield (0, executor_1.default)(options);
validateBuildViteCall(options);
}));
});
//# sourceMappingURL=executor.spec.js.map