How to use cypress - 10 common examples

To help you get started, we’ve selected a few cypress examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bkucera / cypress-plugin-retries / test / helpers.js View on Github external
spec: '',
    expectedResults: {},
  })

  const expectedResults = _.defaults({}, parsedExpectedResults, opts.expectedResults, {
    totalFailed: 0,
  })

  console.log(chalk.cyanBright(`starting test run: ${opts.spec}`))

  const stdio = captureStdio(process.stdout)

  stdio.passThrough((v) => chalk.magenta(stripAnsi(v.toString())))
  // const stdio2 = captureStdio(process.stdout)

  return cypress.run({
    spec: opts.spec,
  }).then((res) => {
    expect(res).includes(expectedResults)
  })
  .finally(() => {
    stdio.restore()
    // console.log(chalk.magenta(stdio.toString()))
  })
  .then(() => {
    console.log(`${chalk.bold('run matched these results:')} ${JSON.stringify(expectedResults, null, 2)}`)
  })
}
github BrowserSync / browser-sync / test / utils.js View on Github external
bs.init(setup, function(err, bs) {
        return cypress.run({
            spec: specs,
        })
            .then((results) => {
                // stop your server when it's complete
                bs.cleanup();
                if (results.failures > 0) {
                    return process.exit(1);
                }
                process.exit(0);
            })
    });
}
github cypress-io / cypress-test-tiny / run.js View on Github external
console.log('\nRunning %d spec:', k, spec)
  k += 1

  const opts = {
    // headed: true,
    spec,
  }

  process.env.DEBUG = process.env.DEBUG || 'cypress:*'

  if (process.env.CI) {
    opts.record = false
    opts.key = process.env.CYPRESS_DASHBOARD_KEY
  }

  return cypress.run(opts).then(results => {
    if (results.failures) {
      numFailed += results.failures

      return results
    }
    return runSpec(spec)
  })
}
github victor0210 / slim / example / cypress.ci.js View on Github external
const server = require("./server");
const cypress = require("cypress");

// start your server
cypress
  .run({
    browser: "chrome"
  })
  .then(() => {
    // stop your server when it's complete
    console.log(`cypress test completed!`);
    process.exit(0);
  });
github nrwl / nx / packages / cypress / src / builders / cypress / cypress.impl.ts View on Github external
if (env) {
    options.env = env;
  }
  if (spec) {
    options.spec = spec;
  }

  options.exit = exit;
  options.headed = !headless;
  options.record = record;
  options.key = key;
  options.parallel = parallel;
  options.ciBuildId = ciBuildId;

  return fromPromise(
    !isWatching || headless ? Cypress.run(options) : Cypress.open(options)
  ).pipe(
    // tap(() => (isWatching && !headless ? process.exit() : null)), // Forcing `cypress.open` to give back the terminal
    map(result => ({
      /**
       * `cypress.open` is returning `0` and is not of the same type as `cypress.run`.
       * `cypress.open` is the graphical UI, so it will be obvious to know what wasn't
       * working. Forcing the build to success when `cypress.open` is used.
       */
      success: !result.totalFailed && !result.failures
    }))
  );
}
github intershop / intershop-pwa / e2e / cypress-ci-e2e.js View on Github external
const run = (num, spec, retryGroup) => {
  num += 1;
  let config = _.cloneDeep(DEFAULT_CONFIG);
  config = { ...config, env: { ...config.env, numRuns: num } };

  if (spec) config.spec = spec;
  if (retryGroup) config.group = retryGroup;

  console.log(config);

  return cypress
    .run(config)
    .then(results => {
      if (results.totalFailed) {
        totalFailuresIncludingRetries += results.totalFailed;

        // rerun again with only the failed tests
        const specs = _(results.runs)
          .filter('stats.failures')
          .map('spec.relative')
          .value();

        console.log(`Run #${num} failed.`);
        console.log(
          _(results.runs)
            .filter('stats.failures')
            .map('tests')
github tastejs / todomvc / tests / cya.js View on Github external
const testApp = app => {
  console.log(
    figlet.textSync(app, {
      font: 'Varsity'
    })
  )

  const colorFailures = n => (n ? chalk.red(n) : chalk.green(n))
  const addColors = R.over(R.lensProp('failures'), colorFailures)

  return cypress
    .run({
      browser: args.browser,
      record: true,
      key: '6f32e649-6348-4d6e-8ec0-4b57774965d1',
      env: {
        framework: app,
        times: args.times
      }
    })
    .then(R.omit(['screenshots', 'video', 'version']))
    .then(R.set(R.lensProp('app'), app))
    .then(addColors)
}
github victronenergy / venus-html5-app / test / run-cypress.js View on Github external
const cypress = require("cypress")
const httpServer = require("http-server")

const server = httpServer.createServer({
  root: "dist/"
})

server.listen(8000)

cypress
  .run()
  .then(res => {
    server.close()
    mqtt.server.close()
    process.exit(res.totalFailed)
  })
  .catch(err => {
    console.error(err)
    process.exit(1)
  })
github intershop / intershop-pwa / e2e / open-cypress.js View on Github external
} else {
  console.error(
    'Did not find a valid ICM_BASE_URL. Setup a environment.local.ts or supply it via environment variable.'
  );
  process.exit(1);
}

console.log('using', icmBaseUrl, 'as ICM_BASE_URL');

const args = process.argv.slice(0, 2);
args.push('open', '-e', 'ICM_BASE_URL=' + icmBaseUrl);
if (process.argv.length > 2) {
  args.push(...process.argv.slice(2));
}

cypress.init(args);
github gymnastjs / picturebook / src / utils / folderStructure.spec.js View on Github external
it('should group tests based on their extension', () => {
    const out = folderStructure(options)
    const { tests } = out.find(({ title }) => title === 'File4') || {}

    expect(tests['cypress.spec']).toEqual(expect.any(String))
    expect(tests.spec).toEqual(expect.any(String))
  })

cypress

Cypress is a next generation front end testing tool built for the modern web

MIT
Latest version published 1 day ago

Package Health Score

95 / 100
Full package analysis