Skip to content

Commit 87f707d

Browse files
author
Observable User
committed
add test for polling for repo auth; deploy.ts test coverage is now back up to status quo ante; fix polling for auth to respect deployOptions.deployPollInterval, though one could argue its now too narrowly named
1 parent 172bf50 commit 87f707d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/deploy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ class Deployer {
311311
providerId: source.provider_id
312312
});
313313
if (!remoteAuthedRepo) {
314+
// TODO: This could poll for auth too, but is a distinct case because it
315+
// means the repo was linked at one point and then something went wrong
314316
throw new CliError(
315317
`Cannot access configured repository; check build settings on ${link(
316318
`${settingsUrl(deployTarget)}/settings`
@@ -336,9 +338,10 @@ class Deployer {
336338

337339
const spinner = this.effects.clack.spinner();
338340
spinner.start("Waiting for repository to be authorized");
341+
const {deployPollInterval: pollInterval = DEPLOY_POLL_INTERVAL_MS} = this.deployOptions;
339342
const pollExpiration = Date.now() + DEPLOY_POLL_MAX_MS;
340343
while (!localRepo) {
341-
await new Promise((resolve) => setTimeout(resolve, 2000));
344+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
342345
if (Date.now() > pollExpiration) {
343346
spinner.stop("Waiting for repository to be authorized timed out.");
344347
throw new CliError("Repository authorization failed");

test/deploy-test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,41 @@ describe("deploy", () => {
300300
effects.close();
301301
});
302302

303+
it("starts cloud build when continuous deployment is enabled for new project and repo is manually auth’ed while CLI is polling", async () => {
304+
const deployId = "deploy123";
305+
getCurrentObservableApi()
306+
.handleGetCurrentUser()
307+
.handleGetWorkspaceProjects({
308+
workspaceLogin: DEPLOY_CONFIG.workspaceLogin,
309+
projects: []
310+
})
311+
.handlePostProject({projectId: DEPLOY_CONFIG.projectId, slug: DEPLOY_CONFIG.projectSlug})
312+
.handleGetRepository({status: 404})
313+
.handleGetRepository()
314+
.handlePostProjectEnvironment()
315+
.handlePostProjectBuild()
316+
.handleGetProject({...DEPLOY_CONFIG, latestCreatedDeployId: deployId})
317+
.handleGetDeploy({deployId, deployStatus: "uploaded"})
318+
.start();
319+
const effects = new MockDeployEffects();
320+
effects.clack.inputs.push(
321+
true, // No apps found. Do you want to create a new app?
322+
DEPLOY_CONFIG.projectSlug, // What slug do you want to use?
323+
"public", // Who is allowed to access your app?
324+
true // Do you want to enable continuous deployment?
325+
);
326+
327+
await (await open("readme.md", "a")).close();
328+
const {stdout, stderr} = await promisify(exec)(
329+
"git add . && git commit -m 'initial' && git remote add origin [email protected]:observablehq/test.git"
330+
);
331+
console.log("starts cloud build test", {stdout, stderr});
332+
333+
await deploy(TEST_OPTIONS, effects);
334+
335+
effects.close();
336+
});
337+
303338
it("starts cloud build when continuous deployment is enabled for existing project with existing source", async () => {
304339
const deployId = "deploy123";
305340
getCurrentObservableApi()

0 commit comments

Comments
 (0)