Skip to content

Commit 27128bb

Browse files
committed
ALL TESTS PASSING incl coverage threshold, thanks to testing cloud build of preconfigured project
1 parent 14ce19b commit 27128bb

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

src/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class Deployer {
279279
if (!isGit) throw new CliError("Not at root of a git repository.");
280280

281281
const {ownerName, repoName} = await getGitHubRemote();
282-
const branch = (await promisify(exec)("git rev-parse --abbrev-ref HEAD")).stdout;
282+
const branch = (await promisify(exec)("git rev-parse --abbrev-ref HEAD")).stdout.trim();
283283
let localRepo = await this.apiClient.getGitHubRepository({ownerName, repoName});
284284

285285
// If a source repository has already been configured, check that it’s

test/deploy-test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,47 @@ describe("deploy", () => {
283283
effects.close();
284284
});
285285

286+
it("starts cloud build when continuous deployment is enabled for existing project with existing source", async () => {
287+
const deployId = "deploy123";
288+
getCurrentObservableApi()
289+
.handleGetCurrentUser()
290+
.handleGetProject({
291+
...DEPLOY_CONFIG,
292+
source: {
293+
provider: "github",
294+
provider_id: "123:456",
295+
url: "https://github.com/observablehq/test.git",
296+
branch: "main"
297+
},
298+
latestCreatedDeployId: null
299+
})
300+
.handleGetRepository({useProviderId: true})
301+
.handlePostProjectBuild()
302+
.handleGetProject({
303+
...DEPLOY_CONFIG,
304+
source: {
305+
provider: "github",
306+
provider_id: "123:456",
307+
url: "https://github.com/observablehq/test.git",
308+
branch: "main"
309+
},
310+
latestCreatedDeployId: deployId
311+
})
312+
.handleGetDeploy({deployId, deployStatus: "uploaded"})
313+
.start();
314+
const effects = new MockDeployEffects({deployConfig: {...DEPLOY_CONFIG, continuousDeployment: true}});
315+
effects.clack.inputs.push(
316+
"bi" // Which app do you want to use?
317+
);
318+
319+
await promisify(exec)(
320+
"touch readme.md; git add .; git commit -m 'initial'; git remote add origin https://github.com/observablehq/test.git"
321+
);
322+
323+
await deploy(TEST_OPTIONS, effects);
324+
325+
effects.close();
326+
});
286327
});
287328

288329
describe("in isolated directory without git repo", () => {

test/mocks/observableApi.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class ObservableApiMock {
150150
title = "Build test case",
151151
accessLevel = "private",
152152
latestCreatedDeployId = null,
153+
source = null,
153154
status = 200
154155
}: {
155156
workspaceLogin: string;
@@ -158,6 +159,7 @@ class ObservableApiMock {
158159
title?: string;
159160
accessLevel?: string;
160161
status?: number;
162+
source?: GetProjectResponse["source"];
161163
latestCreatedDeployId?: null | string;
162164
}): ObservableApiMock {
163165
const response =
@@ -168,11 +170,11 @@ class ObservableApiMock {
168170
slug: projectSlug,
169171
title,
170172
creator: {id: "user-id", login: "user-login"},
171-
owner: {id: "workspace-id", login: "workspace-login"},
173+
owner: {id: "workspace-id", login: workspaceLogin},
172174
latestCreatedDeployId,
173175
automatic_builds_enabled: true,
174176
build_environment_id: "abc123",
175-
source: null
177+
source
176178
} satisfies GetProjectResponse)
177179
: emptyErrorBody;
178180
const headers = authorizationHeader(status !== 401 && status !== 403);
@@ -435,7 +437,7 @@ class ObservableApiMock {
435437
return this;
436438
}
437439

438-
handleGetRepository({status = 200}: {status?: number} = {}) {
440+
handleGetRepository({status = 200, useProviderId = false}: {status?: number; useProviderId?: boolean} = {}) {
439441
const response =
440442
status === 200
441443
? JSON.stringify({
@@ -448,11 +450,24 @@ class ObservableApiMock {
448450
})
449451
: emptyErrorBody;
450452
const headers = authorizationHeader(status !== 401);
451-
this._handlers.push((pool) =>
452-
pool
453-
.intercept({path: "/cli/github/repository?owner=observablehq&repo=test", headers: headersMatcher(headers)})
454-
.reply(status, response, {headers: {"content-type": "application/json"}})
455-
);
453+
if (useProviderId) {
454+
// version that accepts provider_id
455+
this._handlers.push((pool) =>
456+
pool
457+
.intercept({
458+
path: `/cli/github/repository?provider_id=${encodeURIComponent("123:456")}`,
459+
headers: headersMatcher(headers)
460+
})
461+
.reply(status, response, {headers: {"content-type": "application/json"}})
462+
);
463+
} else {
464+
// version that accepts owner & repo
465+
this._handlers.push((pool) =>
466+
pool
467+
.intercept({path: "/cli/github/repository?owner=observablehq&repo=test", headers: headersMatcher(headers)})
468+
.reply(status, response, {headers: {"content-type": "application/json"}})
469+
);
470+
}
456471
return this;
457472
}
458473

0 commit comments

Comments
 (0)