@cypress/webpack-dev-server 1.8.4 → 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.
Files changed (41) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +47 -81
  3. package/dist/CypressCTWebpackPlugin.d.ts +15 -0
  4. package/dist/CypressCTWebpackPlugin.js +103 -0
  5. package/dist/aut-runner.js +1 -0
  6. package/dist/constants.d.ts +1 -0
  7. package/dist/constants.js +9 -0
  8. package/dist/createWebpackDevServer.d.ts +26 -0
  9. package/dist/createWebpackDevServer.js +49 -0
  10. package/dist/devServer.d.ts +35 -0
  11. package/dist/devServer.js +103 -0
  12. package/dist/helpers/createReactAppHandler.d.ts +8 -0
  13. package/dist/helpers/createReactAppHandler.js +300 -0
  14. package/dist/helpers/nextHandler.d.ts +2 -0
  15. package/dist/helpers/nextHandler.js +197 -0
  16. package/dist/helpers/nuxtHandler.d.ts +2 -0
  17. package/dist/helpers/nuxtHandler.js +27 -0
  18. package/dist/helpers/sourceRelativeWebpackModules.d.ts +46 -0
  19. package/dist/helpers/sourceRelativeWebpackModules.js +197 -0
  20. package/dist/helpers/vueCliHandler.d.ts +2 -0
  21. package/dist/helpers/vueCliHandler.js +23 -0
  22. package/dist/index.d.ts +3 -15
  23. package/dist/index.js +4 -63
  24. package/dist/loader.d.ts +1 -3
  25. package/dist/loader.js +8 -28
  26. package/dist/makeDefaultWebpackConfig.d.ts +1 -0
  27. package/dist/makeDefaultWebpackConfig.js +48 -0
  28. package/dist/makeWebpackConfig.d.ts +6 -16
  29. package/dist/makeWebpackConfig.js +120 -93
  30. package/dist/measureWebpackPerformance.d.ts +1 -2
  31. package/dist/measureWebpackPerformance.js +10 -8
  32. package/package.json +34 -26
  33. package/dist/plugin.d.ts +0 -45
  34. package/dist/plugin.js +0 -84
  35. package/dist/startServer.d.ts +0 -13
  36. package/dist/startServer.js +0 -75
  37. package/dist/webpack.config.d.ts +0 -2
  38. package/dist/webpack.config.js +0 -24
  39. package/dist/webpackDevServerFacts.d.ts +0 -6
  40. package/dist/webpackDevServerFacts.js +0 -19
  41. package/index-template.html +0 -12
package/CHANGELOG.md CHANGED
@@ -1,3 +1,40 @@
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
+
1
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)
2
39
 
3
40
 
package/README.md CHANGED
@@ -1,98 +1,64 @@
1
1
  # @cypress/webpack-dev-server
2
2
 
3
- > **Note** this package is not meant to be used outside of cypress component testing.
4
-
5
- Install `@cypress/vue` or `@cypress/react` to get this package working properly
6
-
7
- To install `@cypress/webpack-dev-server` in you component testing environment,
8
- 1. Install it `yarn add @cypress/webpack-dev-server`
9
- 2. Add it to `cypress/plugins/index.js`
10
-
11
- ```js
12
- import { startDevServer } from '@cypress/webpack-dev-server'
13
-
14
- module.exports = (on, config) => {
15
- on('dev-server:start', async (options) => startDevServer({ options }))
16
-
17
- return config
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
- ## Architecture
22
-
23
- ### Cypress server
24
-
25
- - Every HTTP request goes to the cypress server which returns an html page. We call "TOP" because of its name in the dev tools
26
- This page
27
- - renders the list of spec files
28
- - And the timetraveling command log
29
- - Finally, it renders an AUT Iframe. this iframe calls a url that has 2 parts concatenated.
30
- - a prefix: `__cypress/iframes/`
31
- - the path to the current. For example: `src/components/button.spec.tsx`
32
- - In the cypress server, calls prefixed with `__cypress/iframes/...` will be passed to the dev-server as `__cypress/src/index.html`
33
- - Every call with the prefix `__cypress/src/` will be passed to the dev-server to deal as is, without changes.
34
-
35
- ### Dev-server
36
-
37
- - Responds to every query with the prefix `__cypress/src/` (base path should be this prefix).
38
- - Responds to `__cypress/src/index.html` with an html page.
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
- ## Performance tests
40
+ ## Testing
72
41
 
73
- In order to get webpack performance statistics run `yarn cypress open-ct` or `yarn cypress run-ct` with `WEBPACK_PERF_MEASURE` env variable:
42
+ Unit tests can be run with `npm test`. Integration tests can be run with `yarn cypress:run`
74
43
 
75
- ```sh
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
- This will output the timings of whole webpack output and timings for each specified plugin and loader.
46
+ `webpack${major}_wds${devServerMajor}-$framework{-$variant}`
80
47
 
81
- ### Compare results
48
+ - webpack4_wds3-react
49
+ - webpack4_wds4-next-11
50
+ - webpack5_wds3-next-12
51
+ - webpack4_wds4-create-react-app
82
52
 
83
- In order to run performance tests and compare timings with the previous build run:
53
+ ## Architecture
84
54
 
85
- ```sh
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
- This will create the file `./__perf-stats/{name-of-project}.json` or if this file exists will compare results with the previously saved version.
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
- In order to update the `{name-of-project}.json` file and use new stats as a base for the next comparisons run:
59
+ From there, we check the "framework" field to source or define any known webpack transforms to aid in the compilation.
92
60
 
93
- ```sh
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;
@@ -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,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configFiles = void 0;
4
+ exports.configFiles = [
5
+ 'webpack.config.ts',
6
+ 'webpack.config.js',
7
+ 'webpack.config.mjs',
8
+ 'webpack.config.cjs',
9
+ ];
@@ -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;