function snapshot(name, content, opt_breakpoints, opt_enableJs) {
  const enableJs = opt_enableJs || false;
  const defaultBreakpointNames = Object.keys(
      registeredBreakpoints);
  // Transform the `breakpoints` array of named breakpoints into an array of
  // integer widths, mapped by the breakpoints config.
  /** @type {Array<string>} */
  var breakpointNamesList = opt_breakpoints || defaultBreakpointNames;

  const widths = getWidthsFromBreakpointNames(breakpointNamesList);

  // Add a new promise to the list of resource uploads so that finalize_build
  // can wait on resource uploads. We MUST do this immediately here with a
  // custom promise, not wait for the nested `uploadResource()` promise below,
  // to avoid creating a race condition where the uploads array may be missing
  // some possible upload promises.
  //
  // Nasty way to get a reference to the `resolve` method so that we can
  // manually resolve this promise below.
  // http://stackoverflow.com/a/26150465/128597
  var resolveAfterHtmlResourceUploaded;
  var htmlResourceUploadedPromise = new Promise(function(resolve) {
    resolveAfterHtmlResourceUploaded = resolve;
  });
  snapshotResourceUploadPromises.push(htmlResourceUploadedPromise);

  percyBuildPromise.then(function(buildResponse) {
    const percyBuildData = buildResponse.body.data;

    // Construct the root resource and create the snapshot.
    var htmlResource = percyClient.makeResource({
      resourceUrl: '/',
      content: content,
      isRoot: true,
      mimetype: 'text/html',
    });

    var snapshotPromise = percyClient.createSnapshot(
        percyBuildData.id,
        [htmlResource],
        {
          name: name,
          widths: widths,
          enableJavaScript: enableJs,
        });

    // Upload missing resources (just the root resource HTML in this case).
    snapshotPromise.then((response) => {
      var snapshotId = response.body.data.id;

      var missingResources = parseMissingResources(response);
      logDebug('Missing snapshot resources', missingResources);
      uploadHtml(percyBuildData.id, snapshotId, htmlResource, missingResources,
          resolveAfterHtmlResourceUploaded);
    }, (error) => {
      // TODO: Exit with error exit code? May not want to silently let this
      // pass. Need to discuss as a team our strategy for handling failures with
      // percy and determine how reliable percy is.
      if (error.statusCode && error.statusCode == 400) {
        console.warn(
            '[percy][WARNING] Bad request error, skipping snapshot: ' + name
        );
        console.warn(error.toString());
        // Skip this snapshot, resolve on error to unblock the finalization
        // promise chain.
        resolveAfterHtmlResourceUploaded();
      } else {
        handlePercyFailure(error);
      }
    });
  });
}
/**
 * Creates a dom snapshot and adds it to the percy client.
 * It will:
 *   - create config for snapshot widths.
 *   - call percySnapshot() passing widths and html content.
 *   - trigger uploading snapshots to percy if it doesn't already have them.
 *
 * @param {string} name The name to use for this snapshot.
 *     E.g. 'carousel-simple'
 * @param {string} content The html content as a string to take a snapshot of.
 * @param {Array<string>=} opt_breakpoints A list of breakpoint names.
 * @param {boolean=} opt_enableJs Whether or not to enable javascript.
 */
Creates a dom snapshot and adds it to the percy client.
It will:
- create config for snapshot widths.
- call percySnapshot() passing widths and html content.
- trigger uploading snapshots to percy if it doesn't already have them.

@param {string} name The name to use for this snapshot.
Creates a dom snapshot and adds it to the percy client . It will : - create config for snapshot widths . - call percySnapshot () passing widths and html content . - trigger uploading snapshots to percy if it doesn ' t already have them . @param { string } name The name to use for this snapshot .
function snapshot(name, content, opt_breakpoints, opt_enableJs) {
  const enableJs = opt_enableJs || false;
  const defaultBreakpointNames = Object.keys(
      registeredBreakpoints);
  var breakpointNamesList = opt_breakpoints || defaultBreakpointNames;
  const widths = getWidthsFromBreakpointNames(breakpointNamesList);
   Nasty way to get a reference to the `resolve` method so that we can
   manually resolve this promise below.
   http:stackoverflow.com/a/26150465/128597
  var resolveAfterHtmlResourceUploaded;
  var htmlResourceUploadedPromise = new Promise(function(resolve) {
    resolveAfterHtmlResourceUploaded = resolve;
  });
  snapshotResourceUploadPromises.push(htmlResourceUploadedPromise);
  percyBuildPromise.then(function(buildResponse) {
    const percyBuildData = buildResponse.body.data;
     Construct the root resource and create the snapshot.
    var htmlResource = percyClient.makeResource({
      resourceUrl: '/',
      content: content,
      isRoot: true,
      mimetype: 'text/html',
    });
    var snapshotPromise = percyClient.createSnapshot(
        percyBuildData.id,
        [htmlResource],
        {
          name: name,
          widths: widths,
          enableJavaScript: enableJs,
        });
     Upload missing resources (just the root resource HTML in this case).
    snapshotPromise.then((response) => {
      var snapshotId = response.body.data.id;
      var missingResources = parseMissingResources(response);
      logDebug('Missing snapshot resources', missingResources);
      uploadHtml(percyBuildData.id, snapshotId, htmlResource, missingResources,
          resolveAfterHtmlResourceUploaded);
    }, (error) => {
       TODO: Exit with error exit code? May not want to silently let this
       pass. Need to discuss as a team our strategy for handling failures with
       percy and determine how reliable percy is.
      if (error.statusCode && error.statusCode == 400) {
        console.warn(
            '[percy][WARNING] Bad request error, skipping snapshot: ' + name
        );
        console.warn(error.toString());
         Skip this snapshot, resolve on error to unblock the finalization
         promise chain.
        resolveAfterHtmlResourceUploaded();
      } else {
        handlePercyFailure(error);
      }
    });
  });
}
function snapshot ( name , content , opt_breakpoints , opt_enableJs ) { const enableJs = opt_enableJs || false ; const defaultBreakpointNames = Object . keys ( registeredBreakpoints ) ; var breakpointNamesList = opt_breakpoints || defaultBreakpointNames ; const widths = getWidthsFromBreakpointNames ( breakpointNamesList ) ; var resolveAfterHtmlResourceUploaded ; var htmlResourceUploadedPromise = new Promise ( function ( resolve ) { resolveAfterHtmlResourceUploaded = resolve ; } ) ; snapshotResourceUploadPromises . push ( htmlResourceUploadedPromise ) ; percyBuildPromise . then ( function ( buildResponse ) { const percyBuildData = buildResponse . body . data ; var htmlResource = percyClient . makeResource ( { resourceUrl : '/' , content : content , isRoot : true , mimetype : 'text/html' , } ) ; var snapshotPromise = percyClient . createSnapshot ( percyBuildData . id , [ htmlResource ] , { name : name , widths : widths , enableJavaScript : enableJs , } ) ; snapshotPromise . then ( ( response ) => { var snapshotId = response . body . data . id ; var missingResources = parseMissingResources ( response ) ; logDebug ( 'Missing snapshot resources' , missingResources ) ; uploadHtml ( percyBuildData . id , snapshotId , htmlResource , missingResources , resolveAfterHtmlResourceUploaded ) ; } , ( error ) => { if ( error . statusCode && error . statusCode == 400 ) { console . warn ( '[percy][WARNING] Bad request error, skipping snapshot: ' + name ) ; console . warn ( error . toString ( ) ) ; resolveAfterHtmlResourceUploaded ( ) ; } else { handlePercyFailure ( error ) ; } } ) ; } ) ; }
Creates a dom snapshot and adds it to the percy client.
Creates a dom snapshot and adds it to the percy client .
// Transform the `breakpoints` array of named breakpoints into an array of // integer widths, mapped by the breakpoints config. /** @type {Array<string>} */ // Add a new promise to the list of resource uploads so that finalize_build // can wait on resource uploads. We MUST do this immediately here with a // custom promise, not wait for the nested `uploadResource()` promise below, // to avoid creating a race condition where the uploads array may be missing // some possible upload promises. // // Nasty way to get a reference to the `resolve` method so that we can // manually resolve this promise below. // http://stackoverflow.com/a/26150465/128597 // Construct the root resource and create the snapshot. // Upload missing resources (just the root resource HTML in this case). // TODO: Exit with error exit code? May not want to silently let this // pass. Need to discuss as a team our strategy for handling failures with // percy and determine how reliable percy is. // Skip this snapshot, resolve on error to unblock the finalization // promise chain.