|
| 1 | +const spok = require('spok').default |
| 2 | +const cypress = require('cypress') |
| 3 | +const assert = require('assert') |
| 4 | +const debug = require('debug')('test') |
| 5 | + |
| 6 | +const assertResults = results => { |
| 7 | + // let's confirm the number of tests |
| 8 | + // and maybe some additional information |
| 9 | + debug('results %o', results) |
| 10 | + |
| 11 | + spok(assert, results, { |
| 12 | + totalSuites: 0, |
| 13 | + totalTests: 1, |
| 14 | + runs: spok.array |
| 15 | + }) |
| 16 | + assert(results.runs.length === 1, 'single run') |
| 17 | +} |
| 18 | + |
| 19 | +const shouldHaveTest = (title, state, results) => { |
| 20 | + assert(results.runs.length === 1, 'there should be just a single run') |
| 21 | + const test = results.runs[0].tests.find(t => t.title[0] === title) |
| 22 | + debug('found test %o', test) |
| 23 | + assert(test, 'could not find test') |
| 24 | + |
| 25 | + spok(assert, test, { |
| 26 | + title, |
| 27 | + state, |
| 28 | + // there should not be any errors |
| 29 | + error: null |
| 30 | + }) |
| 31 | +} |
| 32 | + |
| 33 | +/* eslint-env mocha */ |
| 34 | +describe('skipping test in headed mode', () => { |
| 35 | + it('runs the test in headless mode', () => { |
| 36 | + return cypress |
| 37 | + .run({ |
| 38 | + spec: 'cypress/integration/headed-spec.js', |
| 39 | + headed: false, |
| 40 | + video: false |
| 41 | + }) |
| 42 | + .then(results => { |
| 43 | + assertResults(results) |
| 44 | + shouldHaveTest( |
| 45 | + 'skips the current test in headed mode', |
| 46 | + 'passed', |
| 47 | + results |
| 48 | + ) |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + it('skips test in headed mode', () => { |
| 53 | + return cypress |
| 54 | + .run({ |
| 55 | + spec: 'cypress/integration/headed-spec.js', |
| 56 | + headed: true, |
| 57 | + video: false |
| 58 | + }) |
| 59 | + .then(results => { |
| 60 | + assertResults(results) |
| 61 | + // the plugin automatically replaces any tests in skipped block |
| 62 | + // with a single dummy test with this name |
| 63 | + shouldHaveTest('Skipping test(s) in headed mode', 'pending', results) |
| 64 | + }) |
| 65 | + }) |
| 66 | +}) |
| 67 | + |
| 68 | +describe('only running test in headed mode', () => { |
| 69 | + it('runs the test in headed mode', () => { |
| 70 | + return cypress |
| 71 | + .run({ |
| 72 | + spec: 'cypress/integration/headed-only-spec.js', |
| 73 | + headed: true, |
| 74 | + video: false |
| 75 | + }) |
| 76 | + .then(results => { |
| 77 | + assertResults(results) |
| 78 | + shouldHaveTest( |
| 79 | + 'runs the current test only in headed mode', |
| 80 | + 'passed', |
| 81 | + results |
| 82 | + ) |
| 83 | + }) |
| 84 | + }) |
| 85 | + |
| 86 | + it('skips test in headless mode', () => { |
| 87 | + return cypress |
| 88 | + .run({ |
| 89 | + spec: 'cypress/integration/headed-only-spec.js', |
| 90 | + headed: false, |
| 91 | + video: false |
| 92 | + }) |
| 93 | + .then(results => { |
| 94 | + assertResults(results) |
| 95 | + shouldHaveTest('Skipping test(s), not on headed', 'pending', results) |
| 96 | + }) |
| 97 | + }) |
| 98 | +}) |
0 commit comments