UNPKG

@nx/remix

Version:

The Remix plugin for Nx contains executors and generators for managing Remix applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Vitest, Jest, Playwright, Cypress, and Storybook. - Generators for applica

64 lines (63 loc) 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nxComponentTestingPreset = nxComponentTestingPreset; const cypress_preset_1 = require("@nx/cypress/plugins/cypress-preset"); const devkit_1 = require("@nx/devkit"); const fs_1 = require("fs"); const path_1 = require("path"); /** * Remix nx preset for Cypress Component Testing * * This preset contains the base configuration * for your component tests that nx recommends. * including a devServer that supports nx workspaces. * you can easily extend this within your cypress config via spreading the preset * @example * export default defineConfig({ * component: { * ...nxComponentTestingPreset(__dirname) * // add your own config here * } * }) * * @param pathToConfig will be used for loading project options and to construct the output paths for videos and screenshots */ function nxComponentTestingPreset(pathToConfig) { const normalizedProjectRootPath = ['.ts', '.js'].some((ext) => pathToConfig.endsWith(ext)) ? pathToConfig : (0, path_1.dirname)(pathToConfig); return { ...(0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig), specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}', devServer: { ...{ framework: 'react', bundler: 'vite' }, viteConfig: async () => { const viteConfigPath = findViteConfig(normalizedProjectRootPath); const { mergeConfig, loadConfigFromFile, searchForWorkspaceRoot } = await Promise.resolve().then(() => require('vite')); const resolved = await loadConfigFromFile({ mode: 'watch', command: 'serve', }, viteConfigPath); return mergeConfig(resolved.config, { server: { fs: { allow: [ searchForWorkspaceRoot(normalizedProjectRootPath), devkit_1.workspaceRoot, (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'node_modules/vite'), ], }, }, }); }, }, }; } function findViteConfig(projectRootFullPath) { const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts']; for (const ext of allowsExt) { if ((0, fs_1.existsSync)((0, path_1.join)(projectRootFullPath, `vite.config.${ext}`))) { return (0, path_1.join)(projectRootFullPath, `vite.config.${ext}`); } } }