@cypress/vite-dev-server 2.2.3 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,64 +1,65 @@
1
1
  # @cypress/vite-dev-server
2
2
 
3
- > ⚡️ + 🌲 Cypress Component Testing w/ Vite
3
+ Implements the APIs for the object-syntax of the Cypress Component-testing "vite dev server".
4
4
 
5
- To install vite in you component testing environment,
6
- 1. Install it `yarn add @cypress/vite-dev-server`
7
- 2. Add it to `cypress/plugins/index.js`
5
+ > **Note:** This package is bundled with the Cypress binary and should not need to be installed separately. See the [Component Framework Configuration Docs](https://docs.cypress.io/guides/component-testing/component-framework-configuration) for setting up component testing with vite. The `devServer` function signature is for advanced use-cases.
8
6
 
9
- ```js
10
- import { startDevServer } from '@cypress/vite-dev-server'
7
+ Object syntax:
11
8
 
12
- module.exports = (on, config) => {
13
- on('dev-server:start', async (options) => startDevServer({ options }))
9
+ ```ts
10
+ import { defineConfig } from 'cypress'
14
11
 
15
- return config
16
- }
12
+ export default defineConfig({
13
+ component: {
14
+ devServer: {
15
+ framework: 'create-react-app',
16
+ bundler: 'vite',
17
+ // viteConfig?: Will try to infer, if passed it will be used as is
18
+ }
19
+ }
20
+ })
17
21
  ```
18
22
 
19
- # @cypress/webpack-dev-server
20
-
21
- > **Note** this package is not meant to be used outside of cypress component testing.
22
-
23
- Install `@cypress/vue` or `@cypress/react` to get this package working properly
23
+ Function syntax:
24
+
25
+ ```ts
26
+ import { devServer } from '@cypress/vite-dev-server'
27
+ import { defineConfig } from 'cypress'
28
+
29
+ export default defineConfig({
30
+ component: {
31
+ devServer(devServerConfig) {
32
+ return devServer({
33
+ ...devServerConfig,
34
+ framework: 'react',
35
+ viteConfig: require('./vite.config.js')
36
+ })
37
+ }
38
+ }
39
+ })
40
+ ```
24
41
 
25
42
  ## Architecture
26
43
 
27
- ### Cypress server
44
+ There should be a single publicly-exported entrypoint for the module, `devServer`, all other types and functions should be considered internal/implementation details, and types stripped from the output.
45
+
46
+ The `devServer` will first source the modules from the user's project, falling back to our own bundled versions of libraries. This ensures that the user has installed the current modules, and throws an error if the user does not have the library installed.
28
47
 
29
- - Every HTTP request goes to the cypress server which returns an html page. We call "TOP" because of its name in the dev tools
30
- This page
31
- - renders the list of spec files
32
- - And the timetraveling command log
33
- - Finally, it renders an AUT Iframe. this iframe calls a url that has 2 parts concatenated.
34
- - a prefix: `__cypress/iframes/`
35
- - the path to the current. For example: `src/components/button.spec.tsx`
36
- - In the cypress server, calls prefixed with `__cypress/iframes/...` will be passed to the dev-server as `__cypress/src/index.html`
37
- - Every call with the prefix `__cypress/src/` will be passed to the dev-server to deal as is, without changes.
48
+ From there, we check the "framework" field to source or define any known vite transforms to aid in the compilation.
38
49
 
39
- ### Dev-server
50
+ We then merge the sourced config with the user's vite config, and layer on our own transforms, and provide this to a vite instance. The vite instance used to create a vite-dev-server, which is returned.
40
51
 
41
- - Responds to every query with the prefix `__cypress/src/` (base path should be this prefix).
42
- - Responds to `__cypress/src/index.html` with an html page.
43
- This page
44
- - will contain an element `<div id="__cy_root"></div>`. Tis will be used by mount function to mount the app containing the components we want.
45
- - will load support files
46
- - will load the current spec from the url
47
- - will start the test when both files are done loading
48
- - The server re-runs the tests as soon as the current spec or any dependency is updated by calling an event `devServerEvents.emit('dev-server:compile:success')`
52
+ ## Compatibility
49
53
 
50
- ## Vite dev server
54
+ | @cypress/vite-dev-server | cypress |
55
+ | ------------------------ | ------- |
56
+ | <= v2 | <= v9 |
57
+ | >= v3 | >= v10 |
51
58
 
52
- - Takes the users `vite.config` and adds base of `__cypress/src/` and a cypress vite plugin.
53
- - The cypress plugin takes care of
54
- - responding to the index.html query with an html page
55
- - restarting the tests when files are changed
56
- - The HTML page calls a script that loads support file and the specs using a native `import()` function
57
- - Then triggers the loaded tests
59
+ ## License
58
60
 
59
- Vite is responsible for compiling and bundling all the files. We use its error overlay to display any transpiling error.
60
- Only runtime errors have to be handled through cypress
61
+ [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/master/LICENSE)
61
62
 
62
- ## Changelog
63
+ This project is licensed under the terms of the [MIT license](/LICENSE).
63
64
 
64
- [Changelog](./CHANGELOG.md)
65
+ ## [Changelog](./CHANGELOG.md)
@@ -1,18 +1,35 @@
1
1
  // This file is merged in a <script type=module> into index.html
2
2
  // it will be used to load and kick start the selected spec
3
- import specLoaders from 'cypress:spec-loaders'
4
- import { hasSupportPath, originAutUrl } from 'cypress:config'
5
3
 
6
- const specPath = window.location.pathname.replace(originAutUrl, '')
4
+ const CypressInstance = window.Cypress = parent.Cypress
5
+
6
+ const importsToLoad = []
7
+
8
+ /* Support file import logic, this should be removed once we
9
+ * are able to return relative paths from the supportFile
10
+ * Jira #UNIFY-1260
11
+ */
12
+ const supportFile = CypressInstance.config('supportFile')
13
+ const projectRoot = CypressInstance.config('projectRoot')
14
+ const devServerPublicPathRoute = CypressInstance.config('devServerPublicPathRoute')
15
+
16
+ if (supportFile) {
17
+ let supportRelativeToProjectRoot = supportFile.replace(projectRoot, '')
7
18
 
8
- const specLoader = specLoaders[specPath]
9
- const importsToLoad = [specLoader || (() => import(/* @vite-ignore */ specPath))]
19
+ if (CypressInstance.config('platform') === 'win32') {
20
+ const platformProjectRoot = projectRoot.replaceAll('/', '\\')
10
21
 
11
- if (hasSupportPath) {
12
- importsToLoad.unshift(() => import('cypress:support-path'))
22
+ supportRelativeToProjectRoot = supportFile.replace(platformProjectRoot, '')
23
+ }
24
+
25
+ // We need a slash before /cypress/supportFile.js, this happens by default
26
+ // with the current string replacement logic.
27
+ importsToLoad.push(() => import(`${devServerPublicPathRoute}${supportRelativeToProjectRoot}`))
13
28
  }
14
29
 
15
- const CypressInstance = window.Cypress = parent.Cypress
30
+ /* Spec file import logic */
31
+ // We need a slash before /src/my-spec.js, this does not happen by default.
32
+ importsToLoad.push(() => import(`${devServerPublicPathRoute}/${CypressInstance.spec.relative}`))
16
33
 
17
34
  if (!CypressInstance) {
18
35
  throw new Error('Tests cannot run without a reference to Cypress!')
@@ -0,0 +1 @@
1
+ export declare const configFiles: string[];
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configFiles = void 0;
4
+ exports.configFiles = [
5
+ 'vite.config.ts',
6
+ 'vite.config.js',
7
+ 'vite.config.mjs',
8
+ 'vite.config.cjs',
9
+ 'vite.config.mts',
10
+ 'vite.config.cts',
11
+ ];
@@ -0,0 +1,17 @@
1
+ /// <reference types="cypress" />
2
+ /// <reference types="node" />
3
+ declare const ALL_FRAMEWORKS: readonly ["react", "vue"];
4
+ export declare type ViteDevServerConfig = {
5
+ specs: Cypress.Spec[];
6
+ cypressConfig: Cypress.PluginConfigOptions;
7
+ devServerEvents: NodeJS.EventEmitter;
8
+ onConfigNotFound?: (devServer: 'vite', cwd: string, lookedIn: string[]) => void;
9
+ } & {
10
+ framework?: typeof ALL_FRAMEWORKS[number];
11
+ viteConfig?: unknown;
12
+ };
13
+ export declare function devServer(config: ViteDevServerConfig): Promise<Cypress.ResolvedDevServerConfig>;
14
+ export declare namespace devServer {
15
+ var create: (devServerConfig: ViteDevServerConfig, vite: typeof import("vite")) => Promise<import("vite").ViteDevServer>;
16
+ }
17
+ export {};
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.devServer = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
+ const getVite_1 = require("./getVite");
7
+ const resolveConfig_1 = require("./resolveConfig");
8
+ const debug = (0, debug_1.default)('cypress:vite-dev-server:devServer');
9
+ const ALL_FRAMEWORKS = ['react', 'vue'];
10
+ async function devServer(config) {
11
+ // This has to be the first thing we do as we need to source vite from their project's dependencies
12
+ const vite = (0, getVite_1.getVite)(config);
13
+ debug('Creating Vite Server');
14
+ const server = await devServer.create(config, vite);
15
+ debug('Vite server created');
16
+ await server.listen();
17
+ const { port } = server.config.server;
18
+ if (!port) {
19
+ throw new Error('Missing vite dev server port.');
20
+ }
21
+ debug('Successfully launched the vite server on port', port);
22
+ return {
23
+ port,
24
+ // Close is for unit testing only. We kill this child process which will handle the closing of the server
25
+ close(cb) {
26
+ return server.close().then(() => cb === null || cb === void 0 ? void 0 : cb()).catch(cb);
27
+ },
28
+ };
29
+ }
30
+ exports.devServer = devServer;
31
+ devServer.create = async function createDevServer(devServerConfig, vite) {
32
+ try {
33
+ const config = await (0, resolveConfig_1.createViteDevServerConfig)(devServerConfig, vite);
34
+ return await vite.createServer(config);
35
+ }
36
+ catch (err) {
37
+ if (err instanceof Error) {
38
+ throw err;
39
+ }
40
+ throw new Error(err);
41
+ }
42
+ };
@@ -0,0 +1,3 @@
1
+ import type { ViteDevServerConfig } from './devServer';
2
+ export declare type Vite = typeof import('vite');
3
+ export declare function getVite(config: ViteDevServerConfig): Vite;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVite = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
+ const debug = (0, debug_1.default)('cypress:vite-dev-server:getVite');
7
+ // "vite-dev-server" is bundled in the binary, so we need to require.resolve "vite"
8
+ // from root of the active project since we don't bundle vite internally but rather
9
+ // use the version the user has installed
10
+ function getVite(config) {
11
+ try {
12
+ const viteImportPath = require.resolve('vite', { paths: [config.cypressConfig.projectRoot] });
13
+ debug('resolved viteImportPath as %s', viteImportPath);
14
+ return require(viteImportPath);
15
+ }
16
+ catch (err) {
17
+ throw new Error(`Could not find "vite" in your project's dependencies. Please install "vite" to fix this error.\n\n${err}`);
18
+ }
19
+ }
20
+ exports.getVite = getVite;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- /// <reference types="cypress" />
2
- import { InlineConfig } from 'vite';
3
- import { StartDevServerOptions } from './resolveServerConfig';
4
- export { StartDevServerOptions };
5
- export declare function startDevServer(startDevServerArgs: StartDevServerOptions): Promise<Cypress.ResolvedDevServerConfig>;
6
- export declare type CypressViteDevServerConfig = Omit<InlineConfig, 'base' | 'root'>;
7
- export declare function devServer(cypressDevServerConfig: Cypress.DevServerConfig, devServerConfig?: CypressViteDevServerConfig): Promise<Cypress.ResolvedDevServerConfig>;
8
- export declare function defineDevServerConfig(devServerConfig: CypressViteDevServerConfig): CypressViteDevServerConfig;
1
+ import { devServer } from './devServer';
2
+ export { devServer };
3
+ export default devServer;
package/dist/index.js CHANGED
@@ -1,29 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineDevServerConfig = exports.devServer = exports.startDevServer = void 0;
4
- const debug_1 = require("debug");
5
- const vite_1 = require("vite");
6
- const resolveServerConfig_1 = require("./resolveServerConfig");
7
- const debug = (0, debug_1.debug)('cypress:vite-dev-server:vite');
8
- async function startDevServer(startDevServerArgs) {
9
- if (!startDevServerArgs.viteConfig) {
10
- debug('User did not pass in any Vite dev server configuration');
11
- startDevServerArgs.viteConfig = {};
12
- }
13
- debug('starting vite dev server');
14
- const resolvedConfig = await (0, resolveServerConfig_1.resolveServerConfig)(startDevServerArgs);
15
- const port = resolvedConfig.server.port;
16
- const viteDevServer = await (0, vite_1.createServer)(resolvedConfig);
17
- await viteDevServer.listen();
18
- debug('Component testing vite server started on port', port);
19
- return { port, close: viteDevServer.close };
20
- }
21
- exports.startDevServer = startDevServer;
22
- function devServer(cypressDevServerConfig, devServerConfig) {
23
- return startDevServer({ options: cypressDevServerConfig, viteConfig: devServerConfig });
24
- }
25
- exports.devServer = devServer;
26
- function defineDevServerConfig(devServerConfig) {
27
- return devServerConfig;
28
- }
29
- exports.defineDevServerConfig = defineDevServerConfig;
3
+ exports.devServer = void 0;
4
+ const devServer_1 = require("./devServer");
5
+ Object.defineProperty(exports, "devServer", { enumerable: true, get: function () { return devServer_1.devServer; } });
6
+ exports.default = devServer_1.devServer;
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { Vite } from '../getVite';
3
+ import type { ViteDevServerConfig } from '../devServer';
4
+ export declare const Cypress: (options: ViteDevServerConfig, vite: Vite) => Plugin;
@@ -1,80 +1,86 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.makeCypressPlugin = void 0;
7
- const path_1 = require("path");
8
- const promises_1 = require("fs/promises");
9
- const debug_1 = __importDefault(require("debug"));
10
- const vite_1 = require("vite");
11
- const debug = (0, debug_1.default)('cypress:vite-dev-server:plugin');
12
- const pluginName = 'cypress-transform-html';
13
- const OSSepRE = new RegExp(`\\${path_1.sep}`, 'g');
14
- function convertPathToPosix(path) {
15
- return path_1.sep === '/'
16
- ? path
17
- : path.replace(OSSepRE, '/');
18
- }
19
- const INIT_FILEPATH = (0, path_1.resolve)(__dirname, '../client/initCypressTests.js');
3
+ exports.Cypress = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
+ const pathe_1 = require("pathe");
7
+ const node_html_parser_1 = require("node-html-parser");
8
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
9
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
10
+ const debug = (0, debug_1.default)('cypress:vite-dev-server:plugins:cypress');
11
+ const INIT_FILEPATH = (0, pathe_1.resolve)(__dirname, '../../client/initCypressTests.js');
20
12
  const HMR_DEPENDENCY_LOOKUP_MAX_ITERATION = 50;
21
13
  function getSpecsPathsSet(specs) {
22
14
  return new Set(specs.map((spec) => spec.absolute));
23
15
  }
24
- const makeCypressPlugin = (projectRoot, supportFilePath, devServerEvents, specs) => {
16
+ const Cypress = (options, vite) => {
25
17
  let base = '/';
18
+ const projectRoot = options.cypressConfig.projectRoot;
19
+ const supportFilePath = options.cypressConfig.supportFile ? path_1.default.resolve(projectRoot, options.cypressConfig.supportFile) : false;
20
+ const devServerEvents = options.devServerEvents;
21
+ const specs = options.specs;
22
+ const indexHtmlFile = options.cypressConfig.indexHtmlFile;
26
23
  let specsPathsSet = getSpecsPathsSet(specs);
24
+ // TODO: use async fs methods here
25
+ // eslint-disable-next-line no-restricted-syntax
26
+ let loader = fs_1.default.readFileSync(INIT_FILEPATH, 'utf8');
27
27
  devServerEvents.on('dev-server:specs:changed', (specs) => {
28
28
  specsPathsSet = getSpecsPathsSet(specs);
29
29
  });
30
- const posixSupportFilePath = supportFilePath ? convertPathToPosix((0, path_1.resolve)(projectRoot, supportFilePath)) : undefined;
31
30
  return {
32
- name: pluginName,
31
+ name: 'cypress:main',
33
32
  enforce: 'pre',
34
33
  configResolved(config) {
35
34
  base = config.base;
36
35
  },
37
- async transformIndexHtml() {
38
- const indexHtmlPath = (0, path_1.resolve)(__dirname, '..', 'index.html');
39
- const indexHtmlContent = await (0, promises_1.readFile)(indexHtmlPath, { encoding: 'utf8' });
36
+ async transformIndexHtml(html) {
37
+ // it's possibe other plugins have modified the HTML
38
+ // before we get to. For example vitejs/plugin-react will
39
+ // add a preamble. We do our best to look at the HTML we
40
+ // receive and inject it.
41
+ // For now we just grab any `<script>` tags and inject them to <head>.
42
+ // We will add more handling as we learn the use cases.
43
+ const root = (0, node_html_parser_1.parse)(html);
44
+ const scriptTagsToInject = root.childNodes.filter((node) => {
45
+ return node instanceof node_html_parser_1.HTMLElement && node.rawTagName === 'script';
46
+ });
47
+ const indexHtmlPath = (0, pathe_1.resolve)(projectRoot, indexHtmlFile);
48
+ debug('resolved the indexHtmlPath as', indexHtmlPath, 'from', indexHtmlFile);
49
+ let indexHtmlContent = await fs_1.default.promises.readFile(indexHtmlPath, { encoding: 'utf8' });
50
+ // Inject the script tags
51
+ indexHtmlContent = indexHtmlContent.replace('<head>', `<head>
52
+ ${scriptTagsToInject.join('')}
53
+ `);
40
54
  // find </body> last index
41
55
  const endOfBody = indexHtmlContent.lastIndexOf('</body>');
42
56
  // insert the script in the end of the body
43
- return `${indexHtmlContent.substring(0, endOfBody)}<script src="${base}cypress:client-init-test" type="module"></script>${indexHtmlContent.substring(endOfBody)}`;
44
- },
45
- resolveId(id) {
46
- if (id === 'cypress:config') {
47
- return id;
48
- }
49
- if (id === 'cypress:support-path') {
50
- return posixSupportFilePath;
51
- }
52
- if (id === 'cypress:spec-loaders') {
53
- return id;
54
- }
55
- if (id === '/cypress:client-init-test') {
56
- return INIT_FILEPATH;
57
- }
58
- },
59
- load(id) {
60
- if (id === 'cypress:spec-loaders') {
61
- return `export default {\n${specs.map((s) => {
62
- return `${JSON.stringify(encodeURI(s.relative))}:()=>import(${JSON.stringify(s.absolute)})`;
63
- }).join(',\n')}\n}`;
64
- }
65
- if (id === 'cypress:config') {
66
- return `
67
- export const hasSupportPath = ${JSON.stringify(!!supportFilePath)}
68
- export const originAutUrl = ${JSON.stringify(`/__cypress/iframes/${(0, vite_1.normalizePath)(projectRoot)}/`)}`;
69
- }
57
+ const newHtml = `
58
+ ${indexHtmlContent.substring(0, endOfBody)}
59
+ <script>${loader}</script>
60
+ ${indexHtmlContent.substring(endOfBody)}
61
+ `;
62
+ return newHtml;
70
63
  },
71
64
  configureServer: async (server) => {
72
- const indexHtml = await (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '..', 'index.html'), { encoding: 'utf8' });
73
- const transformedIndexHtml = await server.transformIndexHtml(base, indexHtml);
74
- server.middlewares.use(`${base}index.html`, (req, res) => res.end(transformedIndexHtml));
65
+ server.middlewares.use(`${base}index.html`, async (req, res) => {
66
+ let transformedIndexHtml = await server.transformIndexHtml(base, '');
67
+ const viteImport = `<script type="module" src="${options.cypressConfig.devServerPublicPathRoute}/@vite/client"></script>`;
68
+ // If we're doing cy-in-cy, we need to be able to access the Cypress instance from the parent frame.
69
+ if (process.env.CYPRESS_INTERNAL_VITE_OPEN_MODE_TESTING) {
70
+ transformedIndexHtml = transformedIndexHtml.replace(viteImport, `<script>document.domain = 'localhost';</script>${viteImport}`);
71
+ }
72
+ return res.end(transformedIndexHtml);
73
+ });
75
74
  },
76
75
  handleHotUpdate: ({ server, file }) => {
77
76
  debug('handleHotUpdate - file', file);
77
+ // If the user provided IndexHtml is changed, do a full-reload
78
+ if (vite.normalizePath(file) === (0, pathe_1.resolve)(projectRoot, indexHtmlFile)) {
79
+ server.ws.send({
80
+ type: 'full-reload',
81
+ });
82
+ return;
83
+ }
78
84
  // get the graph node for the file that just got updated
79
85
  let moduleImporters = server.moduleGraph.fileToModulesMap.get(file);
80
86
  let iterationNumber = 0;
@@ -92,7 +98,7 @@ export const originAutUrl = ${JSON.stringify(`/__cypress/iframes/${(0, vite_1.no
92
98
  debug('handleHotUpdate - support compile success');
93
99
  devServerEvents.emit('dev-server:compile:success');
94
100
  // if we update support we know we have to re-run it all
95
- // no need to ckeck further
101
+ // no need to check further
96
102
  return [];
97
103
  }
98
104
  if (mod.file && specsPathsSet.has(mod.file)) {
@@ -111,7 +117,7 @@ export const originAutUrl = ${JSON.stringify(`/__cypress/iframes/${(0, vite_1.no
111
117
  },
112
118
  };
113
119
  };
114
- exports.makeCypressPlugin = makeCypressPlugin;
120
+ exports.Cypress = Cypress;
115
121
  /**
116
122
  * Gets all the modules that import the set of modules passed in parameters
117
123
  * @param modules the set of module whose dependents to return
@@ -0,0 +1,2 @@
1
+ export * from './inspect';
2
+ export * from './cypress';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./inspect"), exports);
5
+ (0, tslib_1.__exportStar)(require("./cypress"), exports);
@@ -0,0 +1,3 @@
1
+ import type { PluginOption } from 'vite';
2
+ import type { ViteDevServerConfig } from '../devServer';
3
+ export declare const CypressInspect: (config: ViteDevServerConfig) => PluginOption | null;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CypressInspect = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
+ const debug = (0, debug_1.default)('cypress:vite-dev-server:plugins:inspect');
7
+ const CypressInspect = (config) => {
8
+ var _a;
9
+ if (!process.env.CYPRESS_INTERNAL_VITE_INSPECT) {
10
+ debug('skipping vite inspect because CYPRESS_INTERNAL_VITE_INSPECT is not set');
11
+ return null;
12
+ }
13
+ let Inspect;
14
+ try {
15
+ const inspectPluginPath = require.resolve('vite-plugin-inspect', { paths: [config.cypressConfig.projectRoot] });
16
+ const inspectModule = require(inspectPluginPath);
17
+ Inspect = (_a = inspectModule.default) !== null && _a !== void 0 ? _a : inspectModule;
18
+ debug('inspect was found', Inspect);
19
+ }
20
+ catch (err) {
21
+ debug(`Tried to import the inspect plugin 'vite-plugin-inspect'. It's an optional peerDependency so install it if you'd like.`);
22
+ debug(err);
23
+ return null;
24
+ }
25
+ return Object.assign(Object.assign({}, Inspect()), { name: 'cypress:inspect' });
26
+ };
27
+ exports.CypressInspect = CypressInspect;
@@ -0,0 +1,3 @@
1
+ import type { ViteDevServerConfig } from './devServer';
2
+ import type { Vite } from './getVite';
3
+ export declare const createViteDevServerConfig: (config: ViteDevServerConfig, vite: Vite) => Promise<Record<string, any>>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createViteDevServerConfig = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /**
6
+ * The logic inside of this file is heavily reused from
7
+ * Vitest's own config resolution logic.
8
+ * You can find it here https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/create.ts
9
+ */
10
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
11
+ const local_pkg_1 = require("local-pkg");
12
+ const pathe_1 = require("pathe");
13
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
+ const constants_1 = require("./constants");
15
+ const index_1 = require("./plugins/index");
16
+ const debug = (0, debug_1.default)('cypress:vite-dev-server:resolve-config');
17
+ const createViteDevServerConfig = async (config, vite) => {
18
+ const { specs, cypressConfig, viteConfig: viteOverrides } = config;
19
+ const root = cypressConfig.projectRoot;
20
+ const { default: findUp } = await (0, local_pkg_1.importModule)('find-up');
21
+ const configFile = await findUp(constants_1.configFiles, { cwd: root });
22
+ // INFO logging, a lot is logged here.
23
+ // debug('all dev-server options are', options)
24
+ if (configFile) {
25
+ debug('resolved config file at', configFile, 'using root', root);
26
+ }
27
+ else if (viteOverrides) {
28
+ debug(`Couldn't find a Vite config file, however we received a custom viteConfig`, viteOverrides);
29
+ }
30
+ else {
31
+ if (config.onConfigNotFound) {
32
+ config.onConfigNotFound('vite', root, constants_1.configFiles);
33
+ // The config process will be killed from the parent, but we want to early exit so we don't get
34
+ // any additional errors related to not having a config
35
+ process.exit(0);
36
+ }
37
+ else {
38
+ throw new Error(`Your component devServer config for vite is missing a required viteConfig property, since we could not automatically detect one.\n Please add one to your ${config.cypressConfig.configFile}`);
39
+ }
40
+ }
41
+ // Vite caches its output in the .vite directory in the node_modules where vite lives.
42
+ // So we want to find that node_modules path and ensure it's added to the "allow" list
43
+ const vitePathNodeModules = path_1.default.dirname(path_1.default.dirname(require.resolve(`vite/package.json`, {
44
+ paths: [root],
45
+ })));
46
+ const viteBaseConfig = {
47
+ root,
48
+ base: `${cypressConfig.devServerPublicPathRoute}/`,
49
+ configFile,
50
+ optimizeDeps: {
51
+ esbuildOptions: {
52
+ incremental: true,
53
+ plugins: [
54
+ {
55
+ name: 'cypress-esbuild-plugin',
56
+ setup(build) {
57
+ build.onEnd(function (result) {
58
+ // We don't want to completely fail the build here on errors so we treat the errors as warnings
59
+ // which will handle things more gracefully. Vite will 500 on files that have errors when they
60
+ // are requested later and Cypress will display an error message.
61
+ // See: https://github.com/cypress-io/cypress/pull/21599
62
+ result.warnings = [...result.warnings, ...result.errors];
63
+ result.errors = [];
64
+ });
65
+ },
66
+ },
67
+ ],
68
+ },
69
+ entries: [
70
+ ...specs.map((s) => (0, pathe_1.relative)(root, s.relative)),
71
+ ...(cypressConfig.supportFile ? [(0, pathe_1.resolve)(root, cypressConfig.supportFile)] : []),
72
+ ].filter((v) => v != null),
73
+ },
74
+ server: {
75
+ fs: {
76
+ allow: [
77
+ root,
78
+ vitePathNodeModules,
79
+ cypressConfig.cypressBinaryRoot,
80
+ ],
81
+ },
82
+ host: '127.0.0.1',
83
+ },
84
+ plugins: [
85
+ (0, index_1.Cypress)(config, vite),
86
+ (0, index_1.CypressInspect)(config),
87
+ ].filter((p) => p != null),
88
+ };
89
+ const finalConfig = vite.mergeConfig(viteBaseConfig, viteOverrides);
90
+ debug('The resolved server config is', JSON.stringify(finalConfig, null, 2));
91
+ return finalConfig;
92
+ };
93
+ exports.createViteDevServerConfig = createViteDevServerConfig;
package/package.json CHANGED
@@ -1,36 +1,34 @@
1
1
  {
2
2
  "name": "@cypress/vite-dev-server",
3
- "version": "2.2.3",
3
+ "version": "3.1.1",
4
4
  "description": "Launches Vite Dev Server for Component Testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "build": "tsc",
8
- "build-prod": "tsc",
9
- "cy:open": "node ../../scripts/cypress.js open-ct --project ${PWD}",
10
- "cy:run": "node ../../scripts/cypress.js run-ct --project ${PWD}",
11
- "cy:run-signature": "yarn cy:run --config=\"{\\\"pluginsFile\\\":\\\"cypress/new-signature/plugins.js\\\"}\"",
12
- "test": "yarn cy:run && yarn cy:run-signature",
13
- "watch": "tsc -w"
7
+ "build": "tsc || echo 'built, with type errors'",
8
+ "build-prod": "tsc || echo 'built, with type errors'",
9
+ "check-ts": "tsc --noEmit",
10
+ "cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
11
+ "cypress:run-cypress-in-cypress": "cross-env HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
12
+ "cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
13
+ "watch": "tsc -w",
14
+ "test": "yarn test-unit",
15
+ "test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js"
14
16
  },
15
17
  "dependencies": {
16
- "debug": "^4.3.2",
17
- "get-port": "^5.1.1"
18
+ "debug": "4.3.3",
19
+ "find-up": "6.3.0",
20
+ "local-pkg": "0.4.1",
21
+ "node-html-parser": "5.3.3",
22
+ "pathe": "0.2.0"
18
23
  },
19
24
  "devDependencies": {
20
- "@cypress/react": "0.0.0-development",
21
- "@cypress/vue": "0.0.0-development",
22
- "@testing-library/cypress": "7.0.4",
23
- "@vitejs/plugin-vue": "1.2.0",
24
- "@vue/compiler-sfc": "3.0.9",
25
- "cypress": "0.0.0-development",
26
- "mocha-junit-reporter": "^2.0.0",
27
- "mocha-multi-reporters": "^1.5.1",
28
- "react": "17.0.2",
29
- "vite": "2.2.3",
30
- "vue": "3.0.11"
31
- },
32
- "peerDependencies": {
33
- "vite": ">= 2.1.3"
25
+ "chai": "^4.3.6",
26
+ "dedent": "^0.7.0",
27
+ "mocha": "^9.2.2",
28
+ "sinon": "^13.0.1",
29
+ "ts-node": "^10.2.1",
30
+ "vite": "3.0.3",
31
+ "vite-plugin-inspect": "0.4.3"
34
32
  },
35
33
  "files": [
36
34
  "dist",
package/CHANGELOG.md DELETED
@@ -1,296 +0,0 @@
1
- # [@cypress/vite-dev-server-v2.2.3](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.2.2...@cypress/vite-dev-server-v2.2.3) (2022-05-10)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * handle specs with white space in vite-dev-server ([#21386](https://github.com/cypress-io/cypress/issues/21386)) ([f1c3a9b](https://github.com/cypress-io/cypress/commit/f1c3a9b3186057dd63645fd9e617f343db5c473b))
7
-
8
- # [@cypress/vite-dev-server-v2.2.2](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.2.1...@cypress/vite-dev-server-v2.2.2) (2021-12-16)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * check the port is avail on all local hosts ([#19402](https://github.com/cypress-io/cypress/issues/19402)) ([4826175](https://github.com/cypress-io/cypress/commit/4826175040bfc024a36df47dc0c74f2871fa944f))
14
-
15
- # [@cypress/vite-dev-server-v2.2.1](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.2.0...@cypress/vite-dev-server-v2.2.1) (2021-11-19)
16
-
17
-
18
- ### Bug Fixes
19
-
20
- * compile npm packages for node 12 ([#18989](https://github.com/cypress-io/cypress/issues/18989)) ([30b3eb2](https://github.com/cypress-io/cypress/commit/30b3eb2376bc1ed69087ba96f60448687e8489e6))
21
-
22
- # [@cypress/vite-dev-server-v2.2.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.1.1...@cypress/vite-dev-server-v2.2.0) (2021-10-15)
23
-
24
-
25
- ### Features
26
-
27
- * normalized signatures webpack & vite servers ([#18379](https://github.com/cypress-io/cypress/issues/18379)) ([8f5308f](https://github.com/cypress-io/cypress/commit/8f5308f7068b80fb877da539ce34fb67ba497c4f))
28
-
29
- # [@cypress/vite-dev-server-v2.1.1](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.1.0...@cypress/vite-dev-server-v2.1.1) (2021-10-04)
30
-
31
-
32
- ### Bug Fixes
33
-
34
- * **vite-dev-server:** remove base and root from inlineVitConfig types ([#17180](https://github.com/cypress-io/cypress/issues/17180)) ([07e7d0e](https://github.com/cypress-io/cypress/commit/07e7d0ed252bf1a2bd3224f617e1fc2e64f19a06))
35
- * **vite-dev-server:** replace UserConfig with InlineConfig to allow correct `configFile` types ([#18167](https://github.com/cypress-io/cypress/issues/18167)) ([6e0c2c1](https://github.com/cypress-io/cypress/commit/6e0c2c1af81be750a74bad0528d52de45746a453))
36
- * **vite-dev-server:** windows `supportFile` + preserve optimize entries ([#18286](https://github.com/cypress-io/cypress/issues/18286)) ([ea2f6a4](https://github.com/cypress-io/cypress/commit/ea2f6a45c7057e51b2fc879ff70da75538fa1002))
37
-
38
- # [@cypress/vite-dev-server-v2.1.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.8...@cypress/vite-dev-server-v2.1.0) (2021-09-10)
39
-
40
-
41
- ### Features
42
-
43
- * allow usage of @react/plugins with cypress.config.js ([#17738](https://github.com/cypress-io/cypress/issues/17738)) ([da4b1e0](https://github.com/cypress-io/cypress/commit/da4b1e06ce33945aabddda0e6e175dc0e1b488a5))
44
-
45
- # [@cypress/vite-dev-server-v2.0.8](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.7...@cypress/vite-dev-server-v2.0.8) (2021-08-30)
46
-
47
-
48
- ### Bug Fixes
49
-
50
- * prevent vite from crashing where there are no support files or specs found ([#17624](https://github.com/cypress-io/cypress/issues/17624)) ([ae0ea87](https://github.com/cypress-io/cypress/commit/ae0ea87802168c524ee5cfe04d0aa59a46195a7d)), closes [#17373](https://github.com/cypress-io/cypress/issues/17373)
51
- * publish the types for vite-dev-server ([#17786](https://github.com/cypress-io/cypress/issues/17786)) ([a94ff69](https://github.com/cypress-io/cypress/commit/a94ff69d09564140ad0cc890771175396eb351cc)), closes [#17648](https://github.com/cypress-io/cypress/issues/17648)
52
- * repair re-run of vite-dev-server issues ([4139631](https://github.com/cypress-io/cypress/commit/4139631b159bac159bd6d2d4c020b5d8b3aa0fa7))
53
-
54
- # [@cypress/vite-dev-server-v2.0.7](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.6...@cypress/vite-dev-server-v2.0.7) (2021-08-12)
55
-
56
-
57
- ### Bug Fixes
58
-
59
- * **vite-dev-server:** chain update all specs when changing child ([#17693](https://github.com/cypress-io/cypress/issues/17693)) ([66e8896](https://github.com/cypress-io/cypress/commit/66e8896b66207e9ce2d1a5dd9f66f73fe58a1e7e)), closes [#17691](https://github.com/cypress-io/cypress/issues/17691)
60
-
61
- # [@cypress/vite-dev-server-v2.0.6](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.5...@cypress/vite-dev-server-v2.0.6) (2021-08-10)
62
-
63
-
64
- ### Bug Fixes
65
-
66
- * prevent vite from crashing where there are no support files or s… ([#17641](https://github.com/cypress-io/cypress/issues/17641)) ([1d2b053](https://github.com/cypress-io/cypress/commit/1d2b053322eb36935928122e4552563a7f98f35d)), closes [#17624](https://github.com/cypress-io/cypress/issues/17624) [#17373](https://github.com/cypress-io/cypress/issues/17373)
67
-
68
- # [@cypress/vite-dev-server-v2.0.5](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.4...@cypress/vite-dev-server-v2.0.5) (2021-08-04)
69
-
70
-
71
- ### Bug Fixes
72
-
73
- * reload every spec file when support updated ([#17598](https://github.com/cypress-io/cypress/issues/17598)) ([efc38b6](https://github.com/cypress-io/cypress/commit/efc38b67497b48db5b3a636acac3be45dd930593))
74
-
75
- # [@cypress/vite-dev-server-v2.0.4](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.3...@cypress/vite-dev-server-v2.0.4) (2021-07-31)
76
-
77
-
78
- ### Bug Fixes
79
-
80
- * **server:** correctly include projectRoot when adding a CI project from GUI ([#17514](https://github.com/cypress-io/cypress/issues/17514)) ([e49b3a4](https://github.com/cypress-io/cypress/commit/e49b3a4b9fc99bb392235b7cad36139faff08eec))
81
- * only rerun if current spec+deps changed ([#17269](https://github.com/cypress-io/cypress/issues/17269)) ([1433b64](https://github.com/cypress-io/cypress/commit/1433b64d25f186774471593892c1c03aa954c4e3))
82
-
83
- # [@cypress/vite-dev-server-v2.0.3](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.2...@cypress/vite-dev-server-v2.0.3) (2021-07-27)
84
-
85
-
86
- ### Bug Fixes
87
-
88
- * make vite re-run on supportFile change ([#17485](https://github.com/cypress-io/cypress/issues/17485)) ([6cbf4c3](https://github.com/cypress-io/cypress/commit/6cbf4c38296d6287fbcbb0ef5ecd21cf63606153))
89
-
90
- # [@cypress/vite-dev-server-v2.0.2](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.1...@cypress/vite-dev-server-v2.0.2) (2021-07-15)
91
-
92
-
93
- ### Bug Fixes
94
-
95
- * **vite:** autorefresh new spec files ([#17270](https://github.com/cypress-io/cypress/issues/17270)) ([99f9352](https://github.com/cypress-io/cypress/commit/99f93528c87b22656d4d732dfb2ed6843991d861))
96
-
97
- # [@cypress/vite-dev-server-v2.0.1](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.0...@cypress/vite-dev-server-v2.0.1) (2021-06-18)
98
-
99
-
100
- ### Bug Fixes
101
-
102
- * vite startDevServer needs to return close() ([#16950](https://github.com/cypress-io/cypress/issues/16950)) ([67b2b3b](https://github.com/cypress-io/cypress/commit/67b2b3b9be13437e56384e377c7d32c6e433e064))
103
-
104
- # [@cypress/vite-dev-server-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.7...@cypress/vite-dev-server-v2.0.0) (2021-05-31)
105
-
106
-
107
- ### Continuous Integration
108
-
109
- * deliver vue3 on master ([#16728](https://github.com/cypress-io/cypress/issues/16728)) ([0ee001f](https://github.com/cypress-io/cypress/commit/0ee001f6250604711653caf5365d8aca063a9cad)), closes [#15100](https://github.com/cypress-io/cypress/issues/15100)
110
-
111
-
112
- ### BREAKING CHANGES
113
-
114
- * no support for vue 2 anymore
115
-
116
- * build: disable auto deliver of next vue
117
-
118
- * Revert "feat(vue): vue 3 support in @cypress/vue"
119
-
120
- This reverts commit 8f55d7baaff1f240677239ae5fdc4180c4a06475.
121
-
122
- * Revert "build: disable auto deliver of next vue"
123
-
124
- This reverts commit ed46c9e5c551e57901dbdc75db2e83bf194c4b18.
125
-
126
- * chore: release @cypress/vue-v1.1.0-alpha.1
127
-
128
- [skip ci]
129
- * dropped support for vue 2 in favor of vue 3
130
-
131
- * test: remove filter tests not relevant in vue 3
132
-
133
- * build: try publishing as a private new major
134
-
135
- * chore: release @cypress/vue-v3.0.0-alpha.1
136
-
137
- [skip ci]
138
-
139
- * chore: bring back access public
140
-
141
- * fix: update dependency to webpack dev server
142
-
143
- * chore: release @cypress/vue-v3.0.0-alpha.2
144
-
145
- [skip ci]
146
-
147
- * chore: remove unnecessary dependency
148
-
149
- * fix: mistreatment of monorepo dependency
150
-
151
- * chore: release @cypress/vue-v3.0.0-alpha.3
152
-
153
- [skip ci]
154
-
155
- * chore: release @cypress/vue-v3.0.0-alpha.4
156
-
157
- [skip ci]
158
-
159
- * fix: use __cy_root at the root element
160
-
161
- * build: avoid using array spread (tslib imports issue)
162
-
163
- * fix: setup for cypress vue tests
164
-
165
- * fix: add cleanup event
166
-
167
- * test: make sure we use the right build of compiler
168
-
169
- * chore: downgrade VTU to rc-1
170
-
171
- * chore: release @cypress/vue-v3.0.0
172
-
173
- [skip ci]
174
-
175
- * chore: upgrade vue version to 3.0.11
176
-
177
- * fix: adjust optional peer deps
178
-
179
- * fix: allow fo any VTU 2 version using ^
180
-
181
- * test: ignore nuxt example
182
-
183
- * test: update yarn lock on vue cli
184
-
185
- * chore: release @cypress/vue-v3.0.1
186
-
187
- [skip ci]
188
-
189
- * ci: release vue@next on master
190
-
191
- * test: fix vue3 examples
192
-
193
- * ci: open only needed server in circle npm-vue
194
-
195
- Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
196
- Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
197
-
198
- # [@cypress/vite-dev-server-v1.2.7](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.6...@cypress/vite-dev-server-v1.2.7) (2021-05-11)
199
-
200
-
201
- ### Bug Fixes
202
-
203
- * **vite-dev-server:** only re-run tests when specs deps are updated ([#16215](https://github.com/cypress-io/cypress/issues/16215)) ([31d89a5](https://github.com/cypress-io/cypress/commit/31d89a5e1af9acf173a24c26903a48ff11cde894))
204
-
205
- # [@cypress/vite-dev-server-v1.2.6](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.5...@cypress/vite-dev-server-v1.2.6) (2021-04-29)
206
-
207
-
208
- ### Bug Fixes
209
-
210
- * **vite-dev-server:** only re-run tests when specs deps are updated ([#16215](https://github.com/cypress-io/cypress/issues/16215)) ([4d23476](https://github.com/cypress-io/cypress/commit/4d23476711d71711590752cada4863a03e1f777f))
211
- * analyze deps of the specs before starting ([3f52def](https://github.com/cypress-io/cypress/commit/3f52def82e7afe9ee0942e6621924d1d6af5efa8))
212
-
213
- # [@cypress/vite-dev-server-v1.2.5](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.4...@cypress/vite-dev-server-v1.2.5) (2021-04-27)
214
-
215
-
216
- ### Bug Fixes
217
-
218
- * **vite-dev-server:** fix url to the client on win ([#16220](https://github.com/cypress-io/cypress/issues/16220)) ([c809d19](https://github.com/cypress-io/cypress/commit/c809d19cc139200232a4292529b3bac60d68e995))
219
-
220
- # [@cypress/vite-dev-server-v1.2.4](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.3...@cypress/vite-dev-server-v1.2.4) (2021-04-26)
221
-
222
-
223
- ### Bug Fixes
224
-
225
- * accept absolute paths in vite dev server ([#16148](https://github.com/cypress-io/cypress/issues/16148)) ([684730f](https://github.com/cypress-io/cypress/commit/684730fb68b0394a5c602421b38fbb4d066bf439))
226
-
227
- # [@cypress/vite-dev-server-v1.2.3](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.2...@cypress/vite-dev-server-v1.2.3) (2021-04-22)
228
-
229
-
230
- ### Bug Fixes
231
-
232
- * make vite-dev-server work on windows ([#16103](https://github.com/cypress-io/cypress/issues/16103)) ([a380d02](https://github.com/cypress-io/cypress/commit/a380d020a4211ddbb2f10a61308bd1a6d2e45057))
233
-
234
- # [@cypress/vite-dev-server-v1.2.2](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.1...@cypress/vite-dev-server-v1.2.2) (2021-04-15)
235
-
236
-
237
- ### Bug Fixes
238
-
239
- * conditionally require vue and update alias if installed ([#16000](https://github.com/cypress-io/cypress/issues/16000)) ([8b97b46](https://github.com/cypress-io/cypress/commit/8b97b4641e7e1b2af8ea38d44273dcc149267e20))
240
-
241
- # [@cypress/vite-dev-server-v1.2.1](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.2.0...@cypress/vite-dev-server-v1.2.1) (2021-04-13)
242
-
243
-
244
- ### Bug Fixes
245
-
246
- * **vite-dev-server:** Use viteConfig.server.port if defined ([#15893](https://github.com/cypress-io/cypress/issues/15893)) ([d0dcf22](https://github.com/cypress-io/cypress/commit/d0dcf221018cf2c364bc00ff6f750146eb048e7d))
247
-
248
- # [@cypress/vite-dev-server-v1.2.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.1.0...@cypress/vite-dev-server-v1.2.0) (2021-04-05)
249
-
250
-
251
- ### Bug Fixes
252
-
253
- * **vite-dev-server:** import cypress client script asynchronously to avoid flake ([#15778](https://github.com/cypress-io/cypress/issues/15778)) ([88a3830](https://github.com/cypress-io/cypress/commit/88a3830d68ef71290ecad3ab7ba440370f314741))
254
- * make sure the vite server starts on a new port ([57e2988](https://github.com/cypress-io/cypress/commit/57e29886cb731a90724dc5473cfd97760b370c62))
255
- * make vite dev server open on a free port ([#15756](https://github.com/cypress-io/cypress/issues/15756)) ([cd66b05](https://github.com/cypress-io/cypress/commit/cd66b05307ff3f40b3a8bf312a409de2e9ab9399))
256
-
257
-
258
- ### Features
259
-
260
- * simplify vite server ([#15416](https://github.com/cypress-io/cypress/issues/15416)) ([adc2fc8](https://github.com/cypress-io/cypress/commit/adc2fc893fbf32f1f6121d18ddb8a8096e5ebf39))
261
-
262
- # [@cypress/vite-dev-server-v1.1.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.0.2...@cypress/vite-dev-server-v1.1.0) (2021-03-15)
263
-
264
-
265
- ### Bug Fixes
266
-
267
- * **component-testing:** ensure to call unmount after each test ([#15385](https://github.com/cypress-io/cypress/issues/15385)) ([153fc51](https://github.com/cypress-io/cypress/commit/153fc515a53343758393db795879a64494374551))
268
- * **component-testing:** make sure vite html is published on npm ([#15379](https://github.com/cypress-io/cypress/issues/15379)) ([325a7ec](https://github.com/cypress-io/cypress/commit/325a7ec56e9dd91e25f39184407751daf3b9a371))
269
- * **component-testing:** vite server dependency refresh ([#15366](https://github.com/cypress-io/cypress/issues/15366)) ([59dbed9](https://github.com/cypress-io/cypress/commit/59dbed90dcfd6c71d3478cd61d0228cff702087f))
270
-
271
-
272
- ### Features
273
-
274
- * create-cypress-tests installation wizard ([#9563](https://github.com/cypress-io/cypress/issues/9563)) ([c405ee8](https://github.com/cypress-io/cypress/commit/c405ee89ef5321df6151fdeec1e917ac952c0d38)), closes [#9116](https://github.com/cypress-io/cypress/issues/9116)
275
- * rollup-dev-server for CT ([#15215](https://github.com/cypress-io/cypress/issues/15215)) ([6f02719](https://github.com/cypress-io/cypress/commit/6f02719511459ebe682ec85eecc02f6b418d233a))
276
-
277
- # [@cypress/vite-dev-server-v1.0.2](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.0.1...@cypress/vite-dev-server-v1.0.2) (2021-03-10)
278
-
279
-
280
- ### Bug Fixes
281
-
282
- * trigger release of the packages ([#15405](https://github.com/cypress-io/cypress/issues/15405)) ([1ce5755](https://github.com/cypress-io/cypress/commit/1ce57554e260850472cf753de68858f47b3f7b3d))
283
-
284
- # [@cypress/vite-dev-server-v1.0.1](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v1.0.0...@cypress/vite-dev-server-v1.0.1) (2021-02-17)
285
-
286
-
287
- ### Bug Fixes
288
-
289
- * trigger semantic release ([#15128](https://github.com/cypress-io/cypress/issues/15128)) ([3a6f3b1](https://github.com/cypress-io/cypress/commit/3a6f3b1928277f7086062b1107f424e5a0247e00))
290
-
291
- # @cypress/vite-dev-server-v1.0.0 (2021-02-16)
292
-
293
-
294
- ### Features
295
-
296
- * adding vite-dev-server plugin ([#14839](https://github.com/cypress-io/cypress/issues/14839)) ([0225406](https://github.com/cypress-io/cypress/commit/022540605139545d137125dbb6a85eb995053fcb))
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="cypress" />
3
- import { Plugin } from 'vite';
4
- interface Spec {
5
- absolute: string;
6
- relative: string;
7
- }
8
- export declare const makeCypressPlugin: (projectRoot: string, supportFilePath: string | false, devServerEvents: NodeJS.EventEmitter, specs: Spec[]) => Plugin;
9
- export {};
@@ -1,16 +0,0 @@
1
- /// <reference types="cypress" />
2
- import type { InlineConfig } from 'vite';
3
- export interface StartDevServerOptions {
4
- /**
5
- * the Cypress dev server configuration object
6
- */
7
- options: Cypress.DevServerConfig;
8
- /**
9
- * By default, vite will use your vite.config file to
10
- * Start the server. If you need additional plugins or
11
- * to override some options, you can do so using this.
12
- * @optional
13
- */
14
- viteConfig?: Omit<InlineConfig, 'base' | 'root'>;
15
- }
16
- export declare const resolveServerConfig: ({ viteConfig, options }: StartDevServerOptions) => Promise<InlineConfig>;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveServerConfig = void 0;
7
- const debug_1 = __importDefault(require("debug"));
8
- const path_1 = require("path");
9
- const get_port_1 = __importDefault(require("get-port"));
10
- const makeCypressPlugin_1 = require("./makeCypressPlugin");
11
- const debug = (0, debug_1.default)('cypress:vite-dev-server:start');
12
- const resolveServerConfig = async ({ viteConfig, options }) => {
13
- const { projectRoot, supportFile } = options.config;
14
- const requiredOptions = {
15
- base: '/__cypress/src/',
16
- root: projectRoot,
17
- };
18
- const finalConfig = { ...viteConfig, ...requiredOptions };
19
- finalConfig.plugins = [...(finalConfig.plugins || []), (0, makeCypressPlugin_1.makeCypressPlugin)(projectRoot, supportFile, options.devServerEvents, options.specs)];
20
- // This alias is necessary to avoid a "prefixIdentifiers" issue from slots mounting
21
- // only cjs compiler-core accepts using prefixIdentifiers in slots which vue test utils use.
22
- // Could we resolve this usage in test-utils?
23
- try {
24
- finalConfig.resolve = finalConfig.resolve || {};
25
- finalConfig.resolve.alias = {
26
- ...finalConfig.resolve.alias,
27
- '@vue/compiler-core': (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@vue/compiler-core')), 'dist', 'compiler-core.cjs.js'),
28
- };
29
- }
30
- catch (e) {
31
- // Vue 3 is not installed
32
- }
33
- finalConfig.server = finalConfig.server || {};
34
- finalConfig.server.port = await (0, get_port_1.default)({ port: finalConfig.server.port || 3000 }),
35
- // Ask vite to pre-optimize all dependencies of the specs
36
- finalConfig.optimizeDeps = finalConfig.optimizeDeps || {};
37
- // pre-optimize all the specs
38
- if ((options.specs && options.specs.length)) {
39
- // fix: we must preserve entries configured on target project
40
- const existingOptimizeDepsEntries = finalConfig.optimizeDeps.entries;
41
- if (existingOptimizeDepsEntries) {
42
- finalConfig.optimizeDeps.entries = [...existingOptimizeDepsEntries, ...options.specs.map((spec) => spec.relative)];
43
- }
44
- else {
45
- finalConfig.optimizeDeps.entries = [...options.specs.map((spec) => spec.relative)];
46
- }
47
- // only optimize a supportFile is it is not false or undefined
48
- if (supportFile) {
49
- // fix: on windows we need to replace backslashes with slashes
50
- finalConfig.optimizeDeps.entries.push(supportFile.replace(/\\/g, '/'));
51
- }
52
- }
53
- debug(`the resolved server config is ${JSON.stringify(finalConfig, null, 2)}`);
54
- return finalConfig;
55
- };
56
- exports.resolveServerConfig = resolveServerConfig;
package/index.html DELETED
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
- <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
- <title>AUT Frame</title>
8
- </head>
9
- <body>
10
- <div id="__cy_root"></div>
11
- </body>
12
- </html>