Skip to content

Commit 5c08218

Browse files
committed
fixes broken tests
1 parent 756852f commit 5c08218

File tree

3 files changed

+33
-53
lines changed

3 files changed

+33
-53
lines changed

deploy/actions.spec.ts

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { JsonObject, logging } from '@angular-devkit/core';
2-
import {
3-
BuilderContext,
4-
BuilderRun,
5-
ScheduleOptions,
6-
Target
7-
} from '@angular-devkit/architect/src/index';
2+
import { BuilderContext, BuilderRun, ScheduleOptions, Target } from '@angular-devkit/architect/src/index';
83
import deploy from './actions';
94

105
let context: BuilderContext;
6+
const mockEngine = { run: (_: string, __: any, __2: any) => Promise.resolve() }
117

128
const PROJECT = 'pirojok-project';
139

@@ -16,17 +12,10 @@ describe('Deploy Angular apps', () => {
1612

1713
it('should invoke the builder', async () => {
1814
const spy = spyOn(context, 'scheduleTarget').and.callThrough();
19-
await deploy(
20-
{
21-
publish: (_: string, __: any) => Promise.resolve()
22-
},
23-
context,
24-
'host',
25-
{}
26-
);
15+
await deploy(mockEngine, context, 'host', {});
16+
2717
expect(spy).toHaveBeenCalled();
28-
expect(spy).toHaveBeenCalledWith(
29-
{
18+
expect(spy).toHaveBeenCalledWith({
3019
target: 'build',
3120
configuration: 'production',
3221
project: PROJECT
@@ -35,28 +24,19 @@ describe('Deploy Angular apps', () => {
3524
);
3625
});
3726

38-
it('should invoke ghpages.publish', async () => {
39-
const mock = {
40-
publish: (_: string, __: any) => Promise.resolve()
41-
};
42-
const spy = spyOn(mock, 'publish').and.callThrough();
43-
await deploy(mock, context, 'host', {});
27+
it('should invoke engine.run', async () => {
28+
const spy = spyOn(mockEngine, 'run').and.callThrough();
29+
await deploy(mockEngine, context, 'host', {});
30+
4431
expect(spy).toHaveBeenCalled();
45-
expect(spy).toHaveBeenCalledWith('host', {});
32+
expect(spy).toHaveBeenCalledWith('host', {}, context.logger);
4633
});
4734

4835
describe('error handling', () => {
4936
it('throws if there is no target project', async () => {
5037
context.target = undefined;
5138
try {
52-
await deploy(
53-
{
54-
publish: (_: string, __: any) => Promise.resolve()
55-
},
56-
context,
57-
'host',
58-
{}
59-
);
39+
await deploy(mockEngine, context, 'host', {});
6040
fail();
6141
} catch (e) {
6242
expect(e.message).toMatch(/Cannot execute the build target/);
@@ -81,17 +61,15 @@ const initMocks = () => {
8161
id: 1,
8262
logger: new logging.NullLogger() as any,
8363
workspaceRoot: 'cwd',
84-
addTeardown: _ => {},
64+
addTeardown: _ => { },
8565
validateOptions: _ => Promise.resolve({} as any),
8666
getBuilderNameForTarget: () => Promise.resolve(''),
8767
analytics: null as any,
8868
getTargetOptions: (_: Target) => Promise.resolve({}),
89-
reportProgress: (_: number, __?: number, ___?: string) => {},
90-
reportStatus: (_: string) => {},
91-
reportRunning: () => {},
92-
scheduleBuilder: (_: string, __?: JsonObject, ___?: ScheduleOptions) =>
93-
Promise.resolve({} as BuilderRun),
94-
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) =>
95-
Promise.resolve({} as BuilderRun)
69+
reportProgress: (_: number, __?: number, ___?: string) => { },
70+
reportStatus: (_: string) => { },
71+
reportRunning: () => { },
72+
scheduleBuilder: (_: string, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun),
73+
scheduleTarget: (_: Target, __?: JsonObject, ___?: ScheduleOptions) => Promise.resolve({} as BuilderRun)
9674
};
9775
};

deploy/actions.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { BuilderContext } from '@angular-devkit/architect';
22
import { Schema as RealDeployOptions } from './schema';
33
import { json, logging } from '@angular-devkit/core';
4-
import { run } from '../engine/engine';
54

65
type DeployOptions = RealDeployOptions & json.JsonObject;
76

87
export default async function deploy(
8+
engine: { run: (dir: string, options: RealDeployOptions, logger: logging.LoggerApi) => Promise<void> },
99
context: BuilderContext,
1010
projectRoot: string,
1111
options: DeployOptions
@@ -18,13 +18,15 @@ export default async function deploy(
1818
context.logger.info(`📦 Building "${context.target.project}"`);
1919

2020
const build = await context.scheduleTarget({
21-
target: 'build',
22-
project: context.target.project,
23-
configuration: 'production'
24-
},
25-
options
26-
);
21+
target: 'build',
22+
project: context.target.project,
23+
configuration: 'production'
24+
}, options);
2725
await build.result;
2826

29-
await run(projectRoot, options, context.logger as unknown as logging.LoggerApi);
27+
await engine.run(
28+
projectRoot,
29+
options,
30+
context.logger as unknown as logging.LoggerApi
31+
);
3032
}

deploy/builder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {
2-
BuilderContext,
3-
BuilderOutput,
4-
createBuilder
5-
} from '@angular-devkit/architect';
1+
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
62
import { NodeJsSyncHost } from '@angular-devkit/core/node';
7-
import deploy from './actions';
83
import { experimental, join, normalize, json } from '@angular-devkit/core';
94
import { Schema as RealDeployOptions } from './schema';
5+
6+
import deploy from './actions';
7+
import * as engine from '../engine/engine';
8+
109
type DeployOptions = RealDeployOptions & json.JsonObject;
1110

1211
// Call the createBuilder() function to create a builder. This mirrors
@@ -43,6 +42,7 @@ export default createBuilder<any>(
4342

4443
try {
4544
await deploy(
45+
engine,
4646
context,
4747
join(workspace.root, targets.build.options.outputPath),
4848
options

0 commit comments

Comments
 (0)