@cypress/vite-dev-server 2.2.2 → 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 +7 -0
- package/README.md +2 -2
- package/client/initCypressTests.js +7 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -5
- package/dist/makeCypressPlugin.js +36 -27
- package/dist/{startServer.d.ts → resolveServerConfig.d.ts} +2 -2
- package/dist/{startServer.js → resolveServerConfig.js} +2 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
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)
|
|
2
9
|
|
|
3
10
|
|
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
|
|
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
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
|
-
|
|
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
|
|
8
|
+
const specLoader = specLoaders[specPath]
|
|
9
|
+
const importsToLoad = [specLoader || (() => import(/* @vite-ignore */ specPath))]
|
|
10
10
|
|
|
11
|
-
if (
|
|
12
|
-
importsToLoad.unshift(() => import(
|
|
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 './
|
|
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
|
|
5
|
+
const vite_1 = require("vite");
|
|
6
|
+
const resolveServerConfig_1 = require("./resolveServerConfig");
|
|
6
7
|
const debug = (0, debug_1.debug)('cypress:vite-dev-server:vite');
|
|
7
8
|
async function startDevServer(startDevServerArgs) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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:
|
|
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
|
|
9
|
-
const util_1 = require("util");
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
10
9
|
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const vite_1 = require("vite");
|
|
11
11
|
const debug = (0, debug_1.default)('cypress:vite-dev-server:plugin');
|
|
12
|
-
const read = (0, util_1.promisify)(fs_1.readFile);
|
|
13
12
|
const pluginName = 'cypress-transform-html';
|
|
14
13
|
const OSSepRE = new RegExp(`\\${path_1.sep}`, 'g');
|
|
15
14
|
function convertPathToPosix(path) {
|
|
@@ -29,38 +28,48 @@ const makeCypressPlugin = (projectRoot, supportFilePath, devServerEvents, specs)
|
|
|
29
28
|
specsPathsSet = getSpecsPathsSet(specs);
|
|
30
29
|
});
|
|
31
30
|
const posixSupportFilePath = supportFilePath ? convertPathToPosix((0, path_1.resolve)(projectRoot, supportFilePath)) : undefined;
|
|
32
|
-
const normalizedSupportFilePath = posixSupportFilePath ? `${base}@fs/${posixSupportFilePath}` : 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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
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
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="cypress" />
|
|
2
|
-
import {
|
|
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
|
|
16
|
+
export declare const resolveServerConfig: ({ viteConfig, options }: StartDevServerOptions) => Promise<InlineConfig>;
|
|
@@ -3,9 +3,8 @@ 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.
|
|
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");
|
|
@@ -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
|
-
|
|
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 (0, vite_1.createServer)(resolvedConfig);
|
|
65
|
-
}
|
|
66
|
-
exports.start = start;
|
|
56
|
+
exports.resolveServerConfig = resolveServerConfig;
|