|
1 |
| -import {join} from 'path'; |
2 |
| -import {ng} from '../../../utils/process'; |
3 |
| -import {expectFileToExist} from '../../../utils/fs'; |
| 1 | +import { join } from 'path'; |
| 2 | +import { ng } from '../../../utils/process'; |
| 3 | +import { expectFileToExist, rimraf } from '../../../utils/fs'; |
4 | 4 |
|
5 |
| - |
6 |
| -export default function() { |
| 5 | +export default async function () { |
7 | 6 | const upperDirs = join('non', 'existing', 'dir');
|
8 | 7 | const rootDir = join('src', 'app', upperDirs);
|
9 | 8 |
|
10 |
| - const componentDir = join(rootDir, 'test-component'); |
11 |
| - const componentTwoDir = join(rootDir, 'test-component-two'); |
| 9 | + const componentDirectory = join(rootDir, 'test-component'); |
| 10 | + const componentTwoDirectory = join(rootDir, 'test-component-two'); |
| 11 | + |
| 12 | + try { |
| 13 | + // Generate a component |
| 14 | + await ng('generate', 'component', `${upperDirs}/test-component`) |
| 15 | + |
| 16 | + // Ensure component is created in the correct location relative to the workspace root |
| 17 | + await expectFileToExist(join(componentDirectory, 'test-component.component.ts')); |
| 18 | + await expectFileToExist(join(componentDirectory, 'test-component.component.spec.ts')); |
| 19 | + await expectFileToExist(join(componentDirectory, 'test-component.component.html')); |
| 20 | + await expectFileToExist(join(componentDirectory, 'test-component.component.css')); |
| 21 | + |
| 22 | + // Generate another component |
| 23 | + await ng('generate', 'component', `${upperDirs}/Test-Component-Two`); |
12 | 24 |
|
13 |
| - return ng('generate', 'component', `${upperDirs}/test-component`) |
14 |
| - .then(() => expectFileToExist(componentDir)) |
15 |
| - .then(() => expectFileToExist(join(componentDir, 'test-component.component.ts'))) |
16 |
| - .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) |
17 |
| - .then(() => expectFileToExist(join(componentDir, 'test-component.component.html'))) |
18 |
| - .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) |
19 |
| - .then(() => ng('generate', 'component', `${upperDirs}/Test-Component-Two`)) |
20 |
| - .then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.ts'))) |
21 |
| - .then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.spec.ts'))) |
22 |
| - .then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.html'))) |
23 |
| - .then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.css'))) |
| 25 | + // Ensure component is created in the correct location relative to the workspace root |
| 26 | + await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.ts')); |
| 27 | + await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.spec.ts')); |
| 28 | + await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.html')); |
| 29 | + await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.css')); |
24 | 30 |
|
25 |
| - // Try to run the unit tests. |
26 |
| - .then(() => ng('test', '--watch=false')); |
| 31 | + // Ensure unit test execute and pass |
| 32 | + await ng('test', '--watch=false'); |
| 33 | + } finally { |
| 34 | + // Windows CI may fail to clean up the created directory |
| 35 | + // Resolves: "Error: Running "cmd.exe /c git clean -df" returned error code 1" |
| 36 | + await rimraf(rootDir); |
| 37 | + } |
27 | 38 | }
|
0 commit comments