percy / cli

The Percy CLI is used to interact with, and upload snapshots to, percy.io via the command line.
https://docs.percy.io/docs/cli-overview
70 stars 43 forks source link

percy build:finalize throws TypeError: checkForUpdate is not a function #757

Closed mosofsky closed 2 years ago

mosofsky commented 2 years ago

The problem

Upon upgrading from "@percy/cypress": "^2.3.1" to "@percy/cypress": "^3.0.0", I found that "@percy/cli": "^1.0.0-beta.74" was added to my package.json by the instructions at https://docs.percy.io/docs/cypress#upgrading-from-v2. However, on my Gitlab CI pipeline, the command percy build:finalize fails as follows:

$ yarn run percy:finalize
yarn run v1.22.4
$ percy build:finalize
(node:22) UnhandledPromiseRejectionWarning: TypeError: checkForUpdate is not a function
    at /builds/michael2[38](https://gitlab.com/michael238/abcplan/-/jobs/2051146233#L38)/abcplan/node_modules/@percy/cli/bin/run:11:11
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:22) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Done in 0.30s.

To be clear, when I was on "@percy/cypress": "^2.3.1", I did not call percy build:finalize but rather percy finalize --all but I suspect that needed to be migrated to percy build:finalize based on the documentation at https://github.com/percy/cli/tree/v1.0.0-beta.74/packages/cli-build#readme.

I checked https://docs.percy.io/docs/debugging-sdks but there was nothing there about this exception.

Environment

  "percy": {
    "version": 1,
    "snapshot": {
      "widths": [
        1280
      ]
    },
    "agent": {
      "asset-discovery": {
        "page-pool-size-min": 1,
        "page-pool-size-max": 1
      }
    }
  },
jb_percy_finalize:
  stage:
    stg_percy_finalize
  image: cypress/base:14
  except:
    - schedules
  script:
    - yarn run percy:finalize

Details

From what I can tell, the failure on line 11 of run corresponds to this code https://github.com/percy/cli/blob/02baf61a49f09fec97114553f7f2ef7943388920/packages/cli/bin/run :

#!/usr/bin/env node

if (parseInt(process.version.split('.')[0].substring(1), 10) < 12) {
  console.error(`Node ${process.version} is not supported. Percy only ` + (
    'supports the current LTS version of Node. Please upgrade to Node 12+'));
  process.exit(1);
}

import('../dist/index.js').then(
  async ({ checkForUpdate, percy }) => {
    await checkForUpdate();
    await percy(process.argv.slice(2));
  });

Maybe it's supposed to come from https://github.com/percy/cli/blob/7dff31566f0278de9653a2a63b2474d79b5c373e/packages/cli/src/index.js 👍

export { checkForUpdate } from './update';

And update.js is here https://github.com/percy/cli/blob/7dff31566f0278de9653a2a63b2474d79b5c373e/packages/cli/src/update.js

Lastly, checkForUpdate is defined here: https://github.com/percy/cli/blob/7dff31566f0278de9653a2a63b2474d79b5c373e/packages/cli/src/update.js#L66

Also, on my local Mac, I was able to navigate to node_modules/@percy/cli/dist/update.js and see checkForUpdate was defined as follows:

async function checkForUpdate() {
  let {
    data: releases,
    error: cacheError
  } = readFromCache();
  let log = (0, _logger.default)('cli:update');

  try {
    // request new release information if needed
    if (!releases) {
      releases = await fetchReleases();
      if (!cacheError) writeToCache(releases, log);
    } // check the current package version against released versions

    let versions = releases.map(r => r.tag.substr(1));
    let age = versions.indexOf(_package.default.version); // a new version is available

    if (age !== 0) {
      let range = `${_util.colors.red(_package.default.version)} -> ${_util.colors.green(versions[0])}`;
      log.stderr.write('\n');
      log.warn(`${age > 0 && age < 10 ? 'A new version of @percy/cli is available!' : 'Heads up! The current version of @percy/cli is more than 10 releases behind!'} ${range}`);
      log.stderr.write('\n');
    }
  } catch (err) {
    log.debug('Unable to check for updates');
    log.debug(err);
  }
}

Code to reproduce issue

n 14.8.0
yarn run percy:finalize
nyghtly-derek commented 2 years ago

That error message looks similar to the one I got in https://github.com/percy/cli/issues/756, which was also introduced when upgrading to that version of the percy cli.

mosofsky commented 2 years ago

@nyghtly-derek yes it does. We were both using @percy/cli 1.0.0-beta.74. But in my case, it seems like run got to line 11 but it only got to line 9 in yours, right?

nyghtly-derek commented 2 years ago

Yes, they are different in the way that you point out. How strange.