cli.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env node
  2. /**
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* eslint-disable no-console */
  18. "use strict";
  19. var _utils = require("../utils");
  20. var _program = _interopRequireDefault(require("./program"));
  21. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  22. function printPlaywrightTestError(command) {
  23. const packages = [];
  24. for (const pkg of ['playwright', 'playwright-chromium', 'playwright-firefox', 'playwright-webkit']) {
  25. try {
  26. require.resolve(pkg);
  27. packages.push(pkg);
  28. } catch (e) {}
  29. }
  30. if (!packages.length) packages.push('playwright');
  31. const packageManager = (0, _utils.getPackageManager)();
  32. if (packageManager === 'yarn') {
  33. console.error(`Please install @playwright/test package before running "yarn playwright ${command}"`);
  34. console.error(` yarn remove ${packages.join(' ')}`);
  35. console.error(' yarn add -D @playwright/test');
  36. } else if (packageManager === 'pnpm') {
  37. console.error(`Please install @playwright/test package before running "pnpm exec playwright ${command}"`);
  38. console.error(` pnpm remove ${packages.join(' ')}`);
  39. console.error(' pnpm add -D @playwright/test');
  40. } else {
  41. console.error(`Please install @playwright/test package before running "npx playwright ${command}"`);
  42. console.error(` npm uninstall ${packages.join(' ')}`);
  43. console.error(' npm install -D @playwright/test');
  44. }
  45. }
  46. const kExternalPlaywrightTestCommands = [['test', 'Run tests with Playwright Test.'], ['show-report', 'Show Playwright Test HTML report.'], ['merge-reports', 'Merge Playwright Test Blob reports']];
  47. function addExternalPlaywrightTestCommands() {
  48. for (const [command, description] of kExternalPlaywrightTestCommands) {
  49. const playwrightTest = _program.default.command(command).allowUnknownOption(true);
  50. playwrightTest.description(`${description} Available in @playwright/test package.`);
  51. playwrightTest.action(async () => {
  52. printPlaywrightTestError(command);
  53. (0, _utils.gracefullyProcessExitDoNotHang)(1);
  54. });
  55. }
  56. }
  57. if (!process.env.PW_LANG_NAME) addExternalPlaywrightTestCommands();
  58. _program.default.parse(process.argv);