Skip to content

Commit

Permalink
feat: support multiple --text arguments (#168)
Browse files Browse the repository at this point in the history
* feat: add support for multiple text arguments

* add description to the README
  • Loading branch information
bahmutov authored Aug 15, 2024
1 parent d495616 commit 88b009a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ You can search for any text (and not just `.only`) by passing the parameter `--t
stop-only --folder specs --text '.pause()'
```

### any multiple texts

You can search for multiple text strings by providing multiple `--text` arguments. For example, to find both `.only` and `.skip` strings

```text
stop-only --folder specs --text '.only' --text '.skip'
```

### Pre-commit or pre-push hook

If using [pre-git][pre-git] to configure Git hooks, run this tool as a command
Expand Down
16 changes: 13 additions & 3 deletions bin/stop-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const argv = require('minimist')(process.argv.slice(2), {
}
})

function escapeRegExp (string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}

if (debug.enabled) {
console.log('stop-only arguments')
console.log(argv)
Expand Down Expand Up @@ -50,12 +54,18 @@ const normalizeStrings = listOrString => {
return normalized
}

const textToFind = argv.text || '(describe|context|it)\\.only'

let grepArguments = ['--line-number', '--recursive']

if (argv.text) {
grepArguments.push(textToFind)
if (Array.isArray(argv.text)) {
debug('multiple text search')
grepArguments.push('--extended-regexp')
const escaped = argv.text.map(escapeRegExp)
grepArguments.push(`(${escaped.join('|')})`)
} else {
debug('simple text search')
grepArguments.push(argv.text)
}
} else {
// simply find ".only" after suite / test
grepArguments.push('--extended-regexp')
Expand Down
5 changes: 2 additions & 3 deletions test/f7/spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
it('should only', () => {
cy.wrap()
.pause()
it('has the pause', () => {
cy.pause()
})
1 change: 1 addition & 0 deletions test/f7/spec2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it.skip('is skipped', () => {})
13 changes: 13 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,18 @@ describe('stop-only', () => {
la(result.includes(' Found ".pause" in'), 'finds the pause', result)
})
})

it('supports multiple --text arguments', () => {
return execaWrap(
'node',
[bin, '--warn', '--folder', f7, '--text', '.pause', '--text', '.skip'],
wrapOptions
).then(result => {
la(result.includes('code: 0'), 'it is only a warning', result)
la(result.includes(' Found "[ \'.pause\', \'.skip\' ]" in'), 'finds the pause and skip', result)
la(result.includes('spec2.js:1:it.skip'), 'finds the skip', result)
la(result.includes('spec.js:2: cy.pause('), 'finds the pause', result)
})
})
})
})

0 comments on commit 88b009a

Please sign in to comment.