Skip to content

Commit 88936e6

Browse files
committed
fix naming
1 parent 5a414ac commit 88936e6

File tree

10 files changed

+22
-18
lines changed

10 files changed

+22
-18
lines changed

packages/synthetics-sdk-broken-links/src/broken_links.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ export async function runBrokenLinks(
138138
const storageParams: StorageParameters = {
139139
storageClient: storageClient,
140140
bucket: bucket,
141-
checkId: 'fake-check-id',
142-
executionId: 'fake-execution-id',
141+
checkId: 'fake-check-id',
142+
executionId: 'fake-execution-id',
143+
screenshotNumber: 1,
143144
};
144145

145146
const followed_links: BrokenLinksResultV1_SyntheticLinkResult[] = [];

packages/synthetics-sdk-broken-links/src/link_utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export function sanitizeObjectName(
331331
.replace(/\s+/g, '_'); // Replace one or more spaces with underscores
332332
}
333333

334-
export function getStoragePagetStoragePathToExecutionthToExecution(
334+
export function getStoragePathToExecution(
335335
storageParams: StorageParameters,
336336
options: BrokenLinksResultV1_BrokenLinkCheckerOptions
337337
) {

packages/synthetics-sdk-broken-links/src/options_func.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export function setDefaultOptions(
290290
defaultOptions.screenshot_options!.capture_condition;
291291
}
292292

293-
if (outputOptions.screenshot_options?.storage_location) {
293+
if (inputOptions.screenshot_options?.storage_location) {
294294
outputOptions.screenshot_options.storage_location =
295295
inputOptions.screenshot_options!.storage_location!;
296296
} else {

packages/synthetics-sdk-broken-links/src/storage_func.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ export interface StorageParameters {
3535
bucket: Bucket | null;
3636
checkId: string;
3737
executionId: string;
38+
screenshotNumber: number;
3839
}
3940

40-
let SCREENSHOT_NUMBER = 1;
41-
4241
/**
4342
* Attempts to get an existing storage bucket if provided by the user OR
4443
* create/use a dedicated synthetics bucket.
@@ -56,15 +55,13 @@ export async function getOrCreateStorageBucket(
5655
storageLocation: string,
5756
errors: BaseError[]
5857
): Promise<Bucket | null> {
59-
SCREENSHOT_NUMBER = 1;
6058
let bucketName = '';
6159

6260
try {
6361
if (!storageClient) return null;
6462

6563
const projectId = sanitizeObjectName(await resolveProjectId());
6664
const region = sanitizeObjectName(await getExecutionRegion());
67-
// const region = "us-east4"
6865

6966
// if the user chose to use/create the default bucket but we were not able
7067
// to resolve projectId or cloudRegion
@@ -159,8 +156,8 @@ export async function uploadScreenshotToGCS(
159156
return screenshot_output;
160157
}
161158

162-
const screenshot: Buffer = await page.screenshot({ encoding: 'binary' });
163-
const filename = 'screenshot_' + SCREENSHOT_NUMBER + '.png';
159+
const screenshot: Buffer = await page.screenshot({ fullPage: true, encoding: 'binary' });
160+
const filename = 'screenshot_' + storageParams.screenshotNumber + '.png';
164161

165162
const writeDestination = path.join(
166163
getStoragePathToExecution(storageParams, options),
@@ -172,7 +169,7 @@ export async function uploadScreenshotToGCS(
172169
contentType: 'image/png',
173170
});
174171

175-
SCREENSHOT_NUMBER += 1;
172+
storageParams.screenshotNumber += 1;
176173
screenshot_output.screenshot_file = filename;
177174
} catch (err) {
178175
// Handle upload errors

packages/synthetics-sdk-broken-links/test/unit/link_utils.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('GCM Synthetics Broken Links Utilies', async () => {
6969
bucket: {} as Bucket,
7070
checkId: 'uptime123',
7171
executionId: 'exec456',
72+
screenshotNumber: 1,
7273
};
7374

7475
it('checkStatusPassing returns correctly when passed a number as ResponseStatusCode', () => {
@@ -229,8 +230,8 @@ describe('GCM Synthetics Broken Links Utilies', async () => {
229230

230231
describe('sanitizeObjectName', () => {
231232
it('should remove invalid characters', () => {
232-
const input = "test/\@#$%^&*()/_+\-=[]{};':\"\|,.<>/?\r\n\t";
233-
const expectedOutput = "test_@_$%^&_()__+-=__{};'__\_,.______";
233+
const input = 'test/@#$%^&*()/_+-=[]{};\':"|,.<>/?\r\n\t';
234+
const expectedOutput = "test_@_$%^&_()__+-=__{};'___,.______";
234235
expect(sanitizeObjectName(input)).to.equal(expectedOutput);
235236
});
236237

packages/synthetics-sdk-broken-links/test/unit/navigation_func.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ describe('GCM Synthetics Broken Links Navigation Functionality', async () => {
8080
bucket: sinon.createStubInstance(Bucket),
8181
checkId: '',
8282
executionId: '',
83+
screenshotNumber: 1,
8384
};
8485

8586
// Use proxyquire to replace uploadScreenshotToGCS
@@ -339,7 +340,7 @@ describe('GCM Synthetics Broken Links Navigation Functionality', async () => {
339340
});
340341
});
341342

342-
describe.only('retrieveLinksFromPage', async () => {
343+
describe('retrieveLinksFromPage', async () => {
343344
// Puppeteer constants
344345
let browser: Browser;
345346
let page: Page;

packages/synthetics-sdk-broken-links/test/unit/storage_func.spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ describe('GCM Synthetics Broken Links storage_func suite testing', () => {
184184
bucket: bucketStub,
185185
checkId: 'uptime123',
186186
executionId: 'exec456',
187+
screenshotNumber: 1,
187188
};
188189
const options = {
189190
screenshot_options: { storage_location: 'bucket/folder1/folder2' },
@@ -225,6 +226,7 @@ describe('GCM Synthetics Broken Links storage_func suite testing', () => {
225226
bucket: bucketStub,
226227
checkId: '',
227228
executionId: '',
229+
screenshotNumber: 1,
228230
};
229231
const options = {
230232
screenshot_options: {},
@@ -267,6 +269,7 @@ describe('GCM Synthetics Broken Links storage_func suite testing', () => {
267269
bucket: bucketStub,
268270
checkId: '',
269271
executionId: '',
272+
screenshotNumber: 1,
270273
};
271274

272275
const result = await uploadScreenshotToGCS(
@@ -288,7 +291,8 @@ describe('GCM Synthetics Broken Links storage_func suite testing', () => {
288291
bucket: null,
289292
checkId: '',
290293
executionId: '',
291-
};
294+
screenshotNumber: 1,
295+
} as StorageParameters;
292296

293297
const result = await uploadScreenshotToGCS(
294298
pageStub,
Binary file not shown.

samples/broken-links-ok/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const functions = require('@google-cloud/functions-framework');
1818
const GcmSynthetics = require('@google-cloud/synthetics-sdk-broken-links');
1919

2020
const options = {
21-
origin_uri: "https://en.wikipedia.org/wiki/World_War_II",
22-
link_limit: 50,
21+
origin_uri: "https://example.com",
22+
// link_limit: 10,
2323
// query_selector_all: "a", // https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
2424
// get_attributes: ['href'], // https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
2525
// link_order: "FIRST_N", // "FIRST_N" or "RANDOM"

samples/broken-links-ok/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"gcp-build": "node node_modules/puppeteer/install.mjs"
88
},
99
"dependencies": {
10-
"@google-cloud/synthetics-sdk-broken-links": "google-cloud-synthetics-sdk-broken-links-0.2.0.tgz",
10+
"@google-cloud/synthetics-sdk-broken-links": "^0.1.0",
1111
"@google-cloud/functions-framework": "^3.1.2"
1212
},
1313
"author": "Google Inc.",

0 commit comments

Comments
 (0)