Skip to content

Commit

Permalink
feat: add --text parameter (#140)
Browse files Browse the repository at this point in the history
You can search for any text (and not just `.only`) by passing the parameter `--text`. For example, to find stray ".pause()" commands left in your specs, you can do

```text
stop-only --folder specs --text '.pause()'
```

* feat: add --text support

* only run the release job on master branch
  • Loading branch information
bahmutov authored Jan 23, 2023
1 parent de8cb1a commit a30ab22
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
run: npm test

- name: Semantic Release 🚀
uses: cycjimmy/semantic-release-action@v2
if: github.ref == 'refs/heads/master'
uses: cycjimmy/semantic-release-action@v3
with:
branch: master
env:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ Or just warn
stop-only --warn --file tests/spec.js
```

### any text

You can search for any text (and not just `.only`) by passing the parameter `--text`. For example, to find stray ".pause()" commands left in your specs, you can do

```text
stop-only --folder specs --text '.pause()'
```

### Pre-commit or pre-push hook

If using [pre-git][pre-git] to configure Git hooks, run this tool as a command
Expand Down
39 changes: 28 additions & 11 deletions bin/stop-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const execa = require('execa')
const debug = require('debug')('stop-only')
const argv = require('minimist')(process.argv.slice(2), {
string: ['folder', 'skip', 'exclude', 'file'],
string: ['folder', 'skip', 'exclude', 'file', 'text'],
boolean: 'warn',
alias: {
warn: 'w',
Expand Down Expand Up @@ -50,12 +50,17 @@ const normalizeStrings = listOrString => {
return normalized
}

let grepArguments = [
'--line-number',
'--recursive',
'--extended-regexp',
'(describe|context|it)\\.only'
]
const textToFind = argv.text || '(describe|context|it)\\.only'

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

if (argv.text) {
grepArguments.push(textToFind)
} else {
// simply find ".only" after suite / test
grepArguments.push('--extended-regexp')
grepArguments.push('(describe|context|it)\\.only')
}

if (hasFileArgument) {
grepArguments.push(argv.file)
Expand Down Expand Up @@ -101,17 +106,29 @@ const grepFinished = result => {
}

if (result.code === 1) {
debug('could not find .only anywhere')
if (argv.text) {
debug('could not find "%s" anywhere', argv.text)
} else {
debug('could not find .only anywhere')
}
process.exit(0)
}

// found ".only" somewhere
// found ".only" or specific text somewhere
if (argv.warn) {
console.log('⚠️ Found .only in')
if (argv.text) {
console.log('⚠️ Found "%s" in', argv.text)
} else {
console.log('⚠️ Found .only in')
}
console.log(result.stdout)
process.exit(0)
} else {
console.log('Found .only here 👎')
if (argv.text) {
console.log('Found "%s" here 👎', argv.text)
} else {
console.log('Found .only here 👎')
}
console.log(result.stdout)
process.exit(1)
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"unit": "mocha test/spec.js",
"semantic-release": "semantic-release",
"stop-only": "node bin/stop-only.js -f src --skip excluded",
"warn-only": "node bin/stop-only.js --warn -f src"
"warn-only": "node bin/stop-only.js --warn -f src",
"demo-text": "node bin/stop-only.js --warn --text 'NPM module' -f src"
},
"release": {
"analyzeCommits": {
Expand Down
4 changes: 4 additions & 0 deletions test/f7/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it('should only', () => {
cy.wrap()
.pause()
})
16 changes: 15 additions & 1 deletion test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('stop-only', () => {
const f3 = fromThisFolder('f3')
const f4 = fromThisFolder('f4')
const f5 = fromThisFolder('f5')
const f6 = fromThisFolder('f6');
const f6 = fromThisFolder('f6')
const f7 = fromThisFolder('f7')

// we are only testing exit code and standard output
const wrapOptions = { filter: ['code', 'stdout'] }
Expand Down Expand Up @@ -218,4 +219,17 @@ describe('stop-only', () => {
)
})
})

context('warns if it finds arbitrary text', () => {
it('finds the .pause left in folder f7', () => {
return execaWrap(
'node',
[bin, '--warn', '--folder', f7, '--text', '.pause'],
wrapOptions
).then(result => {
la(result.includes('code: 0'), 'it is only a warning', result)
la(result.includes(' Found ".pause" in'), 'finds the pause', result)
})
})
})
})

0 comments on commit a30ab22

Please sign in to comment.