@cypress/vite-dev-server 3.1.1 → 3.3.0
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 +1 -1
- package/client/initCypressTests.js +12 -2
- package/dist/devServer.d.ts +4 -1
- package/dist/devServer.js +1 -1
- package/dist/getVite.js +1 -1
- package/dist/plugins/cypress.js +3 -3
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +3 -2
- package/dist/plugins/inspect.js +1 -1
- package/dist/plugins/sourcemap.d.ts +4 -0
- package/dist/plugins/sourcemap.js +45 -0
- package/dist/resolveConfig.d.ts +2 -1
- package/dist/resolveConfig.js +18 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ We then merge the sourced config with the user's vite config, and layer on our o
|
|
|
58
58
|
|
|
59
59
|
## License
|
|
60
60
|
|
|
61
|
-
[](https://github.com/cypress-io/cypress/blob/
|
|
61
|
+
[](https://github.com/cypress-io/cypress/blob/develop/LICENSE)
|
|
62
62
|
|
|
63
63
|
This project is licensed under the terms of the [MIT license](/LICENSE).
|
|
64
64
|
|
|
@@ -24,12 +24,22 @@ if (supportFile) {
|
|
|
24
24
|
|
|
25
25
|
// We need a slash before /cypress/supportFile.js, this happens by default
|
|
26
26
|
// with the current string replacement logic.
|
|
27
|
-
importsToLoad.push(
|
|
27
|
+
importsToLoad.push({
|
|
28
|
+
load: () => import(`${devServerPublicPathRoute}${supportRelativeToProjectRoot}`),
|
|
29
|
+
absolute: supportFile,
|
|
30
|
+
relative: supportRelativeToProjectRoot,
|
|
31
|
+
relativeUrl: `${devServerPublicPathRoute}${supportRelativeToProjectRoot}`,
|
|
32
|
+
})
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
/* Spec file import logic */
|
|
31
36
|
// We need a slash before /src/my-spec.js, this does not happen by default.
|
|
32
|
-
importsToLoad.push(
|
|
37
|
+
importsToLoad.push({
|
|
38
|
+
load: () => import(`${devServerPublicPathRoute}/${CypressInstance.spec.relative}`),
|
|
39
|
+
absolute: CypressInstance.spec.absolute,
|
|
40
|
+
relative: CypressInstance.spec.relative,
|
|
41
|
+
relativeUrl: `${devServerPublicPathRoute}/${CypressInstance.spec.relative}`,
|
|
42
|
+
})
|
|
33
43
|
|
|
34
44
|
if (!CypressInstance) {
|
|
35
45
|
throw new Error('Tests cannot run without a reference to Cypress!')
|
package/dist/devServer.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/// <reference types="cypress" />
|
|
2
|
+
/// <reference types="cypress" />
|
|
2
3
|
/// <reference types="node" />
|
|
4
|
+
import type { UserConfig } from 'vite';
|
|
3
5
|
declare const ALL_FRAMEWORKS: readonly ["react", "vue"];
|
|
6
|
+
declare type ConfigHandler = UserConfig | (() => UserConfig | Promise<UserConfig>);
|
|
4
7
|
export declare type ViteDevServerConfig = {
|
|
5
8
|
specs: Cypress.Spec[];
|
|
6
9
|
cypressConfig: Cypress.PluginConfigOptions;
|
|
@@ -8,7 +11,7 @@ export declare type ViteDevServerConfig = {
|
|
|
8
11
|
onConfigNotFound?: (devServer: 'vite', cwd: string, lookedIn: string[]) => void;
|
|
9
12
|
} & {
|
|
10
13
|
framework?: typeof ALL_FRAMEWORKS[number];
|
|
11
|
-
viteConfig?:
|
|
14
|
+
viteConfig?: ConfigHandler;
|
|
12
15
|
};
|
|
13
16
|
export declare function devServer(config: ViteDevServerConfig): Promise<Cypress.ResolvedDevServerConfig>;
|
|
14
17
|
export declare namespace devServer {
|
package/dist/devServer.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.devServer = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 =
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
6
|
const getVite_1 = require("./getVite");
|
|
7
7
|
const resolveConfig_1 = require("./resolveConfig");
|
|
8
8
|
const debug = (0, debug_1.default)('cypress:vite-dev-server:devServer');
|
package/dist/getVite.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVite = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 =
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
6
|
const debug = (0, debug_1.default)('cypress:vite-dev-server:getVite');
|
|
7
7
|
// "vite-dev-server" is bundled in the binary, so we need to require.resolve "vite"
|
|
8
8
|
// from root of the active project since we don't bundle vite internally but rather
|
package/dist/plugins/cypress.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Cypress = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 =
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
6
|
const pathe_1 = require("pathe");
|
|
7
7
|
const node_html_parser_1 = require("node-html-parser");
|
|
8
|
-
const fs_1 =
|
|
9
|
-
const path_1 =
|
|
8
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
9
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
10
|
const debug = (0, debug_1.default)('cypress:vite-dev-server:plugins:cypress');
|
|
11
11
|
const INIT_FILEPATH = (0, pathe_1.resolve)(__dirname, '../../client/initCypressTests.js');
|
|
12
12
|
const HMR_DEPENDENCY_LOOKUP_MAX_ITERATION = 50;
|
package/dist/plugins/index.d.ts
CHANGED
package/dist/plugins/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./inspect"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./cypress"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./sourcemap"), exports);
|
package/dist/plugins/inspect.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CypressInspect = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 =
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
6
|
const debug = (0, debug_1.default)('cypress:vite-dev-server:plugins:inspect');
|
|
7
7
|
const CypressInspect = (config) => {
|
|
8
8
|
var _a;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CypressSourcemap = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
const debug = (0, debug_1.default)('cypress:vite-dev-server:plugins:sourcemap');
|
|
7
|
+
const CypressSourcemap = (options, vite) => {
|
|
8
|
+
return {
|
|
9
|
+
name: 'cypress:sourcemap',
|
|
10
|
+
enforce: 'post',
|
|
11
|
+
transform(code, id, options) {
|
|
12
|
+
try {
|
|
13
|
+
if (/\.js$/i.test(id) && !/\/\/# sourceMappingURL=/i.test(code)) {
|
|
14
|
+
/*
|
|
15
|
+
The Vite dev server and plugins automatically generate sourcemaps for most files, but they are
|
|
16
|
+
only included in the served files if any transpilation actually occurred (JSX, TS, etc). This
|
|
17
|
+
means that files that are "pure" JS won't include sourcemaps, so JS spec files that don't require
|
|
18
|
+
transpilation won't get code frames in the runner.
|
|
19
|
+
|
|
20
|
+
A sourcemap for these files is generated (just not served) which is in effect an "identity"
|
|
21
|
+
sourcemap mapping 1-to-1 to the output file. We can grab this and pass it along as a sourcemap
|
|
22
|
+
we want Vite to embed into the output, giving Cypress a sourcemap to use for codeFrame lookups.
|
|
23
|
+
@see https://rollupjs.org/guide/en/#thisgetcombinedsourcemap
|
|
24
|
+
|
|
25
|
+
We utilize a 'post' plugin here and manually append the sourcemap content to the code. We *should*
|
|
26
|
+
be able to pass the sourcemap along using the `map` attribute in the return value, but Babel-based
|
|
27
|
+
plugins don't work with this which causes sourcemaps to break for files that go through common
|
|
28
|
+
plugins like `@vitejs/plugin-react`. By manually appending the sourcemap at this point in time
|
|
29
|
+
Babel-transformed files end up with correct sourcemaps.
|
|
30
|
+
*/
|
|
31
|
+
const sourcemap = this.getCombinedSourcemap();
|
|
32
|
+
code += `\n//# sourceMappingURL=${sourcemap.toUrl()}`;
|
|
33
|
+
return {
|
|
34
|
+
code,
|
|
35
|
+
map: { mappings: '' },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (_err) {
|
|
40
|
+
debug('Failed to propagate sourcemap for %s: %o', id, _err);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
exports.CypressSourcemap = CypressSourcemap;
|
package/dist/resolveConfig.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InlineConfig } from 'vite';
|
|
1
2
|
import type { ViteDevServerConfig } from './devServer';
|
|
2
3
|
import type { Vite } from './getVite';
|
|
3
|
-
export declare const createViteDevServerConfig: (config: ViteDevServerConfig, vite: Vite) => Promise<
|
|
4
|
+
export declare const createViteDevServerConfig: (config: ViteDevServerConfig, vite: Vite) => Promise<InlineConfig>;
|
package/dist/resolveConfig.js
CHANGED
|
@@ -7,10 +7,10 @@ const tslib_1 = require("tslib");
|
|
|
7
7
|
* Vitest's own config resolution logic.
|
|
8
8
|
* You can find it here https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/create.ts
|
|
9
9
|
*/
|
|
10
|
-
const debug_1 =
|
|
10
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
11
11
|
const local_pkg_1 = require("local-pkg");
|
|
12
12
|
const pathe_1 = require("pathe");
|
|
13
|
-
const path_1 =
|
|
13
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
14
|
const constants_1 = require("./constants");
|
|
15
15
|
const index_1 = require("./plugins/index");
|
|
16
16
|
const debug = (0, debug_1.default)('cypress:vite-dev-server:resolve-config');
|
|
@@ -84,9 +84,24 @@ const createViteDevServerConfig = async (config, vite) => {
|
|
|
84
84
|
plugins: [
|
|
85
85
|
(0, index_1.Cypress)(config, vite),
|
|
86
86
|
(0, index_1.CypressInspect)(config),
|
|
87
|
+
(0, index_1.CypressSourcemap)(config, vite),
|
|
87
88
|
].filter((p) => p != null),
|
|
88
89
|
};
|
|
89
|
-
|
|
90
|
+
if (config.cypressConfig.isTextTerminal) {
|
|
91
|
+
viteBaseConfig.server = Object.assign(Object.assign({}, (viteBaseConfig.server || {})), {
|
|
92
|
+
// Disable file watching and HMR when executing tests in `run` mode
|
|
93
|
+
watch: {
|
|
94
|
+
ignored: '**/*',
|
|
95
|
+
}, hmr: false });
|
|
96
|
+
}
|
|
97
|
+
let resolvedOverrides = {};
|
|
98
|
+
if (typeof viteOverrides === 'function') {
|
|
99
|
+
resolvedOverrides = await viteOverrides();
|
|
100
|
+
}
|
|
101
|
+
else if (typeof viteOverrides === 'object') {
|
|
102
|
+
resolvedOverrides = viteOverrides;
|
|
103
|
+
}
|
|
104
|
+
const finalConfig = vite.mergeConfig(viteBaseConfig, resolvedOverrides);
|
|
90
105
|
debug('The resolved server config is', JSON.stringify(finalConfig, null, 2));
|
|
91
106
|
return finalConfig;
|
|
92
107
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cypress/vite-dev-server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Launches Vite Dev Server for Component Testing",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dedent": "^0.7.0",
|
|
27
27
|
"mocha": "^9.2.2",
|
|
28
28
|
"sinon": "^13.0.1",
|
|
29
|
-
"ts-node": "^10.
|
|
30
|
-
"vite": "3.0
|
|
29
|
+
"ts-node": "^10.9.1",
|
|
30
|
+
"vite": "3.1.0",
|
|
31
31
|
"vite-plugin-inspect": "0.4.3"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"type": "git",
|
|
42
42
|
"url": "https://github.com/cypress-io/cypress.git"
|
|
43
43
|
},
|
|
44
|
-
"homepage": "https://github.com/cypress-io/cypress/tree/
|
|
44
|
+
"homepage": "https://github.com/cypress-io/cypress/tree/develop/npm/vite-dev-server#readme",
|
|
45
45
|
"bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md",
|
|
46
46
|
"module": "dist/index.js",
|
|
47
47
|
"publishConfig": {
|