@cypress/vite-dev-server 2.2.0 → 2.2.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
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
+
1
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)
2
23
 
3
24
 
package/README.md CHANGED
@@ -56,8 +56,8 @@ Install `@cypress/vue` or `@cypress/react` to get this package working properly
56
56
  - The HTML page calls a script that loads support file and the specs using a native `import()` function
57
57
  - Then triggers the loaded tests
58
58
 
59
- Vite is reponsible for compiling and bundling all the files. We use its error overlay to display any transpiling error.
60
- Omly runtime errors have to be handled through cypress
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
61
 
62
62
  ## Changelog
63
63
 
@@ -1,15 +1,15 @@
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
-
4
- const supportPath = import.meta.env.__cypress_supportPath
5
- const originAutUrl = import.meta.env.__cypress_originAutUrl
3
+ import specLoaders from 'cypress:spec-loaders'
4
+ import { hasSupportPath, originAutUrl } from 'cypress:config'
6
5
 
7
6
  const specPath = window.location.pathname.replace(originAutUrl, '')
8
7
 
9
- const importsToLoad = [() => import(/* @vite-ignore */ specPath)]
8
+ const specLoader = specLoaders[specPath]
9
+ const importsToLoad = [specLoader || (() => import(/* @vite-ignore */ specPath))]
10
10
 
11
- if (supportPath) {
12
- importsToLoad.unshift(() => import(/* @vite-ignore */ supportPath))
11
+ if (hasSupportPath) {
12
+ importsToLoad.unshift(() => import('cypress:support-path'))
13
13
  }
14
14
 
15
15
  const CypressInstance = window.Cypress = parent.Cypress
@@ -46,3 +46,4 @@ CypressInstance.on('test:before:run', () => {
46
46
 
47
47
  // Make usage of node test plugins possible
48
48
  window.global = window
49
+ window.process = typeof process !== 'undefined' ? process : {}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="cypress" />
2
2
  import { InlineConfig } from 'vite';
3
- import { StartDevServerOptions } from './startServer';
3
+ import { StartDevServerOptions } from './resolveServerConfig';
4
4
  export { StartDevServerOptions };
5
5
  export declare function startDevServer(startDevServerArgs: StartDevServerOptions): Promise<Cypress.ResolvedDevServerConfig>;
6
6
  export declare type CypressViteDevServerConfig = Omit<InlineConfig, 'base' | 'root'>;
package/dist/index.js CHANGED
@@ -2,14 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineDevServerConfig = exports.devServer = exports.startDevServer = void 0;
4
4
  const debug_1 = require("debug");
5
- const startServer_1 = require("./startServer");
6
- const debug = debug_1.debug('cypress:vite-dev-server:vite');
5
+ const vite_1 = require("vite");
6
+ const resolveServerConfig_1 = require("./resolveServerConfig");
7
+ const debug = (0, debug_1.debug)('cypress:vite-dev-server:vite');
7
8
  async function startDevServer(startDevServerArgs) {
8
- const viteDevServer = await startServer_1.start(startDevServerArgs);
9
- const app = await viteDevServer.listen();
10
- const port = app.config.server.port;
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();
11
18
  debug('Component testing vite server started on port', port);
12
- return { port, close: app.httpServer.close };
19
+ return { port, close: viteDevServer.close };
13
20
  }
14
21
  exports.startDevServer = startDevServer;
15
22
  function devServer(cypressDevServerConfig, devServerConfig) {
@@ -5,11 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeCypressPlugin = void 0;
7
7
  const path_1 = require("path");
8
- const fs_1 = require("fs");
9
- const util_1 = require("util");
8
+ const promises_1 = require("fs/promises");
10
9
  const debug_1 = __importDefault(require("debug"));
11
- const debug = debug_1.default('cypress:vite-dev-server:plugin');
12
- const read = util_1.promisify(fs_1.readFile);
10
+ const vite_1 = require("vite");
11
+ const debug = (0, debug_1.default)('cypress:vite-dev-server:plugin');
13
12
  const pluginName = 'cypress-transform-html';
14
13
  const OSSepRE = new RegExp(`\\${path_1.sep}`, 'g');
15
14
  function convertPathToPosix(path) {
@@ -17,7 +16,7 @@ function convertPathToPosix(path) {
17
16
  ? path
18
17
  : path.replace(OSSepRE, '/');
19
18
  }
20
- const INIT_FILEPATH = path_1.resolve(__dirname, '../client/initCypressTests.js');
19
+ const INIT_FILEPATH = (0, path_1.resolve)(__dirname, '../client/initCypressTests.js');
21
20
  const HMR_DEPENDENCY_LOOKUP_MAX_ITERATION = 50;
22
21
  function getSpecsPathsSet(specs) {
23
22
  return new Set(specs.map((spec) => spec.absolute));
@@ -28,39 +27,49 @@ const makeCypressPlugin = (projectRoot, supportFilePath, devServerEvents, specs)
28
27
  devServerEvents.on('dev-server:specs:changed', (specs) => {
29
28
  specsPathsSet = getSpecsPathsSet(specs);
30
29
  });
31
- const posixSupportFilePath = supportFilePath ? convertPathToPosix(path_1.resolve(projectRoot, supportFilePath)) : undefined;
32
- const normalizedSupportFilePath = posixSupportFilePath ? `${base}@fs/${posixSupportFilePath}` : undefined;
30
+ const posixSupportFilePath = supportFilePath ? convertPathToPosix((0, path_1.resolve)(projectRoot, supportFilePath)) : undefined;
33
31
  return {
34
32
  name: pluginName,
35
33
  enforce: 'pre',
36
- config(_, env) {
37
- if (env) {
38
- return {
39
- define: {
40
- 'import.meta.env.__cypress_supportPath': JSON.stringify(normalizedSupportFilePath),
41
- 'import.meta.env.__cypress_originAutUrl': JSON.stringify(`__cypress/iframes/${convertPathToPosix(projectRoot)}/`),
42
- },
43
- };
44
- }
45
- },
46
34
  configResolved(config) {
47
35
  base = config.base;
48
36
  },
49
- transformIndexHtml() {
50
- debug('transformIndexHtml with base', base);
51
- return [
52
- // load the script at the end of the body
53
- // script has to be loaded when the vite client is connected
54
- {
55
- tag: 'script',
56
- injectTo: 'body',
57
- attrs: { type: 'module' },
58
- children: `import(${JSON.stringify(`${base}@fs/${INIT_FILEPATH}`)})`,
59
- },
60
- ];
37
+ async transformIndexHtml() {
38
+ const indexHtmlPath = (0, path_1.resolve)(__dirname, '..', 'index.html');
39
+ const indexHtmlContent = await (0, promises_1.readFile)(indexHtmlPath, { encoding: 'utf8' });
40
+ // find </body> last index
41
+ const endOfBody = indexHtmlContent.lastIndexOf('</body>');
42
+ // 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
+ }
61
70
  },
62
71
  configureServer: async (server) => {
63
- const indexHtml = await read(path_1.resolve(__dirname, '..', 'index.html'), { encoding: 'utf8' });
72
+ const indexHtml = await (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '..', 'index.html'), { encoding: 'utf8' });
64
73
  const transformedIndexHtml = await server.transformIndexHtml(base, indexHtml);
65
74
  server.middlewares.use(`${base}index.html`, (req, res) => res.end(transformedIndexHtml));
66
75
  },
@@ -71,7 +80,7 @@ const makeCypressPlugin = (projectRoot, supportFilePath, devServerEvents, specs)
71
80
  let iterationNumber = 0;
72
81
  const exploredFiles = new Set();
73
82
  // until we reached a point where the current module is imported by no other
74
- while (moduleImporters?.size) {
83
+ while (moduleImporters === null || moduleImporters === void 0 ? void 0 : moduleImporters.size) {
75
84
  if (iterationNumber > HMR_DEPENDENCY_LOOKUP_MAX_ITERATION) {
76
85
  debug(`max hmr iteration reached: ${HMR_DEPENDENCY_LOOKUP_MAX_ITERATION}; Rerun will not happen on this file change.`);
77
86
  return [];
@@ -1,5 +1,5 @@
1
1
  /// <reference types="cypress" />
2
- import { ViteDevServer, InlineConfig } from 'vite';
2
+ import type { InlineConfig } from 'vite';
3
3
  export interface StartDevServerOptions {
4
4
  /**
5
5
  * the Cypress dev server configuration object
@@ -13,4 +13,4 @@ export interface StartDevServerOptions {
13
13
  */
14
14
  viteConfig?: Omit<InlineConfig, 'base' | 'root'>;
15
15
  }
16
- export declare function start(devServerOptions: StartDevServerOptions): Promise<ViteDevServer>;
16
+ export declare const resolveServerConfig: ({ viteConfig, options }: StartDevServerOptions) => Promise<InlineConfig>;
@@ -3,13 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.start = void 0;
6
+ exports.resolveServerConfig = void 0;
7
7
  const debug_1 = __importDefault(require("debug"));
8
- const vite_1 = require("vite");
9
8
  const path_1 = require("path");
10
9
  const get_port_1 = __importDefault(require("get-port"));
11
10
  const makeCypressPlugin_1 = require("./makeCypressPlugin");
12
- const debug = debug_1.default('cypress:vite-dev-server:start');
11
+ const debug = (0, debug_1.default)('cypress:vite-dev-server:start');
13
12
  const resolveServerConfig = async ({ viteConfig, options }) => {
14
13
  const { projectRoot, supportFile } = options.config;
15
14
  const requiredOptions = {
@@ -17,7 +16,7 @@ const resolveServerConfig = async ({ viteConfig, options }) => {
17
16
  root: projectRoot,
18
17
  };
19
18
  const finalConfig = { ...viteConfig, ...requiredOptions };
20
- finalConfig.plugins = [...(finalConfig.plugins || []), makeCypressPlugin_1.makeCypressPlugin(projectRoot, supportFile, options.devServerEvents, options.specs)];
19
+ finalConfig.plugins = [...(finalConfig.plugins || []), (0, makeCypressPlugin_1.makeCypressPlugin)(projectRoot, supportFile, options.devServerEvents, options.specs)];
21
20
  // This alias is necessary to avoid a "prefixIdentifiers" issue from slots mounting
22
21
  // only cjs compiler-core accepts using prefixIdentifiers in slots which vue test utils use.
23
22
  // Could we resolve this usage in test-utils?
@@ -25,14 +24,14 @@ const resolveServerConfig = async ({ viteConfig, options }) => {
25
24
  finalConfig.resolve = finalConfig.resolve || {};
26
25
  finalConfig.resolve.alias = {
27
26
  ...finalConfig.resolve.alias,
28
- '@vue/compiler-core': path_1.resolve(path_1.dirname(require.resolve('@vue/compiler-core')), 'dist', 'compiler-core.cjs.js'),
27
+ '@vue/compiler-core': (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@vue/compiler-core')), 'dist', 'compiler-core.cjs.js'),
29
28
  };
30
29
  }
31
30
  catch (e) {
32
31
  // Vue 3 is not installed
33
32
  }
34
33
  finalConfig.server = finalConfig.server || {};
35
- finalConfig.server.port = await get_port_1.default({ port: finalConfig.server.port || 3000, host: 'localhost' }),
34
+ finalConfig.server.port = await (0, get_port_1.default)({ port: finalConfig.server.port || 3000 }),
36
35
  // Ask vite to pre-optimize all dependencies of the specs
37
36
  finalConfig.optimizeDeps = finalConfig.optimizeDeps || {};
38
37
  // pre-optimize all the specs
@@ -54,13 +53,4 @@ const resolveServerConfig = async ({ viteConfig, options }) => {
54
53
  debug(`the resolved server config is ${JSON.stringify(finalConfig, null, 2)}`);
55
54
  return finalConfig;
56
55
  };
57
- async function start(devServerOptions) {
58
- if (!devServerOptions.viteConfig) {
59
- debug('User did not pass in any Vite dev server configuration');
60
- devServerOptions.viteConfig = {};
61
- }
62
- debug('starting vite dev server');
63
- const resolvedConfig = await resolveServerConfig(devServerOptions);
64
- return vite_1.createServer(resolvedConfig);
65
- }
66
- exports.start = start;
56
+ exports.resolveServerConfig = resolveServerConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/vite-dev-server",
3
- "version": "2.2.0",
3
+ "version": "2.2.3",
4
4
  "description": "Launches Vite Dev Server for Component Testing",
5
5
  "main": "index.js",
6
6
  "scripts": {