Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit d80073b

Browse files
committed
chore: fixes tests
1 parent 78375ac commit d80073b

File tree

4 files changed

+40
-43
lines changed

4 files changed

+40
-43
lines changed

docs/README_contributors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ npm test
150150

151151
```
152152
cd ngx-deploy-starter/src
153+
npx prettier --write '**/*'
153154
npm run build
154155
npm run test
155156
npm publish dist --access public

src/deploy/actions.spec.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,13 @@ describe('Deploy Angular apps', () => {
7070
___?: ScheduleOptions
7171
) =>
7272
Promise.resolve({
73-
result: Promise.resolve(
74-
createBuilderOutputMock(false, 'build error test')
75-
)
73+
result: Promise.resolve(createBuilderOutputMock(false))
7674
} as BuilderRun);
7775
try {
7876
await deploy(mockEngine, context, 'host', {});
7977
fail();
8078
} catch (e) {
81-
expect(e.message).toMatch(/build error test/);
79+
expect(e.message).toEqual('Error while building the app.');
8280
}
8381
});
8482
});
@@ -112,18 +110,16 @@ const initMocks = () => {
112110
Promise.resolve({} as BuilderRun),
113111
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) =>
114112
Promise.resolve({
115-
result: Promise.resolve(createBuilderOutputMock(true, ''))
113+
result: Promise.resolve(createBuilderOutputMock(true))
116114
} as BuilderRun)
117115
};
118116
};
119117

120-
const createBuilderOutputMock = (
121-
success: boolean,
122-
error: string
123-
): BuilderOutput => {
118+
const createBuilderOutputMock = (success: boolean): BuilderOutput => {
124119
return {
125120
info: { info: null },
126-
error: error,
121+
// unfortunately error is undefined in case of a build errors
122+
error: (undefined as unknown) as string,
127123
success: success,
128124
target: {} as Target
129125
};

src/deploy/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default async function deploy(
4949
const buildResult = await build.result;
5050

5151
if (!buildResult.success) {
52-
throw new Error(buildResult.error);
52+
throw new Error('Error while building the app.');
5353
}
5454
}
5555

src/deploy/builder.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,50 @@ import { Schema } from './schema';
1616
// createJobHandler() but add typings specific to Architect Builders.
1717
export default createBuilder<any>(
1818
async (options: Schema, context: BuilderContext): Promise<BuilderOutput> => {
19-
// The project root is added to a BuilderContext.
20-
const root = normalize(context.workspaceRoot);
21-
const workspace = new experimental.workspace.Workspace(
22-
root,
23-
new NodeJsSyncHost()
24-
);
25-
await workspace
26-
.loadWorkspaceFromHost(normalize('angular.json'))
27-
.toPromise();
19+
try {
20+
// The project root is added to a BuilderContext.
21+
const root = normalize(context.workspaceRoot);
22+
const workspace = new experimental.workspace.Workspace(
23+
root,
24+
new NodeJsSyncHost()
25+
);
26+
await workspace
27+
.loadWorkspaceFromHost(normalize('angular.json'))
28+
.toPromise();
2829

29-
if (!context.target) {
30-
throw new Error('Cannot deploy the application without a target');
31-
}
30+
if (!context.target) {
31+
throw new Error('Cannot deploy the application without a target');
32+
}
3233

33-
const targets = workspace.getProjectTargets(context.target.project);
34+
const targets = workspace.getProjectTargets(context.target.project);
3435

35-
if (
36-
!targets ||
37-
!targets.build ||
38-
!targets.build.options ||
39-
!targets.build.options.outputPath
40-
) {
41-
throw new Error('Cannot find the project output directory');
42-
}
36+
if (
37+
!targets ||
38+
!targets.build ||
39+
!targets.build.options ||
40+
!targets.build.options.outputPath
41+
) {
42+
throw new Error('Cannot find the project output directory');
43+
}
4344

44-
// normalizes pathes don't work with all native functions
45-
// as a workaround, you can use the following 2 lines
46-
const isWin = os.platform() === 'win32';
47-
const workspaceRoot = !isWin
48-
? workspace.root
49-
: asWindowsPath(workspace.root);
50-
// if this is not necessary, use this:
51-
// const workspaceRoot = workspace.root;
45+
// normalizes pathes don't work with all native functions
46+
// as a workaround, you can use the following 2 lines
47+
const isWin = os.platform() === 'win32';
48+
const workspaceRoot = !isWin
49+
? workspace.root
50+
: asWindowsPath(workspace.root);
51+
// if this is not necessary, use this:
52+
// const workspaceRoot = workspace.root;
5253

53-
try {
5454
await deploy(
5555
engine,
5656
context,
5757
path.join(workspaceRoot, targets.build.options.outputPath),
5858
options
5959
);
6060
} catch (e) {
61-
context.logger.error('Error when trying to deploy:', e);
62-
console.error(e);
61+
context.logger.error('❌ An error occurred when trying to deploy:');
62+
context.logger.error(e.message);
6363
return { success: false };
6464
}
6565

0 commit comments

Comments
 (0)