|
1 | | -import type { CreateNodesContext } from '@nx/devkit'; |
| 1 | +import type { CreateNodesContext, CreateNodesContextV2 } from '@nx/devkit'; |
2 | 2 | import { vol } from 'memfs'; |
3 | 3 | import { describe, expect } from 'vitest'; |
4 | | -import { invokeCreateNodesOnVirtualFiles } from '@code-pushup/test-nx-utils'; |
| 4 | +import { |
| 5 | + createNodesContextV1, |
| 6 | + createNodesContextV2, |
| 7 | + invokeCreateNodesOnVirtualFilesV1, |
| 8 | + invokeCreateNodesOnVirtualFilesV2, |
| 9 | +} from '@code-pushup/test-nx-utils'; |
5 | 10 | import { PACKAGE_NAME, PROJECT_JSON_FILE_NAME } from '../internal/constants.js'; |
6 | 11 | import { CP_TARGET_NAME } from './constants.js'; |
7 | | -import { createNodes } from './plugin.js'; |
| 12 | +import { createNodes, createNodesV2 } from './plugin.js'; |
8 | 13 |
|
9 | 14 | describe('@code-pushup/nx-plugin/plugin', () => { |
10 | | - let context: CreateNodesContext; |
| 15 | + describe('V1', () => { |
| 16 | + let context: CreateNodesContext; |
11 | 17 |
|
12 | | - beforeEach(() => { |
13 | | - context = { |
14 | | - nxJsonConfiguration: {}, |
15 | | - workspaceRoot: '', |
16 | | - }; |
17 | | - }); |
| 18 | + beforeEach(() => { |
| 19 | + context = createNodesContextV1({ |
| 20 | + nxJsonConfiguration: {}, |
| 21 | + workspaceRoot: '', |
| 22 | + }); |
| 23 | + }); |
18 | 24 |
|
19 | | - afterEach(() => { |
20 | | - vol.reset(); |
21 | | - }); |
| 25 | + afterEach(() => { |
| 26 | + vol.reset(); |
| 27 | + }); |
22 | 28 |
|
23 | | - it('should normalize context and use it to create the configuration target on ROOT project', async () => { |
24 | | - const projectRoot = '.'; |
25 | | - const matchingFilesData = { |
26 | | - [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
27 | | - name: '@org/empty-root', |
28 | | - })}`, |
29 | | - }; |
| 29 | + it('should normalize context and use it to create the configuration target on ROOT project', async () => { |
| 30 | + const projectRoot = '.'; |
| 31 | + const matchingFilesData = { |
| 32 | + [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
| 33 | + name: '@org/empty-root', |
| 34 | + })}`, |
| 35 | + }; |
30 | 36 |
|
31 | | - await expect( |
32 | | - invokeCreateNodesOnVirtualFiles( |
33 | | - createNodes, |
34 | | - context, |
35 | | - {}, |
36 | | - { matchingFilesData }, |
37 | | - ), |
38 | | - ).resolves.toStrictEqual({ |
39 | | - [projectRoot]: { |
40 | | - targets: { |
41 | | - [`${CP_TARGET_NAME}--configuration`]: { |
42 | | - command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, |
| 37 | + await expect( |
| 38 | + invokeCreateNodesOnVirtualFilesV1( |
| 39 | + createNodes, |
| 40 | + context, |
| 41 | + {}, |
| 42 | + { matchingFilesData }, |
| 43 | + ), |
| 44 | + ).resolves.toStrictEqual({ |
| 45 | + [projectRoot]: { |
| 46 | + targets: { |
| 47 | + [`${CP_TARGET_NAME}--configuration`]: { |
| 48 | + command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, |
| 49 | + }, |
43 | 50 | }, |
44 | 51 | }, |
45 | | - }, |
| 52 | + }); |
46 | 53 | }); |
47 | | - }); |
48 | 54 |
|
49 | | - it('should normalize context and use it to create the configuration target on PACKAGE project', async () => { |
50 | | - const projectRoot = 'apps/my-app'; |
51 | | - const matchingFilesData = { |
52 | | - [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
53 | | - name: '@org/empty-root', |
54 | | - })}`, |
55 | | - }; |
| 55 | + it('should create the executor target on PACKAGE project if configured', async () => { |
| 56 | + const projectRoot = 'apps/my-app'; |
| 57 | + const matchingFilesData = { |
| 58 | + [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
| 59 | + name: '@org/empty-root', |
| 60 | + })}`, |
| 61 | + [`${projectRoot}/code-pushup.config.ts`]: '{}', |
| 62 | + }; |
56 | 63 |
|
57 | | - await expect( |
58 | | - invokeCreateNodesOnVirtualFiles( |
59 | | - createNodes, |
60 | | - context, |
61 | | - {}, |
62 | | - { matchingFilesData }, |
63 | | - ), |
64 | | - ).resolves.toStrictEqual({ |
65 | | - [projectRoot]: { |
66 | | - targets: { |
67 | | - [`${CP_TARGET_NAME}--configuration`]: { |
68 | | - command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, |
| 64 | + await expect( |
| 65 | + invokeCreateNodesOnVirtualFilesV1( |
| 66 | + createNodes, |
| 67 | + context, |
| 68 | + { |
| 69 | + projectPrefix: 'cli', |
| 70 | + }, |
| 71 | + { matchingFilesData }, |
| 72 | + ), |
| 73 | + ).resolves.toStrictEqual({ |
| 74 | + [projectRoot]: { |
| 75 | + targets: { |
| 76 | + [CP_TARGET_NAME]: { |
| 77 | + executor: `${PACKAGE_NAME}:cli`, |
| 78 | + options: { |
| 79 | + projectPrefix: 'cli', |
| 80 | + }, |
| 81 | + }, |
69 | 82 | }, |
70 | 83 | }, |
71 | | - }, |
| 84 | + }); |
72 | 85 | }); |
73 | 86 | }); |
74 | 87 |
|
75 | | - it('should create the executor target on ROOT project if configured', async () => { |
76 | | - const projectRoot = '.'; |
77 | | - const matchingFilesData = { |
78 | | - [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
79 | | - name: '@org/empty-root', |
80 | | - })}`, |
81 | | - [`${projectRoot}/code-pushup.config.ts`]: '{}', |
82 | | - }; |
| 88 | + describe('V2', () => { |
| 89 | + let context: CreateNodesContextV2; |
83 | 90 |
|
84 | | - await expect( |
85 | | - invokeCreateNodesOnVirtualFiles( |
86 | | - createNodes, |
87 | | - context, |
88 | | - { |
89 | | - projectPrefix: 'cli', |
90 | | - }, |
91 | | - { matchingFilesData }, |
92 | | - ), |
93 | | - ).resolves.toStrictEqual({ |
94 | | - [projectRoot]: { |
95 | | - targets: { |
96 | | - [CP_TARGET_NAME]: { |
97 | | - executor: `${PACKAGE_NAME}:cli`, |
98 | | - options: { |
99 | | - projectPrefix: 'cli', |
| 91 | + beforeEach(() => { |
| 92 | + context = createNodesContextV2({ |
| 93 | + nxJsonConfiguration: {}, |
| 94 | + workspaceRoot: '', |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + afterEach(() => { |
| 99 | + vol.reset(); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should normalize context and use it to create the configuration target on ROOT project', async () => { |
| 103 | + const projectRoot = '.'; |
| 104 | + const matchingFilesData = { |
| 105 | + [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
| 106 | + name: '@org/empty-root', |
| 107 | + })}`, |
| 108 | + }; |
| 109 | + |
| 110 | + await expect( |
| 111 | + invokeCreateNodesOnVirtualFilesV2( |
| 112 | + createNodesV2, |
| 113 | + context, |
| 114 | + {}, |
| 115 | + { matchingFilesData }, |
| 116 | + ), |
| 117 | + ).resolves.toStrictEqual({ |
| 118 | + [projectRoot]: { |
| 119 | + targets: { |
| 120 | + [`${CP_TARGET_NAME}--configuration`]: { |
| 121 | + command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, |
100 | 122 | }, |
101 | 123 | }, |
102 | 124 | }, |
103 | | - }, |
| 125 | + }); |
104 | 126 | }); |
105 | | - }); |
106 | 127 |
|
107 | | - it('should create the executor target on PACKAGE project if configured', async () => { |
108 | | - const projectRoot = 'apps/my-app'; |
109 | | - const matchingFilesData = { |
110 | | - [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
111 | | - name: '@org/empty-root', |
112 | | - })}`, |
113 | | - [`${projectRoot}/code-pushup.config.ts`]: '{}', |
114 | | - }; |
| 128 | + it('should create the executor target on PACKAGE project if configured', async () => { |
| 129 | + const projectRoot = 'apps/my-app'; |
| 130 | + const matchingFilesData = { |
| 131 | + [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ |
| 132 | + name: '@org/empty-root', |
| 133 | + })}`, |
| 134 | + [`${projectRoot}/code-pushup.config.ts`]: '{}', |
| 135 | + }; |
115 | 136 |
|
116 | | - await expect( |
117 | | - invokeCreateNodesOnVirtualFiles( |
118 | | - createNodes, |
119 | | - context, |
120 | | - { |
121 | | - projectPrefix: 'cli', |
122 | | - }, |
123 | | - { matchingFilesData }, |
124 | | - ), |
125 | | - ).resolves.toStrictEqual({ |
126 | | - [projectRoot]: { |
127 | | - targets: { |
128 | | - [CP_TARGET_NAME]: { |
129 | | - executor: `${PACKAGE_NAME}:cli`, |
130 | | - options: { |
131 | | - projectPrefix: 'cli', |
| 137 | + await expect( |
| 138 | + invokeCreateNodesOnVirtualFilesV2( |
| 139 | + createNodesV2, |
| 140 | + context, |
| 141 | + { |
| 142 | + projectPrefix: 'cli', |
| 143 | + }, |
| 144 | + { matchingFilesData }, |
| 145 | + ), |
| 146 | + ).resolves.toStrictEqual({ |
| 147 | + [projectRoot]: { |
| 148 | + targets: { |
| 149 | + [CP_TARGET_NAME]: { |
| 150 | + executor: `${PACKAGE_NAME}:cli`, |
| 151 | + options: { |
| 152 | + projectPrefix: 'cli', |
| 153 | + }, |
132 | 154 | }, |
133 | 155 | }, |
134 | 156 | }, |
135 | | - }, |
| 157 | + }); |
136 | 158 | }); |
137 | 159 | }); |
138 | 160 | }); |
0 commit comments