From a30ab222036b187130e69437d2e72a1f6969274f Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Mon, 23 Jan 2023 15:18:55 -0500 Subject: [PATCH] feat: add --text parameter (#140) 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 --- .github/workflows/ci.yml | 3 ++- README.md | 8 ++++++++ bin/stop-only.js | 39 ++++++++++++++++++++++++++++----------- package.json | 3 ++- test/f7/spec.js | 4 ++++ test/spec.js | 16 +++++++++++++++- 6 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 test/f7/spec.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c078b4..fc8504f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/README.md b/README.md index 32cc63d..28bd1e3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/stop-only.js b/bin/stop-only.js index af6e45e..26bea0a 100755 --- a/bin/stop-only.js +++ b/bin/stop-only.js @@ -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', @@ -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) @@ -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) } diff --git a/package.json b/package.json index 98e6cc8..c6c6fd2 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/f7/spec.js b/test/f7/spec.js new file mode 100644 index 0000000..88a1b07 --- /dev/null +++ b/test/f7/spec.js @@ -0,0 +1,4 @@ +it('should only', () => { + cy.wrap() + .pause() +}) diff --git a/test/spec.js b/test/spec.js index d55ffda..eacbce9 100644 --- a/test/spec.js +++ b/test/spec.js @@ -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'] } @@ -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) + }) + }) + }) })