@cypress/webpack-dev-server 1.8.4 → 2.2.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 (43) hide show
  1. package/README.md +54 -75
  2. package/dist/CypressCTWebpackPlugin.d.ts +15 -0
  3. package/dist/CypressCTWebpackPlugin.js +105 -0
  4. package/dist/aut-runner.js +1 -0
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.js +9 -0
  7. package/dist/createWebpackDevServer.d.ts +26 -0
  8. package/dist/createWebpackDevServer.js +49 -0
  9. package/dist/devServer.d.ts +35 -0
  10. package/dist/devServer.js +106 -0
  11. package/dist/helpers/angularHandler.d.ts +80 -0
  12. package/dist/helpers/angularHandler.js +131 -0
  13. package/dist/helpers/createReactAppHandler.d.ts +8 -0
  14. package/dist/helpers/createReactAppHandler.js +300 -0
  15. package/dist/helpers/nextHandler.d.ts +3 -0
  16. package/dist/helpers/nextHandler.js +236 -0
  17. package/dist/helpers/nuxtHandler.d.ts +2 -0
  18. package/dist/helpers/nuxtHandler.js +27 -0
  19. package/dist/helpers/sourceRelativeWebpackModules.d.ts +46 -0
  20. package/dist/helpers/sourceRelativeWebpackModules.js +211 -0
  21. package/dist/helpers/vueCliHandler.d.ts +2 -0
  22. package/dist/helpers/vueCliHandler.js +23 -0
  23. package/dist/index.d.ts +3 -15
  24. package/dist/index.js +4 -63
  25. package/dist/loader.d.ts +1 -3
  26. package/dist/loader.js +8 -28
  27. package/dist/makeDefaultWebpackConfig.d.ts +1 -0
  28. package/dist/makeDefaultWebpackConfig.js +45 -0
  29. package/dist/makeWebpackConfig.d.ts +7 -16
  30. package/dist/makeWebpackConfig.js +127 -94
  31. package/dist/measureWebpackPerformance.d.ts +1 -2
  32. package/dist/measureWebpackPerformance.js +11 -8
  33. package/package.json +34 -26
  34. package/CHANGELOG.md +0 -188
  35. package/dist/plugin.d.ts +0 -45
  36. package/dist/plugin.js +0 -84
  37. package/dist/startServer.d.ts +0 -13
  38. package/dist/startServer.js +0 -75
  39. package/dist/webpack.config.d.ts +0 -2
  40. package/dist/webpack.config.js +0 -24
  41. package/dist/webpackDevServerFacts.d.ts +0 -6
  42. package/dist/webpackDevServerFacts.js +0 -19
  43. package/index-template.html +0 -12
package/README.md CHANGED
@@ -1,99 +1,78 @@
1
1
  # @cypress/webpack-dev-server
2
2
 
3
- > **Note** this package is not meant to be used outside of cypress component testing.
3
+ Implements the APIs for the object-syntax of the Cypress Component-testing "webpack dev server".
4
4
 
5
- Install `@cypress/vue` or `@cypress/react` to get this package working properly
5
+ > **Note:** This package is bundled with the Cypress binary and should not need to be installed separately. See the [Component Framework Configuration Docs](https://docs.cypress.io/guides/component-testing/component-framework-configuration) for setting up component testing with webpack. The `devServer` function signature is for advanced use-cases.
6
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`
7
+ Object API:
10
8
 
11
- ```js
12
- import { startDevServer } from '@cypress/webpack-dev-server'
9
+ ```ts
10
+ import { defineConfig } from 'cypress'
13
11
 
14
- module.exports = (on, config) => {
15
- on('dev-server:start', async (options) => startDevServer({ options }))
16
-
17
- return config
18
- }
12
+ export default defineConfig({
13
+ component: {
14
+ devServer: {
15
+ framework: 'create-react-app',
16
+ bundler: 'webpack',
17
+ // webpackConfig?: Will try to infer, if passed it will be used as is
18
+ }
19
+ }
20
+ })
19
21
  ```
20
22
 
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
23
+ Function API:
24
+
25
+ ```ts
26
+ import { devServer } from '@cypress/webpack-dev-server'
27
+ import { defineConfig } from 'cypress'
28
+
29
+ export default defineConfig({
30
+ component: {
31
+ devServer(devServerConfig) {
32
+ return devServer({
33
+ ...devServerConfig,
34
+ framework: 'create-react-app',
35
+ webpackConfig: require('./webpack.config.js')
36
+ })
37
+ }
38
+ }
39
+ })
40
+ ```
48
41
 
49
- Webpack-dev-server fulfills his responsibilities by
42
+ ## Testing
50
43
 
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
44
+ Unit tests can be run with `yarn test`. Integration tests can be run with `yarn cypress:run`
60
45
 
61
- ## API
46
+ This module should be primarily covered by system-tests / open-mode tests. All system-tests directories should be created using the notation:
62
47
 
63
- `startDevServer` takes an object of options.
48
+ `webpack${major}_wds${devServerMajor}-$framework{-$variant}`
64
49
 
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).
50
+ - webpack4_wds3-react
51
+ - webpack4_wds4-next-11
52
+ - webpack5_wds3-next-12
53
+ - webpack4_wds4-create-react-app
68
54
 
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.
55
+ ## Architecture
70
56
 
71
- ## Performance tests
57
+ 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.
72
58
 
73
- In order to get webpack performance statistics run `yarn cypress open-ct` or `yarn cypress run-ct` with `WEBPACK_PERF_MEASURE` env variable:
59
+ 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.
74
60
 
75
- ```sh
76
- WEBPACK_PERF_MEASURE=true yarn cypress run-ct
77
- ```
61
+ From there, we check the "framework" field to source or define any known webpack transforms to aid in the compilation.
78
62
 
79
- This will output the timings of whole webpack output and timings for each specified plugin and loader.
63
+ 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.
80
64
 
81
- ### Compare results
65
+ ## Compatibility
82
66
 
83
- In order to run performance tests and compare timings with the previous build run:
67
+ | @cypress/webpack-dev-server | cypress |
68
+ | --------------------------- | ------- |
69
+ | <= v1 | <= v9 |
70
+ | >= v2 | >= v10 |
84
71
 
85
- ```sh
86
- WEBPACK_PERF_MEASURE=true WEBPACK_PERF_MEASURE_COMPARE={name-of-project} yarn cypress run-ct
87
- ```
72
+ ## License
88
73
 
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.
90
-
91
- In order to update the `{name-of-project}.json` file and use new stats as a base for the next comparisons run:
92
-
93
- ```sh
94
- WEBPACK_PERF_MEASURE=true WEBPACK_PERF_MEASURE_UPDATE=true WEBPACK_PERF_MEASURE_COMPARE={name-of-project} yarn cypress run-ct
95
- ```
74
+ [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/master/LICENSE)
96
75
 
97
- ## Changelog
76
+ This project is licensed under the terms of the [MIT license](/LICENSE).
98
77
 
99
- [Changelog](./CHANGELOG.md)
78
+ ## [Changelog](./CHANGELOG.md)
@@ -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,105 @@
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 = async (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
+ // TODO: don't use a sync fs method here
62
+ // eslint-disable-next-line no-restricted-syntax
63
+ const utimesSync = (_a = inputFileSystem.fileSystem.utimesSync) !== null && _a !== void 0 ? _a : fs_extra_1.default.utimesSync;
64
+ utimesSync(path_1.default.resolve(__dirname, 'browser.js'), new Date(), new Date());
65
+ };
66
+ /**
67
+ * The webpack compiler generates a new `compilation` each time it compiles, so
68
+ * we have to apply hooks to it fresh each time
69
+ *
70
+ * @param compilation webpack 4 `compilation.Compilation`, webpack 5
71
+ * `Compilation`
72
+ */
73
+ this.addCompilationHooks = (compilation) => {
74
+ this.compilation = compilation;
75
+ /* istanbul ignore next */
76
+ if ('NormalModule' in this.webpack) {
77
+ // Webpack 5
78
+ const loader = this.webpack.NormalModule.getCompilationHooks(compilation).loader;
79
+ loader.tap('CypressCTPlugin', this.addLoaderContext);
80
+ }
81
+ else {
82
+ // Webpack 4
83
+ compilation.hooks.normalModuleLoader.tap('CypressCTPlugin', this.addLoaderContext);
84
+ }
85
+ };
86
+ this.files = options.files;
87
+ this.supportFile = options.supportFile;
88
+ this.projectRoot = options.projectRoot;
89
+ this.devServerEvents = options.devServerEvents;
90
+ this.webpack = options.webpack;
91
+ }
92
+ /**
93
+ * The plugin's entrypoint, called once by webpack when the compiler is initialized.
94
+ */
95
+ apply(compiler) {
96
+ const _compiler = compiler;
97
+ this.devServerEvents.on('dev-server:specs:changed', this.onSpecsChange);
98
+ _compiler.hooks.beforeCompile.tapAsync('CypressCTPlugin', this.beforeCompile);
99
+ _compiler.hooks.compilation.tap('CypressCTPlugin', (compilation) => this.addCompilationHooks(compilation));
100
+ _compiler.hooks.done.tap('CypressCTPlugin', () => {
101
+ this.devServerEvents.emit('dev-server:compile:success');
102
+ });
103
+ }
104
+ }
105
+ 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 v3');
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
+ export declare const ALL_FRAMEWORKS: readonly ["create-react-app", "nuxt", "react", "vue-cli", "next", "vue", "angular"];
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,106 @@
1
+ "use strict";
2
+ /// <reference types="cypress" />
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.devServer = exports.ALL_FRAMEWORKS = 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 angularHandler_1 = require("./helpers/angularHandler");
14
+ const debug = (0, debug_1.default)('cypress:webpack-dev-server:devServer');
15
+ exports.ALL_FRAMEWORKS = ['create-react-app', 'nuxt', 'react', 'vue-cli', 'next', 'vue', 'angular'];
16
+ /**
17
+ * import { devServer } from '@cypress/webpack-dev-server'
18
+ *
19
+ * Creates & returns a WebpackDevServer for serving files related
20
+ * to Cypress Component Testing
21
+ *
22
+ * @param config
23
+ */
24
+ function devServer(devServerConfig) {
25
+ return new Promise(async (resolve, reject) => {
26
+ const result = await devServer.create(devServerConfig);
27
+ if (result.version === 3) {
28
+ const srv = result.server.listen(0, '127.0.0.1', () => {
29
+ const port = srv.address().port;
30
+ debug('Component testing webpack server 3 started on port %s', port);
31
+ resolve({
32
+ port,
33
+ // Close is for unit testing only. We kill this child process which will handle the closing of the server
34
+ close: (done) => {
35
+ srv.close((err) => {
36
+ if (err) {
37
+ debug('closing dev server, with error', err);
38
+ }
39
+ debug('closed dev server');
40
+ done === null || done === void 0 ? void 0 : done(err);
41
+ });
42
+ },
43
+ });
44
+ });
45
+ return;
46
+ }
47
+ result.server.start().then(() => {
48
+ if (!result.server.options.port) {
49
+ return reject(new Error(`Expected port ${result.server.options.port} to be a number`));
50
+ }
51
+ debug('Component testing webpack server 4 started on port %s', result.server.options.port);
52
+ resolve({
53
+ port: result.server.options.port,
54
+ // Close is for unit testing only. We kill this child process which will handle the closing of the server
55
+ close: async (done) => {
56
+ debug('closing dev server');
57
+ result.server.stop().then(() => done === null || done === void 0 ? void 0 : done()).catch(done).finally(() => {
58
+ debug('closed dev server');
59
+ });
60
+ },
61
+ });
62
+ }).catch(reject);
63
+ });
64
+ }
65
+ exports.devServer = devServer;
66
+ async function getPreset(devServerConfig) {
67
+ switch (devServerConfig.framework) {
68
+ case 'create-react-app':
69
+ return (0, createReactAppHandler_1.createReactAppHandler)(devServerConfig);
70
+ case 'nuxt':
71
+ return await (0, nuxtHandler_1.nuxtHandler)(devServerConfig);
72
+ case 'vue-cli':
73
+ return (0, vueCliHandler_1.vueCliHandler)(devServerConfig);
74
+ case 'next':
75
+ return await (0, nextHandler_1.nextHandler)(devServerConfig);
76
+ case 'angular':
77
+ return await (0, angularHandler_1.angularHandler)(devServerConfig);
78
+ case 'react':
79
+ case 'vue':
80
+ case undefined:
81
+ return { sourceWebpackModulesResult: (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig) };
82
+ default:
83
+ throw new Error(`Unexpected framework ${devServerConfig.framework}, expected one of ${exports.ALL_FRAMEWORKS.join(', ')}`);
84
+ }
85
+ }
86
+ /**
87
+ * Synchronously create the webpack server instance, without starting.
88
+ * Useful for testing
89
+ *
90
+ * @internal
91
+ */
92
+ devServer.create = async function (devServerConfig) {
93
+ const { frameworkConfig, sourceWebpackModulesResult } = await getPreset(devServerConfig);
94
+ const { server, compiler } = await (0, createWebpackDevServer_1.createWebpackDevServer)({
95
+ devServerConfig,
96
+ frameworkConfig,
97
+ sourceWebpackModulesResult,
98
+ });
99
+ const result = {
100
+ server,
101
+ compiler,
102
+ version: sourceWebpackModulesResult.webpackDevServer.majorVersion,
103
+ };
104
+ return result;
105
+ };
106
+ exports.default = devServer;
@@ -0,0 +1,80 @@
1
+ import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
2
+ export declare type AngularJsonProjectConfig = {
3
+ projectType: string;
4
+ root: string;
5
+ sourceRoot: string;
6
+ architect: {
7
+ build: {
8
+ options: {
9
+ [key: string]: any;
10
+ } & {
11
+ polyfills?: string;
12
+ };
13
+ configurations?: {
14
+ [configuration: string]: {
15
+ [key: string]: any;
16
+ };
17
+ };
18
+ };
19
+ };
20
+ };
21
+ declare type AngularJson = {
22
+ defaultProject?: string;
23
+ projects: {
24
+ [project: string]: AngularJsonProjectConfig;
25
+ };
26
+ };
27
+ export declare function angularHandler(devServerConfig: WebpackDevServerConfig): Promise<PresetHandlerResult>;
28
+ export declare function getAngularBuildOptions(projectConfig: AngularJsonProjectConfig, tsConfig: string): {
29
+ tsConfig: string;
30
+ aot: boolean;
31
+ outputHashing: string;
32
+ budgets: undefined;
33
+ polyfills?: string | undefined;
34
+ outputPath: string;
35
+ assets: never[];
36
+ styles: never[];
37
+ scripts: never[];
38
+ fileReplacements: never[];
39
+ inlineStyleLanguage: string;
40
+ stylePreprocessorOptions: {
41
+ includePaths: never[];
42
+ };
43
+ resourcesOutputPath: undefined;
44
+ commonChunk: boolean;
45
+ baseHref: undefined;
46
+ deployUrl: undefined;
47
+ verbose: boolean;
48
+ progress: boolean;
49
+ i18nMissingTranslation: string;
50
+ i18nDuplicateTranslation: string;
51
+ localize: undefined;
52
+ watch: boolean;
53
+ poll: undefined;
54
+ deleteOutputPath: boolean;
55
+ preserveSymlinks: undefined;
56
+ showCircularDependencies: boolean;
57
+ subresourceIntegrity: boolean;
58
+ serviceWorker: boolean;
59
+ ngswConfigPath: undefined;
60
+ statsJson: boolean;
61
+ webWorkerTsConfig: undefined;
62
+ crossOrigin: string;
63
+ allowedCommonJsDependencies: never[];
64
+ buildOptimizer: boolean;
65
+ optimization: boolean;
66
+ vendorChunk: boolean;
67
+ extractLicenses: boolean;
68
+ sourceMap: boolean;
69
+ namedChunks: boolean;
70
+ };
71
+ export declare function generateTsConfig(devServerConfig: WebpackDevServerConfig, projectConfig: AngularJsonProjectConfig): Promise<string>;
72
+ export declare function getTempDir(): Promise<string>;
73
+ export declare function getAngularCliModules(projectRoot: string): Promise<{
74
+ generateBrowserWebpackConfigFromContext: any;
75
+ getCommonConfig: any;
76
+ getStylesConfig: any;
77
+ }>;
78
+ export declare function getAngularJson(projectRoot: string): Promise<AngularJson>;
79
+ export declare const toPosix: (filePath: string) => string;
80
+ export {};