|
1 | 1 | import { workspaceRoot } from '@nrwl/devkit'; |
2 | 2 | import { join } from 'path'; |
3 | | -import { qwikNxVite, QwikNxVitePluginOptions } from './qwik-nx-vite.plugin'; |
| 3 | +import { qwikNxVite } from './qwik-nx-vite.plugin'; |
| 4 | +import { QwikNxVitePluginOptions } from './models/qwik-nx-vite'; |
4 | 5 |
|
5 | 6 | // eslint-disable-next-line @typescript-eslint/no-var-requires |
6 | 7 | const fileUtils = require('nx/src/project-graph/file-utils'); |
7 | 8 | // eslint-disable-next-line @typescript-eslint/no-var-requires |
8 | 9 | const fs = require('fs'); |
| 10 | +// eslint-disable-next-line @typescript-eslint/no-var-requires |
| 11 | +const getProjectDependenciesModule = require('./utils/get-project-dependencies'); |
9 | 12 |
|
10 | | -const workspaceConfig1 = { |
11 | | - projects: { |
12 | | - 'tmp-test-app-a': { |
13 | | - root: 'apps/test-app-a', |
14 | | - name: 'tmp-test-app-a', |
15 | | - projectType: 'application', |
16 | | - sourceRoot: 'apps/test-app-a/src', |
17 | | - prefix: 'tmp', |
18 | | - tags: ['tag1', 'tag2'], |
19 | | - }, |
20 | | - 'tmp-test-lib-a': { |
21 | | - root: 'libs/test-lib-a', |
22 | | - name: 'tmp-test-lib-a', |
23 | | - projectType: 'library', |
24 | | - sourceRoot: 'libs/test-lib-a/src', |
25 | | - prefix: 'tmp', |
26 | | - tags: ['tag2'], |
27 | | - }, |
28 | | - 'tmp-test-lib-b': { |
29 | | - root: 'libs/test-lib-b', |
30 | | - name: 'tmp-test-lib-b', |
31 | | - projectType: 'library', |
32 | | - sourceRoot: 'libs/test-lib-b/src', |
33 | | - prefix: 'tmp', |
34 | | - tags: ['tag2', 'tag3'], |
35 | | - }, |
36 | | - 'tmp-test-lib-c-nested-1': { |
37 | | - root: 'libs/test-lib-c/nested', |
38 | | - name: 'tmp-test-lib-c-nested-1', |
39 | | - projectType: 'library', |
40 | | - sourceRoot: 'libs/test-lib-c/nested-1/src', |
41 | | - prefix: 'tmp', |
42 | | - tags: ['tag4'], |
43 | | - }, |
44 | | - 'tmp-test-lib-c-nested-2': { |
45 | | - root: 'libs/test-lib-c/nested', |
46 | | - name: 'tmp-test-lib-c-nested-2', |
47 | | - projectType: 'library', |
48 | | - sourceRoot: 'libs/test-lib-c/nested-2/src', |
49 | | - prefix: 'tmp', |
50 | | - tags: ['tag1', 'tag2', 'tag3'], |
51 | | - }, |
52 | | - 'tmp-other-test-lib-a': { |
53 | | - root: 'libs/other/test-lib-a', |
54 | | - name: 'tmp-other-test-lib-a', |
55 | | - projectType: 'library', |
56 | | - sourceRoot: 'libs/other/test-lib-a/src', |
57 | | - prefix: 'tmp', |
58 | | - tags: [], |
59 | | - }, |
60 | | - // it will be excluded because it is not set in our mock tsconfig.json |
61 | | - 'tmp-always-excluded': { |
62 | | - root: 'libs/always/excluded', |
63 | | - name: 'tmp-always-excluded', |
64 | | - projectType: 'library', |
65 | | - sourceRoot: 'libs/always/excluded/src', |
66 | | - prefix: 'tmp', |
67 | | - tags: [], |
| 13 | +function getWorkspaceConfig() { |
| 14 | + return { |
| 15 | + projects: { |
| 16 | + 'tmp-test-app-a': { |
| 17 | + root: 'apps/test-app-a', |
| 18 | + name: 'tmp-test-app-a', |
| 19 | + projectType: 'application', |
| 20 | + sourceRoot: 'apps/test-app-a/src', |
| 21 | + prefix: 'tmp', |
| 22 | + tags: ['tag1', 'tag2'], |
| 23 | + }, |
| 24 | + 'tmp-test-lib-a': { |
| 25 | + root: 'libs/test-lib-a', |
| 26 | + name: 'tmp-test-lib-a', |
| 27 | + projectType: 'library', |
| 28 | + sourceRoot: 'libs/test-lib-a/src', |
| 29 | + prefix: 'tmp', |
| 30 | + tags: ['tag2'], |
| 31 | + }, |
| 32 | + 'tmp-test-lib-b': { |
| 33 | + root: 'libs/test-lib-b', |
| 34 | + name: 'tmp-test-lib-b', |
| 35 | + projectType: 'library', |
| 36 | + sourceRoot: 'libs/test-lib-b/src', |
| 37 | + prefix: 'tmp', |
| 38 | + tags: ['tag2', 'tag3'], |
| 39 | + }, |
| 40 | + 'tmp-test-lib-c-nested-1': { |
| 41 | + root: 'libs/test-lib-c/nested', |
| 42 | + name: 'tmp-test-lib-c-nested-1', |
| 43 | + projectType: 'library', |
| 44 | + sourceRoot: 'libs/test-lib-c/nested-1/src', |
| 45 | + prefix: 'tmp', |
| 46 | + tags: ['tag4'], |
| 47 | + }, |
| 48 | + 'tmp-test-lib-c-nested-2': { |
| 49 | + root: 'libs/test-lib-c/nested', |
| 50 | + name: 'tmp-test-lib-c-nested-2', |
| 51 | + projectType: 'library', |
| 52 | + sourceRoot: 'libs/test-lib-c/nested-2/src', |
| 53 | + prefix: 'tmp', |
| 54 | + tags: ['tag1', 'tag2', 'tag3'], |
| 55 | + }, |
| 56 | + 'tmp-other-test-lib-a': { |
| 57 | + root: 'libs/other/test-lib-a', |
| 58 | + name: 'tmp-other-test-lib-a', |
| 59 | + projectType: 'library', |
| 60 | + sourceRoot: 'libs/other/test-lib-a/src', |
| 61 | + prefix: 'tmp', |
| 62 | + tags: [], |
| 63 | + }, |
| 64 | + // it will be excluded because it is not set in our mock tsconfig.json |
| 65 | + 'tmp-always-excluded': { |
| 66 | + root: 'libs/always/excluded', |
| 67 | + name: 'tmp-always-excluded', |
| 68 | + projectType: 'library', |
| 69 | + sourceRoot: 'libs/always/excluded/src', |
| 70 | + prefix: 'tmp', |
| 71 | + tags: [], |
| 72 | + }, |
68 | 73 | }, |
69 | | - }, |
70 | | -}; |
| 74 | + }; |
| 75 | +} |
71 | 76 |
|
72 | | -const tsConfigString1 = JSON.stringify({ |
73 | | - compilerOptions: { |
74 | | - paths: { |
75 | | - '@tmp/test-lib-a': 'libs/test-lib-a/src/index.ts', |
76 | | - '@tmp/test-lib-b': 'libs/test-lib-b/src/index.ts', |
77 | | - '@tmp/test-lib-c/nested-1': 'libs/test-lib-c/nested-1/src/index.ts', |
78 | | - '@tmp/test-lib-c/nested-2': 'libs/test-lib-c/nested-2/src/index.ts', |
79 | | - '@tmp/other/test-lib-a/nested-2': 'libs/other/test-lib-a/src/index.ts', |
| 77 | +function getTsConfigString() { |
| 78 | + return JSON.stringify({ |
| 79 | + compilerOptions: { |
| 80 | + paths: { |
| 81 | + '@tmp/test-lib-a': 'libs/test-lib-a/src/index.ts', |
| 82 | + '@tmp/test-lib-b': 'libs/test-lib-b/src/index.ts', |
| 83 | + '@tmp/test-lib-c/nested-1': 'libs/test-lib-c/nested-1/src/index.ts', |
| 84 | + '@tmp/test-lib-c/nested-2': 'libs/test-lib-c/nested-2/src/index.ts', |
| 85 | + '@tmp/other/test-lib-a/nested-2': 'libs/other/test-lib-a/src/index.ts', |
| 86 | + }, |
80 | 87 | }, |
81 | | - }, |
82 | | -}); |
| 88 | + }); |
| 89 | +} |
83 | 90 |
|
84 | 91 | describe('qwik-nx-vite plugin', () => { |
85 | 92 | jest |
86 | 93 | .spyOn(fileUtils, 'readWorkspaceConfig') |
87 | | - .mockReturnValue(workspaceConfig1); |
88 | | - jest.spyOn(fs, 'readFileSync').mockReturnValue(tsConfigString1); |
| 94 | + .mockReturnValue(getWorkspaceConfig()); |
| 95 | + jest.spyOn(fs, 'readFileSync').mockReturnValue(getTsConfigString()); |
| 96 | + jest |
| 97 | + .spyOn(getProjectDependenciesModule, 'getProjectDependencies') |
| 98 | + .mockReturnValue( |
| 99 | + Promise.resolve(new Set(Object.keys(getWorkspaceConfig().projects))) |
| 100 | + ); |
89 | 101 |
|
90 | 102 | /** |
91 | 103 | * @param options options for the qwikNxVite plugin |
@@ -132,7 +144,7 @@ describe('qwik-nx-vite plugin', () => { |
132 | 144 | ]); |
133 | 145 | }); |
134 | 146 |
|
135 | | - describe('Should not include current porject as a vendor root for itself', () => { |
| 147 | + describe('Should not include current project as a vendor root for itself', () => { |
136 | 148 | it('with project name specified', async () => { |
137 | 149 | const paths = await getDecoratedPaths({ |
138 | 150 | currentProjectName: 'tmp-test-lib-a', |
|
0 commit comments