@cypress/webpack-dev-server 1.8.2 → 2.0.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/CHANGELOG.md +51 -0
- package/README.md +47 -81
- package/dist/CypressCTWebpackPlugin.d.ts +15 -0
- package/dist/CypressCTWebpackPlugin.js +103 -0
- package/dist/aut-runner.js +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +9 -0
- package/dist/createWebpackDevServer.d.ts +26 -0
- package/dist/createWebpackDevServer.js +49 -0
- package/dist/devServer.d.ts +35 -0
- package/dist/devServer.js +103 -0
- package/dist/helpers/createReactAppHandler.d.ts +8 -0
- package/dist/helpers/createReactAppHandler.js +300 -0
- package/dist/helpers/nextHandler.d.ts +2 -0
- package/dist/helpers/nextHandler.js +197 -0
- package/dist/helpers/nuxtHandler.d.ts +2 -0
- package/dist/helpers/nuxtHandler.js +27 -0
- package/dist/helpers/sourceRelativeWebpackModules.d.ts +46 -0
- package/dist/helpers/sourceRelativeWebpackModules.js +197 -0
- package/dist/helpers/vueCliHandler.d.ts +2 -0
- package/dist/helpers/vueCliHandler.js +23 -0
- package/dist/index.d.ts +3 -15
- package/dist/index.js +4 -63
- package/dist/loader.d.ts +1 -3
- package/dist/loader.js +7 -27
- package/dist/makeDefaultWebpackConfig.d.ts +1 -0
- package/dist/makeDefaultWebpackConfig.js +48 -0
- package/dist/makeWebpackConfig.d.ts +6 -16
- package/dist/makeWebpackConfig.js +120 -93
- package/dist/measureWebpackPerformance.d.ts +1 -2
- package/dist/measureWebpackPerformance.js +10 -8
- package/package.json +34 -25
- package/dist/plugin.d.ts +0 -45
- package/dist/plugin.js +0 -84
- package/dist/startServer.d.ts +0 -13
- package/dist/startServer.js +0 -75
- package/dist/webpack.config.d.ts +0 -2
- package/dist/webpack.config.js +0 -24
- package/dist/webpackDevServerFacts.d.ts +0 -6
- package/dist/webpackDevServerFacts.js +0 -19
- package/index-template.html +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
# [@cypress/webpack-dev-server-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v1.8.4...@cypress/webpack-dev-server-v2.0.0) (2022-06-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add package.json metadata for webpack-dev-server ([#22292](https://github.com/cypress-io/cypress/issues/22292)) ([9cfec97](https://github.com/cypress-io/cypress/commit/9cfec9750f2ddc9fe691aabbe2ecc9bc02a3d915))
|
|
7
|
+
* ct testing support for node 17+ ([#21430](https://github.com/cypress-io/cypress/issues/21430)) ([0f786ab](https://github.com/cypress-io/cypress/commit/0f786ab893d178c2f87eed6a1334a248c6bec7a6))
|
|
8
|
+
* display cy.mount command log ([#21500](https://github.com/cypress-io/cypress/issues/21500)) ([140b4ba](https://github.com/cypress-io/cypress/commit/140b4ba2110243712a614a39b2408c30cce4d0b1))
|
|
9
|
+
* Ensuring spec file presence prior to webpack-dev-server compilation ([#21550](https://github.com/cypress-io/cypress/issues/21550)) ([87eec2b](https://github.com/cypress-io/cypress/commit/87eec2b460b02a123667b40ee907878fa4be2bee))
|
|
10
|
+
* Guard against slow requests in GraphQL Resolution (part 2) ([#21020](https://github.com/cypress-io/cypress/issues/21020)) ([b0c8db3](https://github.com/cypress-io/cypress/commit/b0c8db34348be31f32795f3f67c3408403d59ace))
|
|
11
|
+
* issue with compilation failures in component testing ([#21599](https://github.com/cypress-io/cypress/issues/21599)) ([f2bce02](https://github.com/cypress-io/cypress/commit/f2bce02f5dcab7a73a2a1b8e102518d706a29c25))
|
|
12
|
+
* next 12.1.6 support and add tests ([#21515](https://github.com/cypress-io/cypress/issues/21515)) ([ada7179](https://github.com/cypress-io/cypress/commit/ada7179acb4ff0ca0057714883153cc9b2006daa))
|
|
13
|
+
* restart dev-server on config change ([#21212](https://github.com/cypress-io/cypress/issues/21212)) ([00a0f5a](https://github.com/cypress-io/cypress/commit/00a0f5a0e905fdfe5ef9f8ba71f915ed20ca4b72))
|
|
14
|
+
* supportFile path and supportFile false for vite on windows ([#21156](https://github.com/cypress-io/cypress/issues/21156)) ([dd180c8](https://github.com/cypress-io/cypress/commit/dd180c89b27546b0c96cc3f4fb4e75d983c8003e))
|
|
15
|
+
* UNIFY-1774 error if component config is not sourced for webpack/vite ([#21563](https://github.com/cypress-io/cypress/issues/21563)) ([566a7b1](https://github.com/cypress-io/cypress/commit/566a7b1feb0fc1a8f1ccf83a23d8ad7a94409a6b))
|
|
16
|
+
* wire up scaffolded indexHtml to dev servers ([#20453](https://github.com/cypress-io/cypress/issues/20453)) ([3a8797e](https://github.com/cypress-io/cypress/commit/3a8797e54db9fd0ef93a14ddc71c138ba8251e53))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### chore
|
|
20
|
+
|
|
21
|
+
* prep npm packages for use with Cypress v10 ([b924d08](https://github.com/cypress-io/cypress/commit/b924d086ee2e2ccc93303731e001b2c9e9d0af17))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* add new webpack-dev-server package based on object API & bundling ([#20861](https://github.com/cypress-io/cypress/issues/20861)) ([e1da852](https://github.com/cypress-io/cypress/commit/e1da8524733c0ebedc2aed5c97117adb25fa733b))
|
|
27
|
+
* Add typings for new devServer config ([#18797](https://github.com/cypress-io/cypress/issues/18797)) ([e018a14](https://github.com/cypress-io/cypress/commit/e018a14c211bfcbdc4568a9a737f14f5c1686e35))
|
|
28
|
+
* Deprecate run-ct / open-ct, and update all examples to use --ct instead ([#18422](https://github.com/cypress-io/cypress/issues/18422)) ([196e8f6](https://github.com/cypress-io/cypress/commit/196e8f62cc6d27974f235945cb5700624b3dae41))
|
|
29
|
+
* index.html configurability and storybook support ([#18242](https://github.com/cypress-io/cypress/issues/18242)) ([745b3ac](https://github.com/cypress-io/cypress/commit/745b3ac4518302983522daedf817623334feae5b))
|
|
30
|
+
* merging / delegating remote queries to cloud schema ([#17875](https://github.com/cypress-io/cypress/issues/17875)) ([94541d4](https://github.com/cypress-io/cypress/commit/94541d4f18591e8fa4b8702c39e92b0a7238aa5d))
|
|
31
|
+
* swap the #__cy_root id selector to become data-cy-root for component mounting ([#20951](https://github.com/cypress-io/cypress/issues/20951)) ([0e7b555](https://github.com/cypress-io/cypress/commit/0e7b555f93fb403f431c5de4a07ae7ad6ac89ba2))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### BREAKING CHANGES
|
|
35
|
+
|
|
36
|
+
* new version of packages for Cypress v10
|
|
37
|
+
|
|
38
|
+
# [@cypress/webpack-dev-server-v1.8.4](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v1.8.3...@cypress/webpack-dev-server-v1.8.4) (2022-03-29)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* **deps:** add 'lodash' to webpack-dev-server plugin dependencies ([#20815](https://github.com/cypress-io/cypress/issues/20815)) ([a472427](https://github.com/cypress-io/cypress/commit/a4724271601aff110c68ae4364e68764f22cd12c))
|
|
44
|
+
|
|
45
|
+
# [@cypress/webpack-dev-server-v1.8.3](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v1.8.2...@cypress/webpack-dev-server-v1.8.3) (2022-03-15)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* **webpack-dev-server:** do not encodeUri in loader ([#20575](https://github.com/cypress-io/cypress/issues/20575)) ([1b152fc](https://github.com/cypress-io/cypress/commit/1b152fca1b9ed9894cf7a5b2a964c856f73fc685)), closes [#20593](https://github.com/cypress-io/cypress/issues/20593)
|
|
51
|
+
|
|
1
52
|
# [@cypress/webpack-dev-server-v1.8.2](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v1.8.1...@cypress/webpack-dev-server-v1.8.2) (2022-03-03)
|
|
2
53
|
|
|
3
54
|
|
package/README.md
CHANGED
|
@@ -1,98 +1,64 @@
|
|
|
1
1
|
# @cypress/webpack-dev-server
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
3
|
+
Implements the APIs for the object-syntax of the Cypress Component-testing "webpack dev server".
|
|
4
|
+
|
|
5
|
+
Object syntax:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { defineConfig } from 'cypress'
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
component: {
|
|
12
|
+
devServer: {
|
|
13
|
+
framework: 'create-react-app',
|
|
14
|
+
bundler: 'webpack',
|
|
15
|
+
// webpackConfig?: Will try to infer, if passed it will be used as is
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
This page
|
|
40
|
-
- will contain an element `<div id="__cy_root"></div>` to attach the mounted components to.
|
|
41
|
-
- will load support files
|
|
42
|
-
- will load the current spec from the url
|
|
43
|
-
- will start the test when both files are done loading
|
|
44
|
-
- The server re-runs the tests as soon as the current spec or any dependency is updated
|
|
45
|
-
by calling an event `devServerEvents.emit('dev-server:compile:success')`
|
|
46
|
-
|
|
47
|
-
## Webpack
|
|
48
|
-
|
|
49
|
-
Webpack-dev-server fulfills his responsibilities by
|
|
50
|
-
|
|
51
|
-
- Making a `webpack.config` from the users setup by changing the entrypoint to `browser.ts`
|
|
52
|
-
- Launches the webpack dev server with `devServer.publicPath = "__cypress/src/"` and `devServer.hot = false`
|
|
53
|
-
- The entry point (`browser.ts`) delegates the loading of spec files to the loader.
|
|
54
|
-
- By using a require on itself, it enables using a custom loader and Hot Module Replacements if hot is false.
|
|
55
|
-
- The plugin is responsible for passing down the path to the support files and the list of specs discovered by the cypress server to the loader
|
|
56
|
-
- The loader:
|
|
57
|
-
- compares the url with each spec path given by the plugin
|
|
58
|
-
- picks the spec that should be run
|
|
59
|
-
- runs the `AUT-Runner.ts` to load and launch the support file and the current spec
|
|
60
|
-
|
|
61
|
-
## API
|
|
62
|
-
|
|
63
|
-
`startDevServer` takes an object of options.
|
|
64
|
-
|
|
65
|
-
- `options` (required): this contains various internal configuration. It's provided as the first argument to the `dev-server:start` event. Just make sure you pass it to the `startDevServer`.
|
|
66
|
-
- `webpackConfig` (optional): the webpack config used by your application. We provide some [presets](https://github.com/cypress-io/cypress/tree/develop/npm/react/plugins), but you can pass the `webpackConfig` manually, too.
|
|
67
|
-
- `template` (optional): by default [this index.html](https://github.com/cypress-io/cypress/blob/develop/npm/webpack-dev-server/index-template.html) is used. You can provide your own using this option. This is useful if you'd like to include some CDN links, or in some way customize the default html. If you are passing this option, ensure your `index.html` contains the same content as [the default template](https://github.com/cypress-io/cypress/blob/develop/npm/webpack-dev-server/index-template.html). Some of our presets include a custom `index.html`, such as [Next](https://github.com/cypress-io/cypress/tree/develop/npm/react/plugins/next).
|
|
68
|
-
|
|
69
|
-
See [npm/react/plugins/next](https://github.com/cypress-io/cypress/blob/develop/npm/react/plugins/next/index.js) for a full example using all the options.
|
|
21
|
+
Function syntax:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { devServer } from '@cypress/webpack-dev-server'
|
|
25
|
+
import { defineConfig } from 'cypress'
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
component: {
|
|
29
|
+
devServer(cypressConfig) {
|
|
30
|
+
return devServer({
|
|
31
|
+
cypressConfig,
|
|
32
|
+
framework: 'react',
|
|
33
|
+
webpackConfig: require('./webpack.config.js')
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
```
|
|
70
39
|
|
|
71
|
-
##
|
|
40
|
+
## Testing
|
|
72
41
|
|
|
73
|
-
|
|
42
|
+
Unit tests can be run with `npm test`. Integration tests can be run with `yarn cypress:run`
|
|
74
43
|
|
|
75
|
-
|
|
76
|
-
WEBPACK_PERF_MEASURE=true yarn cypress run-ct
|
|
77
|
-
```
|
|
44
|
+
This module should be primarily covered by system-tests / open-mode tests. All system-tests directories should be created using the notation:
|
|
78
45
|
|
|
79
|
-
|
|
46
|
+
`webpack${major}_wds${devServerMajor}-$framework{-$variant}`
|
|
80
47
|
|
|
81
|
-
|
|
48
|
+
- webpack4_wds3-react
|
|
49
|
+
- webpack4_wds4-next-11
|
|
50
|
+
- webpack5_wds3-next-12
|
|
51
|
+
- webpack4_wds4-create-react-app
|
|
82
52
|
|
|
83
|
-
|
|
53
|
+
## Architecture
|
|
84
54
|
|
|
85
|
-
|
|
86
|
-
WEBPACK_PERF_MEASURE=true WEBPACK_PERF_MEASURE_COMPARE={name-of-project} yarn cypress run-ct
|
|
87
|
-
```
|
|
55
|
+
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.
|
|
88
56
|
|
|
89
|
-
|
|
57
|
+
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.
|
|
90
58
|
|
|
91
|
-
|
|
59
|
+
From there, we check the "framework" field to source or define any known webpack transforms to aid in the compilation.
|
|
92
60
|
|
|
93
|
-
|
|
94
|
-
WEBPACK_PERF_MEASURE=true WEBPACK_PERF_MEASURE_UPDATE=true WEBPACK_PERF_MEASURE_COMPARE={name-of-project} yarn cypress run-ct
|
|
95
|
-
```
|
|
61
|
+
We then merge the sourced config with the user's webpack config, and layer on our own transforms, and provide this to a webpack instance. The webpack instance used to create a webpack-dev-server, which is returned.
|
|
96
62
|
|
|
97
63
|
## Changelog
|
|
98
64
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { EventEmitter } from 'events';
|
|
4
|
+
export interface CypressCTWebpackPluginOptions {
|
|
5
|
+
files: Cypress.Cypress['spec'][];
|
|
6
|
+
projectRoot: string;
|
|
7
|
+
supportFile: string | false;
|
|
8
|
+
devServerEvents: EventEmitter;
|
|
9
|
+
webpack: Function;
|
|
10
|
+
}
|
|
11
|
+
export declare type CypressCTContextOptions = Omit<CypressCTWebpackPluginOptions, 'devServerEvents' | 'webpack'>;
|
|
12
|
+
export interface CypressCTWebpackContext {
|
|
13
|
+
_cypress: CypressCTContextOptions;
|
|
14
|
+
}
|
|
15
|
+
export declare const normalizeError: (error: Error | string) => string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CypressCTWebpackPlugin = exports.normalizeError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
6
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
7
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
8
|
+
const normalizeError = (error) => {
|
|
9
|
+
return typeof error === 'string' ? error : error.message;
|
|
10
|
+
};
|
|
11
|
+
exports.normalizeError = normalizeError;
|
|
12
|
+
/**
|
|
13
|
+
* A webpack 4/5 compatible Cypress Component Testing Plugin
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
class CypressCTWebpackPlugin {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.files = [];
|
|
20
|
+
this.compilation = null;
|
|
21
|
+
this.addLoaderContext = (loaderContext, module) => {
|
|
22
|
+
loaderContext._cypress = {
|
|
23
|
+
files: this.files,
|
|
24
|
+
projectRoot: this.projectRoot,
|
|
25
|
+
supportFile: this.supportFile,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
this.beforeCompile = async (compilationParams, callback) => {
|
|
29
|
+
if (!this.compilation) {
|
|
30
|
+
callback();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Ensure we don't try to load files that have been removed from the file system
|
|
34
|
+
// but have not yet been detected by the onSpecsChange handler
|
|
35
|
+
const foundFiles = (await Promise.all(this.files.map(async (file) => {
|
|
36
|
+
try {
|
|
37
|
+
const exists = await fs_extra_1.default.pathExists(file.absolute);
|
|
38
|
+
return exists ? file : null;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
})));
|
|
44
|
+
this.files = foundFiles.filter((file) => file !== null);
|
|
45
|
+
callback();
|
|
46
|
+
};
|
|
47
|
+
/*
|
|
48
|
+
* `webpack --watch` watches the existing specs and their dependencies for changes,
|
|
49
|
+
* but we also need to add additional dependencies to our dynamic "browser.js" (generated
|
|
50
|
+
* using loader.ts) when new specs are created. This hook informs webpack that browser.js
|
|
51
|
+
* has been "updated on disk", causing a recompliation (and pulling the new specs in as
|
|
52
|
+
* dependencies).
|
|
53
|
+
*/
|
|
54
|
+
this.onSpecsChange = (specs) => {
|
|
55
|
+
var _a;
|
|
56
|
+
if (!this.compilation || lodash_1.default.isEqual(specs, this.files)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.files = specs;
|
|
60
|
+
const inputFileSystem = this.compilation.inputFileSystem;
|
|
61
|
+
const utimesSync = (_a = inputFileSystem.fileSystem.utimesSync) !== null && _a !== void 0 ? _a : fs_extra_1.default.utimesSync;
|
|
62
|
+
utimesSync(path_1.default.resolve(__dirname, 'browser.js'), new Date(), new Date());
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The webpack compiler generates a new `compilation` each time it compiles, so
|
|
66
|
+
* we have to apply hooks to it fresh each time
|
|
67
|
+
*
|
|
68
|
+
* @param compilation webpack 4 `compilation.Compilation`, webpack 5
|
|
69
|
+
* `Compilation`
|
|
70
|
+
*/
|
|
71
|
+
this.addCompilationHooks = (compilation) => {
|
|
72
|
+
this.compilation = compilation;
|
|
73
|
+
/* istanbul ignore next */
|
|
74
|
+
if ('NormalModule' in this.webpack) {
|
|
75
|
+
// Webpack 5
|
|
76
|
+
const loader = this.webpack.NormalModule.getCompilationHooks(compilation).loader;
|
|
77
|
+
loader.tap('CypressCTPlugin', this.addLoaderContext);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Webpack 4
|
|
81
|
+
compilation.hooks.normalModuleLoader.tap('CypressCTPlugin', this.addLoaderContext);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.files = options.files;
|
|
85
|
+
this.supportFile = options.supportFile;
|
|
86
|
+
this.projectRoot = options.projectRoot;
|
|
87
|
+
this.devServerEvents = options.devServerEvents;
|
|
88
|
+
this.webpack = options.webpack;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The plugin's entrypoint, called once by webpack when the compiler is initialized.
|
|
92
|
+
*/
|
|
93
|
+
apply(compiler) {
|
|
94
|
+
const _compiler = compiler;
|
|
95
|
+
this.devServerEvents.on('dev-server:specs:changed', this.onSpecsChange);
|
|
96
|
+
_compiler.hooks.beforeCompile.tapAsync('CypressCTPlugin', this.beforeCompile);
|
|
97
|
+
_compiler.hooks.compilation.tap('CypressCTPlugin', (compilation) => this.addCompilationHooks(compilation));
|
|
98
|
+
_compiler.hooks.done.tap('CypressCTPlugin', () => {
|
|
99
|
+
this.devServerEvents.emit('dev-server:compile:success');
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.CypressCTWebpackPlugin = CypressCTWebpackPlugin;
|
package/dist/aut-runner.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.init = void 0;
|
|
5
5
|
function init(importPromises, parent = (window.opener || window.parent)) {
|
|
6
|
+
// @ts-expect-error
|
|
6
7
|
const Cypress = window.Cypress = parent.Cypress;
|
|
7
8
|
if (!Cypress) {
|
|
8
9
|
throw new Error('Tests cannot run without a reference to Cypress!');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const configFiles: string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { WebpackDevServerConfig } from './devServer';
|
|
2
|
+
import type { SourceRelativeWebpackResult } from './helpers/sourceRelativeWebpackModules';
|
|
3
|
+
/**
|
|
4
|
+
* Takes the webpack / webpackDevServer modules, the configuration provide
|
|
5
|
+
* from the framework override (if any), and the configuration provided
|
|
6
|
+
* from the user config (if any) and makes the final config we want to
|
|
7
|
+
* serve into webpack
|
|
8
|
+
*/
|
|
9
|
+
export interface CreateFinalWebpackConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Initial config passed to devServer
|
|
12
|
+
*/
|
|
13
|
+
devServerConfig: WebpackDevServerConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Result of sourcing the webpack from the
|
|
16
|
+
*/
|
|
17
|
+
sourceWebpackModulesResult: SourceRelativeWebpackResult;
|
|
18
|
+
/**
|
|
19
|
+
* Framework-specific config overrides
|
|
20
|
+
*/
|
|
21
|
+
frameworkConfig?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export declare function createWebpackDevServer(config: CreateFinalWebpackConfig): Promise<{
|
|
24
|
+
server: unknown;
|
|
25
|
+
compiler: object;
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebpackDevServer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
6
|
+
const makeWebpackConfig_1 = require("./makeWebpackConfig");
|
|
7
|
+
const debug = (0, debug_1.default)('cypress:webpack-dev-server:start');
|
|
8
|
+
async function createWebpackDevServer(config) {
|
|
9
|
+
const { sourceWebpackModulesResult: { webpack: { module: webpack, }, webpackDevServer: { majorVersion: webpackDevServerMajorVersion, }, }, } = config;
|
|
10
|
+
const finalWebpackConfig = await (0, makeWebpackConfig_1.makeWebpackConfig)(config);
|
|
11
|
+
const webpackCompiler = webpack(finalWebpackConfig);
|
|
12
|
+
if (webpackDevServerMajorVersion === 4) {
|
|
13
|
+
debug('using webpack-dev-server v4');
|
|
14
|
+
return webpackDevServer4(config, webpackCompiler, finalWebpackConfig);
|
|
15
|
+
}
|
|
16
|
+
if (webpackDevServerMajorVersion === 3) {
|
|
17
|
+
debug('using webpack-dev-server v4');
|
|
18
|
+
return webpackDevServer3(config, webpackCompiler, finalWebpackConfig);
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Unsupported webpackDevServer version ${webpackDevServerMajorVersion}`);
|
|
21
|
+
}
|
|
22
|
+
exports.createWebpackDevServer = createWebpackDevServer;
|
|
23
|
+
function webpackDevServer4(config, compiler, finalWebpackConfig) {
|
|
24
|
+
var _a;
|
|
25
|
+
const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
|
|
26
|
+
const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
|
|
27
|
+
const webpackDevServerConfig = Object.assign(Object.assign({ host: '127.0.0.1', port: 'auto' }, finalWebpackConfig === null || finalWebpackConfig === void 0 ? void 0 : finalWebpackConfig.devServer), { devMiddleware: {
|
|
28
|
+
publicPath: devServerPublicPathRoute,
|
|
29
|
+
stats: (_a = finalWebpackConfig.stats) !== null && _a !== void 0 ? _a : 'minimal',
|
|
30
|
+
}, hot: false });
|
|
31
|
+
const server = new WebpackDevServer(webpackDevServerConfig, compiler);
|
|
32
|
+
return {
|
|
33
|
+
server,
|
|
34
|
+
compiler,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function webpackDevServer3(config, compiler, finalWebpackConfig) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
|
|
40
|
+
const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
|
|
41
|
+
const webpackDevServerConfig = Object.assign(Object.assign({}, (_a = finalWebpackConfig.devServer) !== null && _a !== void 0 ? _a : {}), { hot: false,
|
|
42
|
+
// @ts-ignore ignore webpack-dev-server v3 type errors
|
|
43
|
+
inline: false, publicPath: devServerPublicPathRoute, noInfo: false, stats: (_b = finalWebpackConfig.stats) !== null && _b !== void 0 ? _b : 'minimal' });
|
|
44
|
+
const server = new WebpackDevServer(compiler, webpackDevServerConfig);
|
|
45
|
+
return {
|
|
46
|
+
server,
|
|
47
|
+
compiler,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { Configuration } from 'webpack';
|
|
4
|
+
import { SourceRelativeWebpackResult } from './helpers/sourceRelativeWebpackModules';
|
|
5
|
+
export declare type WebpackDevServerConfig = {
|
|
6
|
+
specs: Cypress.Spec[];
|
|
7
|
+
cypressConfig: Cypress.PluginConfigOptions;
|
|
8
|
+
devServerEvents: NodeJS.EventEmitter;
|
|
9
|
+
onConfigNotFound?: (devServer: 'webpack', cwd: string, lookedIn: string[]) => void;
|
|
10
|
+
} & {
|
|
11
|
+
framework?: typeof ALL_FRAMEWORKS[number];
|
|
12
|
+
webpackConfig?: unknown;
|
|
13
|
+
};
|
|
14
|
+
declare const ALL_FRAMEWORKS: readonly ["create-react-app", "nuxt", "react", "vue-cli", "next", "vue"];
|
|
15
|
+
/**
|
|
16
|
+
* import { devServer } from '@cypress/webpack-dev-server'
|
|
17
|
+
*
|
|
18
|
+
* Creates & returns a WebpackDevServer for serving files related
|
|
19
|
+
* to Cypress Component Testing
|
|
20
|
+
*
|
|
21
|
+
* @param config
|
|
22
|
+
*/
|
|
23
|
+
export declare function devServer(devServerConfig: WebpackDevServerConfig): Promise<Cypress.ResolvedDevServerConfig>;
|
|
24
|
+
export declare namespace devServer {
|
|
25
|
+
var create: (devServerConfig: WebpackDevServerConfig) => Promise<{
|
|
26
|
+
server: unknown;
|
|
27
|
+
compiler: object;
|
|
28
|
+
version: 4 | 3;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
export declare type PresetHandlerResult = {
|
|
32
|
+
frameworkConfig?: Configuration;
|
|
33
|
+
sourceWebpackModulesResult: SourceRelativeWebpackResult;
|
|
34
|
+
};
|
|
35
|
+
export default devServer;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference types="cypress" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.devServer = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const createWebpackDevServer_1 = require("./createWebpackDevServer");
|
|
7
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
8
|
+
const vueCliHandler_1 = require("./helpers/vueCliHandler");
|
|
9
|
+
const nuxtHandler_1 = require("./helpers/nuxtHandler");
|
|
10
|
+
const createReactAppHandler_1 = require("./helpers/createReactAppHandler");
|
|
11
|
+
const nextHandler_1 = require("./helpers/nextHandler");
|
|
12
|
+
const sourceRelativeWebpackModules_1 = require("./helpers/sourceRelativeWebpackModules");
|
|
13
|
+
const debug = (0, debug_1.default)('cypress:webpack-dev-server:devServer');
|
|
14
|
+
const ALL_FRAMEWORKS = ['create-react-app', 'nuxt', 'react', 'vue-cli', 'next', 'vue'];
|
|
15
|
+
/**
|
|
16
|
+
* import { devServer } from '@cypress/webpack-dev-server'
|
|
17
|
+
*
|
|
18
|
+
* Creates & returns a WebpackDevServer for serving files related
|
|
19
|
+
* to Cypress Component Testing
|
|
20
|
+
*
|
|
21
|
+
* @param config
|
|
22
|
+
*/
|
|
23
|
+
function devServer(devServerConfig) {
|
|
24
|
+
return new Promise(async (resolve, reject) => {
|
|
25
|
+
const result = await devServer.create(devServerConfig);
|
|
26
|
+
if (result.version === 3) {
|
|
27
|
+
const srv = result.server.listen(0, '127.0.0.1', () => {
|
|
28
|
+
const port = srv.address().port;
|
|
29
|
+
debug('Component testing webpack server 3 started on port %s', port);
|
|
30
|
+
resolve({
|
|
31
|
+
port,
|
|
32
|
+
// Close is for unit testing only. We kill this child process which will handle the closing of the server
|
|
33
|
+
close: (done) => {
|
|
34
|
+
srv.close((err) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
debug('closing dev server, with error', err);
|
|
37
|
+
}
|
|
38
|
+
debug('closed dev server');
|
|
39
|
+
done === null || done === void 0 ? void 0 : done(err);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
result.server.start().then(() => {
|
|
47
|
+
if (!result.server.options.port) {
|
|
48
|
+
return reject(new Error(`Expected port ${result.server.options.port} to be a number`));
|
|
49
|
+
}
|
|
50
|
+
debug('Component testing webpack server 4 started on port %s', result.server.options.port);
|
|
51
|
+
resolve({
|
|
52
|
+
port: result.server.options.port,
|
|
53
|
+
// Close is for unit testing only. We kill this child process which will handle the closing of the server
|
|
54
|
+
close: async (done) => {
|
|
55
|
+
debug('closing dev server');
|
|
56
|
+
result.server.stop().then(() => done === null || done === void 0 ? void 0 : done()).catch(done).finally(() => {
|
|
57
|
+
debug('closed dev server');
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}).catch(reject);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.devServer = devServer;
|
|
65
|
+
async function getPreset(devServerConfig) {
|
|
66
|
+
switch (devServerConfig.framework) {
|
|
67
|
+
case 'create-react-app':
|
|
68
|
+
return (0, createReactAppHandler_1.createReactAppHandler)(devServerConfig);
|
|
69
|
+
case 'nuxt':
|
|
70
|
+
return await (0, nuxtHandler_1.nuxtHandler)(devServerConfig);
|
|
71
|
+
case 'vue-cli':
|
|
72
|
+
return (0, vueCliHandler_1.vueCliHandler)(devServerConfig);
|
|
73
|
+
case 'next':
|
|
74
|
+
return await (0, nextHandler_1.nextHandler)(devServerConfig);
|
|
75
|
+
case 'react':
|
|
76
|
+
case 'vue':
|
|
77
|
+
case undefined:
|
|
78
|
+
return { sourceWebpackModulesResult: (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig) };
|
|
79
|
+
default:
|
|
80
|
+
throw new Error(`Unexpected framework ${devServerConfig.framework}, expected one of ${ALL_FRAMEWORKS.join(', ')}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Synchronously create the webpack server instance, without starting.
|
|
85
|
+
* Useful for testing
|
|
86
|
+
*
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
devServer.create = async function (devServerConfig) {
|
|
90
|
+
const { frameworkConfig, sourceWebpackModulesResult } = await getPreset(devServerConfig);
|
|
91
|
+
const { server, compiler } = await (0, createWebpackDevServer_1.createWebpackDevServer)({
|
|
92
|
+
devServerConfig,
|
|
93
|
+
frameworkConfig,
|
|
94
|
+
sourceWebpackModulesResult,
|
|
95
|
+
});
|
|
96
|
+
const result = {
|
|
97
|
+
server,
|
|
98
|
+
compiler,
|
|
99
|
+
version: sourceWebpackModulesResult.webpackDevServer.majorVersion,
|
|
100
|
+
};
|
|
101
|
+
return result;
|
|
102
|
+
};
|
|
103
|
+
exports.default = devServer;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Configuration } from 'webpack';
|
|
2
|
+
import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
|
|
3
|
+
/**
|
|
4
|
+
* Sourcing the config for create-react-app
|
|
5
|
+
*/
|
|
6
|
+
export declare function createReactAppHandler(devServerConfig: WebpackDevServerConfig): PresetHandlerResult;
|
|
7
|
+
export declare const cypressGlobals: string[];
|
|
8
|
+
export declare function reactScriptsFiveModifications(webpackConfig: Configuration): void;
|