|
1 | | -import {join} from 'path'; |
2 | | -import {ng} from '../../../utils/process'; |
3 | | -import {createDir, expectFileToExist} from '../../../utils/fs'; |
| 1 | +import { join } from 'path'; |
| 2 | +import { ng } from '../../../utils/process'; |
| 3 | +import { createDir, expectFileToExist, rimraf } from '../../../utils/fs'; |
4 | 4 |
|
| 5 | +export default async function () { |
| 6 | + const currentDirectory = process.cwd(); |
| 7 | + const childDirectory = join('src', 'app', 'sub-dir'); |
5 | 8 |
|
6 | | -export default function() { |
7 | | - const subDir = 'sub-dir'; |
8 | | - const componentDir = join('src', 'app', subDir, 'test-component'); |
| 9 | + try { |
| 10 | + // Create and enter a child directory inside the project |
| 11 | + await createDir(childDirectory); |
| 12 | + process.chdir(childDirectory); |
9 | 13 |
|
10 | | - return Promise.resolve() |
11 | | - .then(() => process.chdir('src')) |
12 | | - .then(() => process.chdir('app')) |
13 | | - .then(() => createDir(subDir)) |
14 | | - .then(() => process.chdir(subDir)) |
15 | | - .then(() => ng('generate', 'component', 'test-component')) |
16 | | - .then(() => process.chdir('../../..')) |
17 | | - .then(() => expectFileToExist(join(componentDir, 'test-component.component.ts'))) |
18 | | - .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) |
19 | | - .then(() => expectFileToExist(join(componentDir, 'test-component.component.html'))) |
20 | | - .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) |
| 14 | + // Generate a component inside the child directory |
| 15 | + await ng('generate', 'component', 'test-component'); |
21 | 16 |
|
22 | | - // Try to run the unit tests. |
23 | | - .then(() => ng('test', '--watch=false')); |
| 17 | + // Move back to the root of the workspacee |
| 18 | + process.chdir(currentDirectory); |
| 19 | + |
| 20 | + // Ensure component is created in the correct location relative to the workspace root |
| 21 | + const componentDirectory = join(childDirectory, 'test-component'); |
| 22 | + await expectFileToExist(join(componentDirectory, 'test-component.component.ts')); |
| 23 | + await expectFileToExist(join(componentDirectory, 'test-component.component.spec.ts')); |
| 24 | + await expectFileToExist(join(componentDirectory, 'test-component.component.html')); |
| 25 | + await expectFileToExist(join(componentDirectory, 'test-component.component.css')); |
| 26 | + |
| 27 | + // Ensure unit test execute and pass |
| 28 | + await ng('test', '--watch=false'); |
| 29 | + } finally { |
| 30 | + // Windows CI may fail to clean up the created directory |
| 31 | + // Resolves: "Error: Running "cmd.exe /c git clean -df" returned error code 1" |
| 32 | + await rimraf(childDirectory); |
| 33 | + } |
24 | 34 | } |
0 commit comments