|
1 | 1 | import { beforeEach, describe, it } from 'mocha'
|
2 | 2 | import { expect } from 'chai'
|
| 3 | +import path from 'path' |
3 | 4 | import PickleFilter from './pickle_filter'
|
4 | 5 | import { parse } from '../test/gherkin_helpers'
|
5 | 6 |
|
@@ -37,67 +38,87 @@ describe('PickleFilter', () => {
|
37 | 38 | })
|
38 | 39 |
|
39 | 40 | describe('line filters', () => {
|
40 |
| - beforeEach(function () { |
41 |
| - pickleFilter = new PickleFilter({ |
42 |
| - cwd, |
| 41 | + const variants = [ |
| 42 | + { |
| 43 | + name: 'with relative paths', |
43 | 44 | featurePaths: ['features/a.feature', 'features/b.feature:2:4'],
|
44 |
| - names: [], |
45 |
| - tagExpression: '', |
46 |
| - }) |
47 |
| - }) |
48 |
| - |
49 |
| - describe('pickle in feature without line specified', () => { |
50 |
| - it('returns true', async function () { |
51 |
| - // Arrange |
52 |
| - const { |
53 |
| - pickles: [pickle], |
54 |
| - gherkinDocument, |
55 |
| - } = await parse({ |
56 |
| - data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'), |
57 |
| - uri: 'features/a.feature', |
| 45 | + }, |
| 46 | + { |
| 47 | + name: 'with absolute paths', |
| 48 | + featurePaths: [ |
| 49 | + path.join(cwd, 'features/a.feature'), |
| 50 | + path.join(cwd, 'features/b.feature:2:4'), |
| 51 | + ], |
| 52 | + }, |
| 53 | + ] |
| 54 | + |
| 55 | + variants.forEach(({ name, featurePaths }) => { |
| 56 | + describe(name, () => { |
| 57 | + beforeEach(function () { |
| 58 | + pickleFilter = new PickleFilter({ |
| 59 | + cwd, |
| 60 | + featurePaths, |
| 61 | + names: [], |
| 62 | + tagExpression: '', |
| 63 | + }) |
58 | 64 | })
|
59 | 65 |
|
60 |
| - // Act |
61 |
| - const result = pickleFilter.matches({ pickle, gherkinDocument }) |
62 |
| - |
63 |
| - // Assert |
64 |
| - expect(result).to.eql(true) |
65 |
| - }) |
66 |
| - }) |
67 |
| - |
68 |
| - describe('pickle in feature with line specified', () => { |
69 |
| - it('returns true if pickle line matches', async function () { |
70 |
| - // Arrange |
71 |
| - const { |
72 |
| - pickles: [pickle], |
73 |
| - gherkinDocument, |
74 |
| - } = await parse({ |
75 |
| - data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'), |
76 |
| - uri: 'features/b.feature', |
| 66 | + describe('pickle in feature without line specified', () => { |
| 67 | + it('returns true', async function () { |
| 68 | + // Arrange |
| 69 | + const { |
| 70 | + pickles: [pickle], |
| 71 | + gherkinDocument, |
| 72 | + } = await parse({ |
| 73 | + data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'), |
| 74 | + uri: 'features/a.feature', |
| 75 | + }) |
| 76 | + |
| 77 | + // Act |
| 78 | + const result = pickleFilter.matches({ pickle, gherkinDocument }) |
| 79 | + |
| 80 | + // Assert |
| 81 | + expect(result).to.eql(true) |
| 82 | + }) |
77 | 83 | })
|
78 | 84 |
|
79 |
| - // Act |
80 |
| - const result = pickleFilter.matches({ pickle, gherkinDocument }) |
81 |
| - |
82 |
| - // Assert |
83 |
| - expect(result).to.eql(true) |
84 |
| - }) |
85 |
| - |
86 |
| - it('returns false if pickle line does not match', async function () { |
87 |
| - // Arrange |
88 |
| - const { |
89 |
| - pickles: [pickle], |
90 |
| - gherkinDocument, |
91 |
| - } = await parse({ |
92 |
| - data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join('\n'), |
93 |
| - uri: 'features/b.feature', |
| 85 | + describe('pickle in feature with line specified', () => { |
| 86 | + it('returns true if pickle line matches', async function () { |
| 87 | + // Arrange |
| 88 | + const { |
| 89 | + pickles: [pickle], |
| 90 | + gherkinDocument, |
| 91 | + } = await parse({ |
| 92 | + data: ['Feature: a', 'Scenario: b', 'Given a step'].join('\n'), |
| 93 | + uri: 'features/b.feature', |
| 94 | + }) |
| 95 | + |
| 96 | + // Act |
| 97 | + const result = pickleFilter.matches({ pickle, gherkinDocument }) |
| 98 | + |
| 99 | + // Assert |
| 100 | + expect(result).to.eql(true) |
| 101 | + }) |
| 102 | + |
| 103 | + it('returns false if pickle line does not match', async function () { |
| 104 | + // Arrange |
| 105 | + const { |
| 106 | + pickles: [pickle], |
| 107 | + gherkinDocument, |
| 108 | + } = await parse({ |
| 109 | + data: ['Feature: a', '', 'Scenario: b', 'Given a step'].join( |
| 110 | + '\n' |
| 111 | + ), |
| 112 | + uri: 'features/b.feature', |
| 113 | + }) |
| 114 | + |
| 115 | + // Act |
| 116 | + const result = pickleFilter.matches({ pickle, gherkinDocument }) |
| 117 | + |
| 118 | + // Assert |
| 119 | + expect(result).to.eql(false) |
| 120 | + }) |
94 | 121 | })
|
95 |
| - |
96 |
| - // Act |
97 |
| - const result = pickleFilter.matches({ pickle, gherkinDocument }) |
98 |
| - |
99 |
| - // Assert |
100 |
| - expect(result).to.eql(false) |
101 | 122 | })
|
102 | 123 | })
|
103 | 124 | })
|
|
0 commit comments