|
| 1 | +jest.mock('../../core/project-graph'); |
| 2 | +jest.mock('../../utilities/assets'); |
| 3 | +jest.mock('../../utilities/buildable-libs-utils'); |
| 4 | +jest.mock('../../utilities/fileutils'); |
| 5 | +jest.mock('../../utilities/typescript/compilation'); |
| 6 | + |
1 | 7 | import { ExecutorContext } from '@nrwl/devkit';
|
2 | 8 | import { join } from 'path';
|
3 | 9 | import { copyAssets } from '../../utilities/assets';
|
| 10 | +import { |
| 11 | + calculateProjectDependencies, |
| 12 | + checkDependentProjectsHaveBeenBuilt, |
| 13 | + createTmpTsConfig, |
| 14 | +} from '../../utilities/buildable-libs-utils'; |
4 | 15 | import { readJsonFile, writeJsonFile } from '../../utilities/fileutils';
|
5 | 16 | import { compileTypeScript } from '../../utilities/typescript/compilation';
|
6 | 17 | import { TypeScriptExecutorOptions } from './schema';
|
7 | 18 | import { tscExecutor } from './tsc.impl';
|
8 | 19 |
|
9 |
| -const defaultPackageJson = { name: 'workspacelib', version: '0.0.1' }; |
10 |
| -jest.mock('../../utilities/fileutils', () => ({ |
11 |
| - ...jest.requireActual<any>('../../utilities/fileutils'), |
12 |
| - writeJsonFile: jest.fn(), |
13 |
| - readJsonFile: jest.fn(() => ({ ...defaultPackageJson })), |
14 |
| -})); |
15 |
| -const readJsonFileMock = readJsonFile as jest.Mock<any>; |
16 |
| -jest.mock('../../utilities/typescript/compilation'); |
17 |
| -const compileTypeScriptMock = compileTypeScript as jest.Mock<{ |
18 |
| - success: boolean; |
19 |
| -}>; |
20 |
| -jest.mock('../../utilities/assets'); |
21 |
| - |
22 | 20 | describe('executor: tsc', () => {
|
23 | 21 | const assets = ['some-file.md'];
|
24 | 22 | let context: ExecutorContext;
|
25 | 23 | let normalizedOptions: TypeScriptExecutorOptions;
|
26 | 24 | let options: TypeScriptExecutorOptions;
|
| 25 | + const defaultPackageJson = { name: 'workspacelib', version: '0.0.1' }; |
| 26 | + const compileTypeScriptMock = compileTypeScript as jest.Mock; |
| 27 | + const readJsonFileMock = readJsonFile as jest.Mock; |
27 | 28 |
|
28 | 29 | beforeEach(() => {
|
| 30 | + jest.clearAllMocks(); |
| 31 | + |
| 32 | + (calculateProjectDependencies as jest.Mock).mockImplementation(() => ({ |
| 33 | + target: { data: { root: 'libs/workspacelib' } }, |
| 34 | + dependencies: [], |
| 35 | + })); |
| 36 | + (createTmpTsConfig as jest.Mock).mockImplementation( |
| 37 | + () => '/my-app/tsconfig.app.generated.json' |
| 38 | + ); |
| 39 | + (checkDependentProjectsHaveBeenBuilt as jest.Mock).mockReturnValue(true); |
| 40 | + readJsonFileMock.mockImplementation(() => ({ ...defaultPackageJson })); |
| 41 | + |
29 | 42 | context = {
|
30 | 43 | cwd: '/root',
|
31 | 44 | root: '/root',
|
@@ -54,8 +67,19 @@ describe('executor: tsc', () => {
|
54 | 67 | outputPath: join(context.root, options.outputPath),
|
55 | 68 | tsConfig: join(context.root, options.tsConfig),
|
56 | 69 | };
|
| 70 | + }); |
57 | 71 |
|
58 |
| - jest.clearAllMocks(); |
| 72 | + it('should return { success: false } when dependent projects have not been built', async () => { |
| 73 | + (calculateProjectDependencies as jest.Mock).mockImplementation(() => ({ |
| 74 | + target: { data: { root: 'libs/workspacelib' } }, |
| 75 | + dependencies: [{}], |
| 76 | + })); |
| 77 | + (checkDependentProjectsHaveBeenBuilt as jest.Mock).mockReturnValue(false); |
| 78 | + |
| 79 | + const result = await tscExecutor(options, context); |
| 80 | + |
| 81 | + expect(result).toEqual({ success: false }); |
| 82 | + expect(compileTypeScriptMock).not.toHaveBeenCalled(); |
59 | 83 | });
|
60 | 84 |
|
61 | 85 | it('should return typescript compilation result', async () => {
|
|
0 commit comments