Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add rootResourceURL in front of percy specific resources #388

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/services/agent-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class AgentService {
profile('agentService.handleSnapshot')

// truncate domSnapshot for the logs if it's very large
const rootURL = request.body.url
let domSnapshotLog = request.body.domSnapshot
if (domSnapshotLog.length > Constants.MAX_LOG_LENGTH) {
domSnapshotLog = domSnapshotLog.substring(0, Constants.MAX_LOG_LENGTH)
Expand Down Expand Up @@ -116,7 +117,7 @@ export class AgentService {
}

let resources = await this.snapshotService.buildResources(
request.body.url,
rootURL,
domSnapshot,
snapshotOptions,
snapshotLogger,
Expand All @@ -133,9 +134,9 @@ export class AgentService {
}

resources = resources.concat(
this.snapshotService.buildRootResource(request.body.url, domSnapshot),
this.snapshotService.buildRootResource(rootURL, domSnapshot),
// @ts-ignore we won't write anything if css is not is passed
this.snapshotService.buildPercyCSSResource(percyCSSFileName, snapshotOptions.percyCSS, snapshotLogger),
this.snapshotService.buildPercyCSSResource(rootURL, percyCSSFileName, snapshotOptions.percyCSS, snapshotLogger),
this.snapshotService.buildLogResource(snapshotLog),
)

Expand Down
11 changes: 8 additions & 3 deletions src/services/snapshot-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as crypto from 'crypto'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import { URL } from 'url'
import { AssetDiscoveryConfiguration } from '../configuration/asset-discovery-configuration'
import { SnapshotOptions } from '../percy-agent-client/snapshot-options'
import { logError, profile } from '../utils/logger'
Expand Down Expand Up @@ -65,9 +66,13 @@ export default class SnapshotService extends PercyClientService {
})
}

buildPercyCSSResource(fileName: string, css: string, logger: any) {
buildPercyCSSResource(url: string, fileName: string, css: string, logger: any) {
if (!css) { return [] }
logger.debug(`Creating Percy Specific file: ${fileName}. CSS string: ${css}`)

const parsedRootResourceUrl = new URL(url)
const rootURL = `${parsedRootResourceUrl.protocol}//${parsedRootResourceUrl.host}`

logger.debug(`Creating Percy Specific file: ${fileName}. Root URL: ${rootURL}. CSS string: ${css}`)

const buffer = Buffer.from(css, 'utf8')
const sha = crypto.createHash('sha256').update(buffer).digest('hex')
Expand All @@ -81,7 +86,7 @@ export default class SnapshotService extends PercyClientService {
}

return this.percyClient.makeResource({
resourceUrl: `/${fileName}`,
resourceUrl: `${rootURL}/${fileName}`,
mimetype: 'text/css',
localPath,
sha,
Expand Down