|
| 1 | +const { filterSpecsFromCoverage } = require('../../utils') |
| 2 | + |
| 3 | +describe('minimatch', () => { |
| 4 | + it('string matches', () => { |
| 5 | + expect( |
| 6 | + Cypress.minimatch('/path/to/specA.js', '/path/to/specA.js'), |
| 7 | + 'matches full strings' |
| 8 | + ).to.be.true |
| 9 | + |
| 10 | + expect( |
| 11 | + Cypress.minimatch('/path/to/specA.js', 'specA.js'), |
| 12 | + 'does not match just the end' |
| 13 | + ).to.be.false |
| 14 | + |
| 15 | + expect( |
| 16 | + Cypress.minimatch('/path/to/specA.js', '**/specA.js'), |
| 17 | + 'matches using **' |
| 18 | + ).to.be.true |
| 19 | + }) |
| 20 | +}) |
| 21 | + |
| 22 | +describe('filtering specs', () => { |
| 23 | + it('filters list of specs by single string', () => { |
| 24 | + const config = cy.stub() |
| 25 | + config.withArgs('testFiles').returns(['specA.js']) |
| 26 | + config.withArgs('integrationFolder').returns('/path/to/integration/') |
| 27 | + |
| 28 | + const totalCoverage = { |
| 29 | + '/path/to/specA.js': {}, |
| 30 | + '/path/to/specB.js': {} |
| 31 | + } |
| 32 | + const result = filterSpecsFromCoverage(totalCoverage, config) |
| 33 | + expect(result).to.deep.equal({ |
| 34 | + '/path/to/specB.js': {} |
| 35 | + }) |
| 36 | + }) |
| 37 | + |
| 38 | + it('filters list of specs by pattern', () => { |
| 39 | + const config = cy.stub() |
| 40 | + config.withArgs('testFiles').returns(['**/*B.js']) |
| 41 | + config.withArgs('integrationFolder').returns('/path/to/integration/') |
| 42 | + |
| 43 | + const totalCoverage = { |
| 44 | + '/path/to/specA.js': {}, |
| 45 | + '/path/to/specB.js': {} |
| 46 | + } |
| 47 | + const result = filterSpecsFromCoverage(totalCoverage, config) |
| 48 | + expect(result).to.deep.equal({ |
| 49 | + '/path/to/specA.js': {} |
| 50 | + }) |
| 51 | + }) |
| 52 | + |
| 53 | + it('filters list of specs by pattern and single spec', () => { |
| 54 | + const config = cy.stub() |
| 55 | + config.withArgs('testFiles').returns(['**/*B.js', 'specA.js']) |
| 56 | + config.withArgs('integrationFolder').returns('/path/to/integration/') |
| 57 | + |
| 58 | + const totalCoverage = { |
| 59 | + '/path/to/specA.js': {}, |
| 60 | + '/path/to/specB.js': {} |
| 61 | + } |
| 62 | + const result = filterSpecsFromCoverage(totalCoverage, config) |
| 63 | + expect(result, 'all specs have been filtered out').to.deep.equal({}) |
| 64 | + }) |
| 65 | + |
| 66 | + it('filters list of specs in integration folder', () => { |
| 67 | + const config = cy.stub() |
| 68 | + config.withArgs('testFiles').returns('**/*.*') // default pattern |
| 69 | + config.withArgs('integrationFolder').returns('/path/to/integration/') |
| 70 | + |
| 71 | + const totalCoverage = { |
| 72 | + '/path/to/specA.js': {}, |
| 73 | + '/path/to/specB.js': {}, |
| 74 | + // these files should be removed |
| 75 | + '/path/to/integration/spec1.js': {}, |
| 76 | + '/path/to/integration/spec2.js': {} |
| 77 | + } |
| 78 | + const result = filterSpecsFromCoverage(totalCoverage, config) |
| 79 | + expect(result).to.deep.equal({ |
| 80 | + '/path/to/specA.js': {}, |
| 81 | + '/path/to/specB.js': {} |
| 82 | + }) |
| 83 | + }) |
| 84 | +}) |
0 commit comments