@nx/storybook 19.0.1 → 19.0.3

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/generators.json CHANGED
@@ -18,7 +18,8 @@
18
18
  "cypress-project": {
19
19
  "factory": "./src/generators/cypress-project/cypress-project",
20
20
  "schema": "./src/generators/cypress-project/schema.json",
21
- "description": "Add cypress e2e app to test a UI library that is set up for Storybook.",
21
+ "description": "Add cypress E2E app to test a ui library that is set up for Storybook.",
22
+ "x-deprecated": "Deprecated: Use 'interactionTests' instead when running '@nx/storybook:configuration'. This generator will be removed in v21.",
22
23
  "hidden": false
23
24
  },
24
25
  "migrate-7": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/storybook",
3
- "version": "19.0.1",
3
+ "version": "19.0.3",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Storybook contains executors and generators for allowing your workspace to use the powerful Storybook integration testing & documenting capabilities.",
6
6
  "repository": {
@@ -30,14 +30,14 @@
30
30
  "migrations": "./migrations.json"
31
31
  },
32
32
  "dependencies": {
33
- "@nx/devkit": "19.0.1",
33
+ "@nx/devkit": "19.0.3",
34
34
  "@phenomnomnominal/tsquery": "~5.0.1",
35
35
  "semver": "^7.5.3",
36
36
  "tslib": "^2.3.0",
37
- "@nx/cypress": "19.0.1",
38
- "@nx/js": "19.0.1",
39
- "@nx/eslint": "19.0.1",
40
- "@nrwl/storybook": "19.0.1"
37
+ "@nx/cypress": "19.0.3",
38
+ "@nx/js": "19.0.3",
39
+ "@nx/eslint": "19.0.3",
40
+ "@nrwl/storybook": "19.0.3"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
@@ -1 +1,2 @@
1
- export declare function nxE2EStorybookPreset(filePath: string): any;
1
+ import { NxCypressE2EPresetOptions } from '@nx/cypress/plugins/cypress-preset';
2
+ export declare function nxE2EStorybookPreset(filePath: string, options?: NxCypressE2EPresetOptions): any;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxE2EStorybookPreset = void 0;
4
4
  const cypress_preset_1 = require("@nx/cypress/plugins/cypress-preset");
5
- function nxE2EStorybookPreset(filePath) {
5
+ function nxE2EStorybookPreset(filePath, options) {
6
6
  return {
7
- ...(0, cypress_preset_1.nxE2EPreset)(filePath),
7
+ ...(0, cypress_preset_1.nxE2EPreset)(filePath, options),
8
8
  baseUrl: 'http://localhost:4400',
9
9
  };
10
10
  }
@@ -12,11 +12,11 @@ export interface StorybookConfigureSchema {
12
12
  configureStaticServe?: boolean;
13
13
  skipFormat?: boolean;
14
14
  /**
15
- * @deprecated Use interactionTests instead. This option will be removed in v19.
15
+ * @deprecated Use interactionTests instead. This option will be removed in v20.
16
16
  */
17
17
  configureCypress?: boolean;
18
18
  /**
19
- * @deprecated Use interactionTests instead. This option will be removed in v19.
19
+ * @deprecated Use interactionTests instead. This option will be removed in v20.
20
20
  */
21
21
  cypressDirectory?: string;
22
22
  addPlugin?: boolean;
@@ -28,12 +28,12 @@
28
28
  "configureCypress": {
29
29
  "type": "boolean",
30
30
  "description": "Run the cypress-configure generator.",
31
- "x-deprecated": "Use interactionTests instead. This option will be removed in v19."
31
+ "x-deprecated": "Use interactionTests instead. This option will be removed in v20."
32
32
  },
33
33
  "cypressDirectory": {
34
34
  "type": "string",
35
35
  "description": "A directory where the Cypress project will be placed. Added at root by default.",
36
- "x-deprecated": "Use interactionTests instead. This option will be removed in v19."
36
+ "x-deprecated": "Use interactionTests instead. This option will be removed in v20."
37
37
  },
38
38
  "linter": {
39
39
  "description": "The tool to use for running lint checks.",
@@ -15,6 +15,7 @@ async function cypressProjectGenerator(tree, schema) {
15
15
  }
16
16
  exports.cypressProjectGenerator = cypressProjectGenerator;
17
17
  async function cypressProjectGeneratorInternal(tree, schema) {
18
+ devkit_1.logger.warn(`Use 'interactionTests' instead when running '@nx/storybook:configuration'. This generator will be removed in v21.`);
18
19
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
19
20
  const e2eName = schema.name ? `${schema.name}-e2e` : undefined;
20
21
  const { projectName, projectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
@@ -37,28 +38,42 @@ async function cypressProjectGeneratorInternal(tree, schema) {
37
38
  project: projectName,
38
39
  js: schema.js,
39
40
  linter: schema.linter,
40
- directory: projectRoot,
41
41
  devServerTarget: `${schema.name}:storybook`,
42
42
  skipFormat: true,
43
43
  });
44
44
  const generatedCypressProjectName = (0, project_name_1.getE2eProjectName)(schema.name, libRoot, schema.directory);
45
45
  removeUnneededFiles(tree, generatedCypressProjectName, schema.js);
46
- addBaseUrlToCypressConfig(tree, generatedCypressProjectName);
47
- updateAngularJsonBuilder(tree, {
48
- e2eProjectName: generatedCypressProjectName,
49
- targetProjectName: schema.name,
50
- ciTargetName: schema.ciTargetName,
51
- });
46
+ const project = (0, devkit_1.readProjectConfiguration)(tree, generatedCypressProjectName);
47
+ if (project.targets.e2e && project.targets.e2e.options) {
48
+ addBaseUrlToCypressConfig(tree, generatedCypressProjectName, project.root);
49
+ updateAngularJsonBuilder(tree, {
50
+ e2eProjectName: generatedCypressProjectName,
51
+ targetProjectName: schema.name,
52
+ ciTargetName: schema.ciTargetName,
53
+ });
54
+ }
55
+ else if (hasCypressPlugin(tree)) {
56
+ generateCypressConfigForInferredPlugin(tree, generatedCypressProjectName, project.root, schema.name, schema.ciTargetName);
57
+ }
58
+ else {
59
+ throw new Error(`Unable to generate Cypress Project for Storybook project. Please report this issue at https://github.com/nrwl/nx/issues/new/choose`);
60
+ }
52
61
  if (!schema.skipFormat) {
53
62
  await (0, devkit_1.formatFiles)(tree);
54
63
  }
55
64
  return cypressTask;
56
65
  }
57
66
  exports.cypressProjectGeneratorInternal = cypressProjectGeneratorInternal;
67
+ function hasCypressPlugin(tree) {
68
+ const nxJson = (0, devkit_1.readNxJson)(tree);
69
+ return nxJson.plugins?.some((p) => typeof p === 'string'
70
+ ? p === '@nx/cypress/plugin'
71
+ : p.plugin === '@nx/cypress/plugin');
72
+ }
58
73
  function removeUnneededFiles(tree, projectName, js) {
59
74
  const { sourceRoot, root } = (0, devkit_1.readProjectConfiguration)(tree, projectName);
60
75
  const fileType = js ? 'js' : 'ts';
61
- if (tree.exists((0, path_1.join)(root, 'cypress.config.ts'))) {
76
+ if (tree.exists((0, devkit_1.joinPathFragments)(root, 'cypress.config.ts'))) {
62
77
  (0, utilities_1.safeFileDelete)(tree, `${sourceRoot}/e2e/app.cy.${fileType}`);
63
78
  (0, utilities_1.safeFileDelete)(tree, `${sourceRoot}/support/app.po.${fileType}`);
64
79
  }
@@ -67,10 +82,27 @@ function removeUnneededFiles(tree, projectName, js) {
67
82
  (0, utilities_1.safeFileDelete)(tree, `${sourceRoot}/support/app.po.${fileType}`);
68
83
  }
69
84
  }
70
- function addBaseUrlToCypressConfig(tree, projectName) {
71
- const projectRoot = (0, devkit_1.readProjectConfiguration)(tree, projectName).root;
72
- const cypressJson = (0, path_1.join)(projectRoot, 'cypress.json');
73
- const cypressTs = (0, path_1.join)(projectRoot, 'cypress.config.ts');
85
+ function generateCypressConfigForInferredPlugin(tree, projectName, projectRoot, targetProjectName, ciTargetName) {
86
+ const cypressJson = (0, devkit_1.joinPathFragments)(projectRoot, 'cypress.json');
87
+ const cypressTs = (0, devkit_1.joinPathFragments)(projectRoot, 'cypress.config.ts');
88
+ if (tree.exists(cypressJson)) {
89
+ tree.delete(cypressJson);
90
+ }
91
+ if (tree.exists(cypressTs)) {
92
+ // cypress >= v10
93
+ tree.delete(cypressTs);
94
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files', 'inferred-target'), projectRoot, {
95
+ defaultWebServerCommand: `npx nx run ${targetProjectName}:storybook`,
96
+ ciWebServerCommand: ciTargetName
97
+ ? `npx nx run ${targetProjectName}:${ciTargetName}:ci`
98
+ : `npx nx run ${targetProjectName}:storybook:ci`,
99
+ tpl: '',
100
+ });
101
+ }
102
+ }
103
+ function addBaseUrlToCypressConfig(tree, projectName, projectRoot) {
104
+ const cypressJson = (0, devkit_1.joinPathFragments)(projectRoot, 'cypress.json');
105
+ const cypressTs = (0, devkit_1.joinPathFragments)(projectRoot, 'cypress.config.ts');
74
106
  // TODO(caleb): remove this when cypress < v10 is deprecated
75
107
  if (tree.exists(cypressJson)) {
76
108
  // cypress < v10
@@ -82,14 +114,14 @@ function addBaseUrlToCypressConfig(tree, projectName) {
82
114
  else if (tree.exists(cypressTs)) {
83
115
  // cypress >= v10
84
116
  tree.delete(cypressTs);
85
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, {
117
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files', 'explicit-target'), projectRoot, {
86
118
  tpl: '',
87
119
  });
88
120
  }
89
121
  }
90
122
  function updateAngularJsonBuilder(tree, opts) {
91
123
  const project = (0, devkit_1.readProjectConfiguration)(tree, opts.e2eProjectName);
92
- const e2eTarget = project.targets.e2e;
124
+ const e2eTarget = project.targets.e2e ?? {};
93
125
  project.targets.e2e = {
94
126
  ...e2eTarget,
95
127
  options: {
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'cypress';
2
+ import { nxE2EStorybookPreset } from '@nx/storybook/presets/cypress';
3
+
4
+ export default defineConfig({
5
+ e2e: nxE2EStorybookPreset(__dirname, {
6
+ cypressDir: 'src',
7
+ webServerCommands: {
8
+ default: "<%= defaultWebServerCommand %>",
9
+ ci: "<%= ciWebServerCommand %>"
10
+ },
11
+ ciWebServerCommand: "<%= ciWebServerCommand %>"
12
+ }),
13
+ });
@@ -4,6 +4,7 @@
4
4
  "$id": "cypress-configure",
5
5
  "title": "Cypress Configuration",
6
6
  "description": "Add cypress E2E app to test a ui library that is set up for Storybook.",
7
+ "x-deprecated": "Use 'interactionTests' instead when running '@nx/storybook:configuration'. This generator will be removed in v21.",
7
8
  "type": "object",
8
9
  "properties": {
9
10
  "name": {
@@ -60,7 +60,7 @@ async function initGeneratorInternal(tree, schema) {
60
60
  nxJson.useInferencePlugins !== false;
61
61
  schema.addPlugin ??= addPluginDefault;
62
62
  if (schema.addPlugin) {
63
- await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/storybook/plugin', plugin_1.createNodes, {
63
+ await (0, add_plugin_1.addPlugin)(tree, '@nx/storybook/plugin', plugin_1.createNodes, {
64
64
  serveStorybookTargetName: [
65
65
  'storybook',
66
66
  'serve:storybook',