@cypress/webpack-dev-server 2.3.0 → 2.4.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 CHANGED
@@ -71,7 +71,7 @@ We then merge the sourced config with the user's webpack config, and layer on ou
71
71
 
72
72
  ## License
73
73
 
74
- [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/master/LICENSE)
74
+ [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/develop/LICENSE)
75
75
 
76
76
  This project is licensed under the terms of the [MIT license](/LICENSE).
77
77
 
@@ -23,11 +23,14 @@ exports.createWebpackDevServer = createWebpackDevServer;
23
23
  function webpackDevServer4(config, compiler, finalWebpackConfig) {
24
24
  var _a;
25
25
  const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
26
+ const isOpenMode = !config.devServerConfig.cypressConfig.isTextTerminal;
26
27
  const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
27
28
  const webpackDevServerConfig = Object.assign(Object.assign({ host: '127.0.0.1', port: 'auto' }, finalWebpackConfig === null || finalWebpackConfig === void 0 ? void 0 : finalWebpackConfig.devServer), { devMiddleware: {
28
29
  publicPath: devServerPublicPathRoute,
29
30
  stats: (_a = finalWebpackConfig.stats) !== null && _a !== void 0 ? _a : 'minimal',
30
- }, hot: false });
31
+ }, hot: false,
32
+ // Only enable file watching & reload when executing tests in `open` mode
33
+ liveReload: isOpenMode });
31
34
  const server = new WebpackDevServer(webpackDevServerConfig, compiler);
32
35
  return {
33
36
  server,
@@ -37,10 +40,13 @@ function webpackDevServer4(config, compiler, finalWebpackConfig) {
37
40
  function webpackDevServer3(config, compiler, finalWebpackConfig) {
38
41
  var _a, _b;
39
42
  const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config;
43
+ const isOpenMode = !config.devServerConfig.cypressConfig.isTextTerminal;
40
44
  const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module;
41
45
  const webpackDevServerConfig = Object.assign(Object.assign({}, (_a = finalWebpackConfig.devServer) !== null && _a !== void 0 ? _a : {}), { hot: false,
42
46
  // @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' });
47
+ inline: false, publicPath: devServerPublicPathRoute, noInfo: false, stats: (_b = finalWebpackConfig.stats) !== null && _b !== void 0 ? _b : 'minimal',
48
+ // Only enable file watching & reload when executing tests in `open` mode
49
+ liveReload: isOpenMode });
44
50
  const server = new WebpackDevServer(compiler, webpackDevServerConfig);
45
51
  return {
46
52
  server,
@@ -14,12 +14,13 @@ declare type FrameworkConfig = {
14
14
  projectConfig: Cypress.AngularDevServerProjectConfig;
15
15
  };
16
16
  };
17
+ export declare type ConfigHandler = Partial<Configuration> | (() => Partial<Configuration> | Promise<Partial<Configuration>>);
17
18
  export declare type WebpackDevServerConfig = {
18
19
  specs: Cypress.Spec[];
19
20
  cypressConfig: Cypress.PluginConfigOptions;
20
21
  devServerEvents: NodeJS.EventEmitter;
21
22
  onConfigNotFound?: (devServer: 'webpack', cwd: string, lookedIn: string[]) => void;
22
- webpackConfig?: unknown;
23
+ webpackConfig?: ConfigHandler;
23
24
  } & FrameworkConfig;
24
25
  /**
25
26
  * import { devServer } from '@cypress/webpack-dev-server'
package/dist/devServer.js CHANGED
@@ -69,7 +69,7 @@ async function getPreset(devServerConfig) {
69
69
  case 'nuxt':
70
70
  return await (0, nuxtHandler_1.nuxtHandler)(devServerConfig);
71
71
  case 'vue-cli':
72
- return (0, vueCliHandler_1.vueCliHandler)(devServerConfig);
72
+ return await (0, vueCliHandler_1.vueCliHandler)(devServerConfig);
73
73
  case 'next':
74
74
  return await (0, nextHandler_1.nextHandler)(devServerConfig);
75
75
  case 'angular':
@@ -36,6 +36,7 @@ function getAngularBuildOptions(buildOptions, tsConfig) {
36
36
  }
37
37
  exports.getAngularBuildOptions = getAngularBuildOptions;
38
38
  async function generateTsConfig(devServerConfig, buildOptions) {
39
+ var _a;
39
40
  const { cypressConfig } = devServerConfig;
40
41
  const { projectRoot } = cypressConfig;
41
42
  const specPattern = Array.isArray(cypressConfig.specPattern) ? cypressConfig.specPattern : [cypressConfig.specPattern];
@@ -45,13 +46,15 @@ async function generateTsConfig(devServerConfig, buildOptions) {
45
46
  includePaths.push((0, exports.toPosix)(cypressConfig.supportFile));
46
47
  }
47
48
  if (buildOptions.polyfills) {
48
- const polyfills = getProjectFilePath(buildOptions.polyfills);
49
- includePaths.push(polyfills);
49
+ const polyfills = Array.isArray(buildOptions.polyfills)
50
+ ? buildOptions.polyfills.filter((p) => { var _a, _b; return ((_a = devServerConfig.options) === null || _a === void 0 ? void 0 : _a.projectConfig.sourceRoot) && p.startsWith((_b = devServerConfig.options) === null || _b === void 0 ? void 0 : _b.projectConfig.sourceRoot); })
51
+ : [buildOptions.polyfills];
52
+ includePaths.push(...polyfills.map((p) => getProjectFilePath(p)));
50
53
  }
51
54
  const cypressTypes = getProjectFilePath('node_modules', 'cypress', 'types', 'index.d.ts');
52
55
  includePaths.push(cypressTypes);
53
56
  const tsConfigContent = JSON.stringify({
54
- extends: getProjectFilePath('tsconfig.json'),
57
+ extends: getProjectFilePath((_a = buildOptions.tsConfig) !== null && _a !== void 0 ? _a : 'tsconfig.json'),
55
58
  compilerOptions: {
56
59
  outDir: getProjectFilePath('out-tsc/cy'),
57
60
  allowSyntheticDefaultImports: true,
@@ -104,7 +107,11 @@ async function getAngularJson(projectRoot) {
104
107
  exports.getAngularJson = getAngularJson;
105
108
  function createFakeContext(projectRoot, defaultProjectConfig) {
106
109
  const logger = {
107
- createChild: () => ({}),
110
+ createChild: () => {
111
+ return {
112
+ warn: () => { },
113
+ };
114
+ },
108
115
  };
109
116
  const context = {
110
117
  target: {
@@ -137,8 +144,16 @@ async function getAngularCliWebpackConfig(devServerConfig) {
137
144
  delete config.entry.main;
138
145
  return config;
139
146
  }
147
+ function removeSourceMapPlugin(config) {
148
+ var _a;
149
+ config.plugins = (_a = config.plugins) === null || _a === void 0 ? void 0 : _a.filter((plugin) => {
150
+ var _a;
151
+ return ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.constructor) === null || _a === void 0 ? void 0 : _a.name) !== 'SourceMapDevToolPlugin';
152
+ });
153
+ }
140
154
  async function angularHandler(devServerConfig) {
141
155
  const webpackConfig = await getAngularCliWebpackConfig(devServerConfig);
156
+ removeSourceMapPlugin(webpackConfig);
142
157
  return { frameworkConfig: webpackConfig, sourceWebpackModulesResult: (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig) };
143
158
  }
144
159
  exports.angularHandler = angularHandler;
@@ -1,2 +1,2 @@
1
1
  import type { PresetHandlerResult, WebpackDevServerConfig } from '../devServer';
2
- export declare function vueCliHandler(devServerConfig: WebpackDevServerConfig): PresetHandlerResult;
2
+ export declare function vueCliHandler(devServerConfig: WebpackDevServerConfig): Promise<PresetHandlerResult>;
@@ -5,19 +5,21 @@ const tslib_1 = require("tslib");
5
5
  const debug_1 = tslib_1.__importDefault(require("debug"));
6
6
  const sourceRelativeWebpackModules_1 = require("./sourceRelativeWebpackModules");
7
7
  const debug = (0, debug_1.default)('cypress:webpack-dev-server:vueCliHandler');
8
- function vueCliHandler(devServerConfig) {
8
+ async function vueCliHandler(devServerConfig) {
9
9
  const sourceWebpackModulesResult = (0, sourceRelativeWebpackModules_1.sourceDefaultWebpackDependencies)(devServerConfig);
10
10
  try {
11
- const config = require.resolve('@vue/cli-service/webpack.config', {
11
+ const Service = require(require.resolve('@vue/cli-service', {
12
12
  paths: [devServerConfig.cypressConfig.projectRoot],
13
- });
14
- const webpackConfig = require(config);
13
+ }));
14
+ let service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd());
15
+ await service.init(process.env.VUE_CLI_MODE || process.env.NODE_ENV);
16
+ const webpackConfig = service.resolveWebpackConfig();
15
17
  debug('webpack config %o', webpackConfig);
16
18
  return { frameworkConfig: webpackConfig, sourceWebpackModulesResult };
17
19
  }
18
20
  catch (e) {
19
21
  console.error(e); // eslint-disable-line no-console
20
- throw Error(`Error loading @vue/cli-service/webpack.config.js. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`);
22
+ throw Error(`Error loading @vue/cli-service/lib/Service or resolving WebpackConfig. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`);
21
23
  }
22
24
  }
23
25
  exports.vueCliHandler = vueCliHandler;
package/dist/loader.js CHANGED
@@ -18,7 +18,9 @@ const makeImport = (file, filename, chunkName, projectRoot) => {
18
18
  return `"${filename}": {
19
19
  shouldLoad: () => document.location.pathname.includes("${encodeURI(file.absolute)}"),
20
20
  load: () => import("${file.absolute}" ${magicComments}),
21
- chunkName: "${chunkName}",
21
+ absolute: "${file.absolute.split(path.sep).join(path.posix.sep)}",
22
+ relative: "${file.relative.split(path.sep).join(path.posix.sep)}",
23
+ relativeUrl: "/__cypress/src/${chunkName}.js",
22
24
  }`;
23
25
  };
24
26
  /**
@@ -53,8 +55,8 @@ function loader() {
53
55
  ctx.cacheable(false);
54
56
  const { files, projectRoot, supportFile } = ctx._cypress;
55
57
  const supportFileAbsolutePath = supportFile ? JSON.stringify(path.resolve(projectRoot, supportFile)) : undefined;
56
- return `
57
- var loadSupportFile = ${supportFile ? `() => import(${supportFileAbsolutePath})` : `() => Promise.resolve()`}
58
+ const supportFileRelativePath = supportFile ? JSON.stringify(path.relative(projectRoot, supportFileAbsolutePath || '')) : undefined;
59
+ const result = `
58
60
  var allTheSpecs = ${buildSpecs(projectRoot, files)};
59
61
 
60
62
  var { init } = require(${JSON.stringify(require.resolve('./aut-runner'))})
@@ -62,12 +64,23 @@ function loader() {
62
64
  var scriptLoaders = Object.values(allTheSpecs).reduce(
63
65
  (accSpecLoaders, specLoader) => {
64
66
  if (specLoader.shouldLoad()) {
65
- accSpecLoaders.push(specLoader.load)
67
+ accSpecLoaders.push(specLoader)
66
68
  }
67
69
  return accSpecLoaders
68
- }, [loadSupportFile])
70
+ }, [])
71
+
72
+ if (${!!supportFile}) {
73
+ var supportFile = {
74
+ absolute: ${supportFileAbsolutePath},
75
+ relative: ${supportFileRelativePath},
76
+ relativeUrl: "/__cypress/src/cypress-support-file.js",
77
+ load: () => import(${supportFileAbsolutePath} /* webpackChunkName: "cypress-support-file" */),
78
+ }
79
+ scriptLoaders.unshift(supportFile)
80
+ }
69
81
 
70
82
  init(scriptLoaders)
71
83
  `;
84
+ return result;
72
85
  }
73
86
  exports.default = loader;
@@ -13,23 +13,40 @@ const OUTPUT_PATH = path_1.default.join(__dirname, 'dist');
13
13
  function makeDefaultWebpackConfig(config) {
14
14
  const { module: _HtmlWebpackPlugin, packageJson: { version }, importPath, } = config.sourceWebpackModulesResult.htmlWebpackPlugin;
15
15
  const indexHtmlFile = config.devServerConfig.cypressConfig.indexHtmlFile;
16
+ const isRunMode = config.devServerConfig.cypressConfig.isTextTerminal;
16
17
  const HtmlWebpackPlugin = _HtmlWebpackPlugin;
17
18
  debug(`Using HtmlWebpackPlugin version ${version} from ${importPath}`);
19
+ const optimization = {};
20
+ if (config.sourceWebpackModulesResult.webpack.majorVersion === 5) {
21
+ optimization.emitOnErrors = true;
22
+ }
23
+ else {
24
+ optimization.noEmitOnErrors = false;
25
+ }
26
+ // To prevent files from being tree shaken by webpack, we set optimization.sideEffects: false ensuring that
27
+ // webpack does not recognize the sideEffects flag in the package.json and thus files are not unintentionally
28
+ // dropped during testing in production mode.
29
+ optimization.sideEffects = false;
18
30
  const finalConfig = {
19
31
  mode: 'development',
20
- optimization: {
21
- splitChunks: {
32
+ optimization: Object.assign(Object.assign({}, optimization), { splitChunks: {
22
33
  chunks: 'all',
23
- },
24
- },
34
+ } }),
25
35
  output: {
26
36
  filename: '[name].js',
27
37
  path: OUTPUT_PATH,
28
38
  },
29
39
  plugins: [
30
- new HtmlWebpackPlugin(Object.assign({ template: indexHtmlFile }, (config.devServerConfig.framework === 'angular' ? { scriptLoading: 'module' } : {}))),
40
+ new HtmlWebpackPlugin(Object.assign({ template: indexHtmlFile }, (config.devServerConfig.framework === 'angular' ? { scriptLoading: 'module', base: '/__cypress/src/' } : {}))),
31
41
  ],
42
+ devtool: 'inline-source-map',
32
43
  };
44
+ if (isRunMode) {
45
+ // Disable file watching when executing tests in `run` mode
46
+ finalConfig.watchOptions = {
47
+ ignored: '**/*',
48
+ };
49
+ }
33
50
  if (config.sourceWebpackModulesResult.webpackDevServer.majorVersion === 4) {
34
51
  return Object.assign(Object.assign({}, finalConfig), { devServer: {
35
52
  client: {
@@ -65,7 +65,7 @@ function modifyWebpackConfigForCypress(webpackConfig) {
65
65
  * to pass to the sourced webpack function
66
66
  */
67
67
  async function makeWebpackConfig(config) {
68
- var _a, _b;
68
+ var _a, _b, _c;
69
69
  const { module: webpack } = config.sourceWebpackModulesResult.webpack;
70
70
  let userWebpackConfig = config.devServerConfig.webpackConfig;
71
71
  const frameworkWebpackConfig = config.frameworkConfig;
@@ -96,6 +96,9 @@ async function makeWebpackConfig(config) {
96
96
  }
97
97
  }
98
98
  }
99
+ userWebpackConfig = typeof userWebpackConfig === 'function'
100
+ ? await userWebpackConfig()
101
+ : userWebpackConfig;
99
102
  const userAndFrameworkWebpackConfig = modifyWebpackConfigForCypress((0, webpack_merge_1.merge)(frameworkWebpackConfig !== null && frameworkWebpackConfig !== void 0 ? frameworkWebpackConfig : {}, userWebpackConfig !== null && userWebpackConfig !== void 0 ? userWebpackConfig : {}));
100
103
  debug(`User passed in user and framework webpack config with values %o`, userAndFrameworkWebpackConfig);
101
104
  debug(`New webpack entries %o`, files);
@@ -122,6 +125,10 @@ async function makeWebpackConfig(config) {
122
125
  ],
123
126
  };
124
127
  const mergedConfig = (0, webpack_merge_1.merge)(userAndFrameworkWebpackConfig, (0, makeDefaultWebpackConfig_1.makeDefaultWebpackConfig)(config), dynamicWebpackConfig);
128
+ // Some frameworks (like Next.js) change this value which changes the path we would need to use to fetch our spec.
129
+ // (eg, http://localhost:xxxx/<dev-server-public-path>/static/chunks/spec-<x>.js). Deleting this key to normalize
130
+ // the spec URL to `*/spec-<x>.js` which we need to know up-front so we can fetch the sourcemaps.
131
+ (_c = mergedConfig.output) === null || _c === void 0 ? true : delete _c.chunkFilename;
125
132
  // Angular loads global styles and polyfills via script injection in the index.html
126
133
  if (framework === 'angular') {
127
134
  mergedConfig.entry = Object.assign(Object.assign({}, mergedConfig.entry || {}), { 'cypress-entry': exports.CYPRESS_WEBPACK_ENTRYPOINT });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/webpack-dev-server",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Launches Webpack Dev Server for Component Testing",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -37,7 +37,7 @@
37
37
  "proxyquire": "2.1.3",
38
38
  "sinon": "^13.0.1",
39
39
  "snap-shot-it": "^7.9.6",
40
- "ts-node": "^10.2.1",
40
+ "ts-node": "^10.9.1",
41
41
  "webpack": "npm:webpack@^5",
42
42
  "webpack-4": "npm:webpack@^4",
43
43
  "webpack-dev-server-3": "npm:webpack-dev-server@^3"
@@ -50,7 +50,7 @@
50
50
  "type": "git",
51
51
  "url": "https://github.com/cypress-io/cypress.git"
52
52
  },
53
- "homepage": "https://github.com/cypress-io/cypress/tree/master/npm/webpack-dev-server#readme",
53
+ "homepage": "https://github.com/cypress-io/cypress/tree/develop/npm/webpack-dev-server#readme",
54
54
  "bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md",
55
55
  "publishConfig": {
56
56
  "access": "public"