Files
appium/packages/gulp-plugins/README.md
T
Christopher Hiller 868517b6f4 chore: remove gulp from appium package (#16459)
This change removes `gulp` and replaces it with plain ol' `babel` and `mocha`.

## `appium`

- No gulp.
- `test/` has been re-organized.  All test files now end in the extension `.spec.js`, which is a recognized convention and understood by editors/IDEs.  The tests are further split into `unit` and `e2e` subdirs.  This makes working with both `babel` and `mocha` easier.
- The tests are _not_ run against the transpiled code; code is now transpiled on-the-fly via `@babel/register`. This only affects `appium`.
- `commands-yml/validator.js` moved to `scripts/parse-yml-commands.js`. It has been rewritten as a CJS module.  `commands-yml/` should not contain `.js` files.
- `test/setup.js` is a new test harness specific to Appium, which loads & configures `@babel/register`.  Eventually, the contents of this file can be moved into the root monorepo's `test/setup.js`, but the rest of the packages do not need `@babel/register`, so we avoid the overhead.

## `@appium/gulp-plugins`

- Unfortunately, due to the new `npm test` strategy (see below), we cannot use the `nyan` reporter.  Or rather, we _can_, but will not see the animation.  So the reporter is now set to default to `spec`.
- Modified tests so they didn't overwrite the actual `build` dir with transpiled fixtures, which is what was happening. This was causing failures depending on the transpile/test order.

## All Packages

- All packages now have their own `build`, `test`, `test:e2e` and `dev` (just build + watch mode) npm scripts. This makes running a complete build easier, since each package can now provide its own appropriate command.  This is _mostly_ just `gulp once` (where `gulp` was used before), except for `appium`, where `@babel/cli` is used directly.
- This is what happens when `npm test` is run from the monorepo (in order):
    1. All packages are built (in parallel) by running `npm run build` in each folder (via `lerna`). See `pretest`
    2. All code is linted directly via `eslint`.
    3. All _unit tests_ are run w/ `npm test` in each folder, having assumed transpilation already occurred (if necessary).
- `npm run e2e-test` runs the `npm run test:e2e` in each folder. No transpilation occurs! Careful.
- All scripts are expected to live in `packages/*/scripts`, and this directory enforces CJS via ESLint.  `postinstall.js` moved, as well as `check-npm-pack-files.js`. `generate-schema-declarations.mjs` moved from the root `scripts/` dir into `packages/appium/scripts/`; it's now CJS instead of ESM.
- I had profiled running various things with `lerna run --parallel`, but it turns out this is not faster.  I'm not sure why, but I think it may have something to do with streaming STDOUT/STDERR, or potentially the overhead of running child processes outweighs the time it takes to actually run tests and builds.
- The behavior of `lerna run` now mimicks `lerna exec`, which was "run stuff in serial, streaming the output". The default behavior of `lerna run` is "run stuff in parallel, buffering the output".  Buffered output sucks, and streaming the output from all tasks at once creates chaos.  To override this behavior, you'll see `--parallel --concurrency=8 --prefix` for tasks that can truly be parallelized, like transpilation.  The number 8 is the "maximum", and CI usually won't have more than 2 cores available anyway.
- When run in CI, Mocha runs with `--forbid-only`, which will fail if there's an `.only()` somewhere in the tests. Further, it forces color output.

## Etc.

- Updated Wallaby config, `.gitignore`, `.eslintignore`.
- Sorted `package.json` files
- Removed `watch` and `coverage` scripts which were broken anyway.

chore(appium): fix schema json path issues

- the path to the JSON schema is now correct: `lib/appium-config-schema.json`
- add `log-symbols` to devdeps for niceness. this is already a transitive dep
2022-03-09 14:50:45 -08:00

5.4 KiB

appium-gulp-plugins

Custom plugins used across appium modules

status

Build Status

boilerplate plugin

This plugin sets up all the other typical plugins we use with a simple configuration object.

usage

Basically just set up the boilerplate plugin as follows:

let gulp = require('gulp'),
    boilerplate = require('@appium/gulp-plugins').boilerplate.use(gulp);

boilerplate({build: "My Project Name"});

You can pass a lot of options to configure boilerplate. Here are the options along with their defaults (from lib/boilerplate.js):

const DEFAULT_OPTS = {
  files: ['*.js', 'lib/**/*.js', 'test/**/*.js', '!gulpfile.js'],
  transpile: true,
  transpileOut: 'build',
  babelOpts: {},
  linkBabelRuntime: true,
  watch: true,
  watchE2E: false,
  test: {
    files: ['${testDir}/**/*-specs.js', '!${testDir}/**/*-e2e-specs.js'],
    traceWarnings: false,
  },
  coverage: {
    files: ['./build/test/**/*-specs.js', '!./build/test/**/*-e2e-specs.js'],
    verbose: true,
  },
  'coverage-e2e': {
    files: ['./build/test/**/*-e2e-specs.js'],
    verbose: true,
  },
  e2eTest: {
    files: ['${testDir}/**/*-e2e-specs.js'],
    forceExit: false,
    traceWarnings: false,
  },
  testReporter: (process.env.TRAVIS || process.env.CI) ? 'spec' : 'nyan',
  testTimeout: 20000,
  build: 'Appium',
  extraPrepublishTasks: [],
  eslint: true,
  eslintOnWatch: false, // deprecated, move to lintOnWatch
  lintOnWatch: false,
  ci: {
    interval: 60000,
    owner: 'appium',
    repo: 'appium-build-store',
  },
};

As you can see, it defaults to transpiling with Babel, running eslint running tests, and with the default task being gulp watch.

transpile plugin

Babel compilation, sourcemaps and file renaming functionality in one plugin. .es7.js and .es6.js files will be automatically renamed to .js files. The necessary sourcemaps, comments and imports are also automatically added.

usage

1/ Configure gulp as below:

let gulp = require('gulp'),
Transpiler = require('appium-gulp-plugins').Transpiler;

gulp.task('transpile', function () {
  let transpiler = new Transpiler();
  // babel options are configurable in transpiler.babelOpts

  return gulp.src('test/fixtures/es7/**/*.js')
    .pipe(transpiler.stream())
    .pipe(gulp.dest('build'));
});

2/ in your code you need to mark the main and mocha files as below:

  • main: add // transpile:main at the beginning of the file (example here) .
  • mocha: add // transpile:mocha at the beginning of the file (example here)

Regular lib files do not need any extra comments.

watch plugin

There are some issues with Gulp 3.x error handling which cause the default gulp-watch to hang. This plugin is a small hack which solves that by respawning the whole process on error. This should not be needed in gulp 4.0.

Files in the /test directory that are named .*-specs.js are run. Tests which end in .*-e2e-specs.js are not run when watching. To run end-to-end tests, run gulp e2e-test:run.

usage

const gulp = require('gulp');
const spawnWatcher = require('./index').spawnWatcher.use(gulp, opts);

spawnWatcher.configure('watch', ['lib/**/*.js','test/**/*.js','!test/fixtures'], function () {
  // this is the watch action
  return runSequence('test');
});

The test function in spawnWatcher.configure should return a promise.

error handling

The spawn needs to catch error as soon as they happen. To do so use the spawnWatcher.handleError method, for instance:

// add error handling where needed
gulp.task('transpile', function () {
  return gulp.src('test/es7/**/*.js')
    .pipe(transpile())
    .on('error', spawnWatcher.handleError)
    .pipe(gulp.dest('build'));
});

gulp.task('test', ['transpile'] , function () {
  return gulp.src('build/test/a-specs.js')
    .pipe(mocha())
    .on('error', spawnWatcher.handleError);
});

notification

Native notification is enabled by default. To disable it use the --no-notif option.

collate logging and tests

Set the environment variable _FORCE_LOGS

iOS app building

This package can create gulp tasks for building and cleaning iOS apps. By providing an iosApps property in the options sent to boilerplate() with the following:

iosApps: {
  relativeLocations: {
    iphoneos: 'relative/path/to/device/app.app',
    iphonesimulator: 'relative/path/to/sim/app.app',
  },
  appName: 'AppName.app',
},

This will create a number of gulp tasks, centrally one named ios-apps:install, which will go through the process of cleaning the build, building, and putting the products into deterministic places.

The simulator app will be build in build/Release-iphonesimulator/<appName>, and the real device app will be in build/Release-iphoneos/<appName>.

To build for real devices, set the environment variable IOS_REAL_DEVICE or REAL_DEVICE. To specify an xcconfig file, set its location in the XCCONFIG_FILE environment variable.

hacking this package

Since this package is used to build and test all the Appium packages, it should not use any of those packages.

watch

npm run watch

test

npm test