-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplugin-plugins-config.e2e.test.ts
More file actions
99 lines (90 loc) · 2.63 KB
/
plugin-plugins-config.e2e.test.ts
File metadata and controls
99 lines (90 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import type { Tree } from '@nx/devkit';
import path from 'node:path';
import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration';
import { afterEach, expect } from 'vitest';
import { generateCodePushupConfig } from '@code-pushup/nx-plugin';
import {
generateWorkspaceAndProject,
materializeTree,
nxShowProjectJson,
nxTargetProject,
registerPluginInWorkspace,
} from '@code-pushup/test-nx-utils';
import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
teardownTestFolder,
} from '@code-pushup/test-utils';
import { INLINE_PLUGIN } from '../mocks/inline-plugin.js';
describe('nx-plugin pluginsConfig', () => {
let tree: Tree;
const project = 'my-lib';
const testFileDir = path.join(
E2E_ENVIRONMENTS_DIR,
nxTargetProject(),
TEST_OUTPUT_DIR,
'plugin-plugins-config',
);
beforeEach(async () => {
tree = await generateWorkspaceAndProject(project);
});
afterEach(async () => {
await teardownTestFolder(testFileDir);
});
it('should apply pluginsConfig options to executor target', async () => {
const cwd = path.join(testFileDir, 'plugins-config-applied');
const binPath = 'packages/cli/src/index.ts';
const configPath = '{projectRoot}/code-pushup.config.ts';
const projectPrefix = 'cli';
// Register plugin with options in the plugins array and pluginsConfig
registerPluginInWorkspace(
tree,
{
plugin: '@code-pushup/nx-plugin',
options: {
config: configPath,
persist: {
outputDir: '.code-pushup/{projectName}',
},
},
},
{
projectPrefix,
bin: binPath,
env: {
NODE_OPTIONS: '--import tsx',
TSX_TSCONFIG_PATH: 'tsconfig.base.json',
},
},
);
const { root } = readProjectConfiguration(tree, project);
generateCodePushupConfig(tree, root, {
plugins: [
{
fileImports: '',
codeStrings: INLINE_PLUGIN,
},
],
});
await materializeTree(tree, cwd);
const { code, projectJson } = await nxShowProjectJson(cwd, project);
expect(code).toBe(0);
expect(projectJson).toStrictEqual(
expect.objectContaining({
targets: expect.objectContaining({
'code-pushup': expect.objectContaining({
executor: '@code-pushup/nx-plugin:cli',
options: expect.objectContaining({
projectPrefix,
bin: binPath,
env: {
NODE_OPTIONS: '--import tsx',
TSX_TSCONFIG_PATH: 'tsconfig.base.json',
},
}),
}),
}),
}),
);
});
});