victorperin / qr-scanner-cli

A CLI tool to read QR Code from images
https://victorperin.github.io/qr-scanner-cli/
MIT License
73 stars 24 forks source link

Tests: Fix all surviving mutations #185

Closed victorperin closed 3 years ago

victorperin commented 3 years ago

I recently implemented mutation tests with stryker mutator and discovered some surviving mutations, meaning our tests are not covering those changed parts.

How to check the mutations

Just run npm run test:mutation

Survived mutations output

❯ npm run test:mutation

> qr-scanner-cli@0.2.2-development test:mutation
> node tests/mutation/stryker.js

23:36:56 (17950) INFO ConfigReader Using stryker.conf.js
23:36:57 (17950) INFO InputFileResolver Found 13 of 1046 file(s) to be mutated.
23:36:57 (17950) INFO Instrumenter Instrumented 13 source file(s) with 95 mutant(s)
23:36:58 (17950) INFO ConcurrencyTokenProvider Creating 8 checker process(es) and 7 test runner process(es).
23:37:02 (17950) INFO DryRunExecutor Starting initial test run (jest test runner with "perTest" coverage analysis). This may take a while.
23:37:25 (17950) INFO DryRunExecutor Initial test run succeeded. Ran 33 tests in 23 seconds (net 8679 ms, overhead 14541 ms).
Mutation testing  [] 100% (elapsed: <1m, remaining: n/a) 88/88 tested (22 survived, 0 timed out)

All tests
  src
    cli/execution.test.ts
      ✓ should execute scanFrom file [line 24] (killed 3)
      ✓ should warn if no argument passed [line 36] (killed 3)
    handlers
      error.test.ts
        ✓ error handler scanFromFile should throw generic error if unknown error is received [line 5] (killed 2)
        ✓ error handler scanFromFile should throw error if error "no such file or directory" is received [line 13] (killed 2)
        ✓ error handler scanFromBitmap should throw generic error if unknown error is received [line 23] (killed 1)
        ✓ error handler scanFromBitmap should throw warning if "0 patterns found" is received [line 30] (killed 2)
      flags.test.ts
        ~ doOpen should open with text if flag open exists [line 12] (covered 4)
        ✓ doOpen should not open with text if there is no flag open [line 24] (killed 1)
        ~ doOpen should return text if there is no flag open [line 36] (covered 3)
    infrastructure
      boxen.test.ts
        ✓ Should call boxen with basic settings and return boxen content [line 10] (killed 3)
        ~ Should add margin if config is passed [line 30] (covered 1)
      jimp.test.ts
        ✘ jimp/getBitmap should execute Jimp.read with input [line 12] (covered 0)
        ✘ jimp/getBitmap should return bitmap from Jimp.read response [line 21] (covered 0)
      qrcode-reader.test.ts
        ~ should resolve if qr is qrcode-reader runs callback without errors [line 12] (covered 6)
        ~ should reject if qr is qrcode-reader runs callback with error [line 27] (covered 5)
    pipelines
      scanFromBitmap.test.ts
        ~ scanFromBitmap should readQR [line 26] (covered 6)
        ~ scanFromBitmap flags tests should check for flag clipboard [line 42] (covered 6)
        ~ scanFromBitmap flags tests should check for flag open [line 42] (covered 6)
        ~ scanFromBitmap errors should should not execute errorHandle if no error occours [line 55] (covered 6)
        ~ scanFromBitmap errors should handle errors with errorHandlers [line 61] (covered 6)
      scanFromFile.test.ts
        ✓ should pass on happy path [line 41] (killed 3)
        ✓ should copy to clipboard if flag is present [line 54] (killed 2)
        ~ should output without box if clear flag is present [line 67] (covered 14)
        ~ should execute flags (clear, clipboard) [line 81] (covered 15)
        ✓ should execute open with --open [line 95] (killed 2)
        ~ programatic mode should return value [line 108] (covered 13)
        ~ programatic mode should use flags [line 114] (covered 15)
  tests/integration
    cli.test.ts
      ✘ Should read successfully the URL from QR-Code [line 39] (covered 0)
      ✘ Should output text to clipboard if -p is specified [line 48] (covered 0)
      ✘ Should handle missing parameter <file> [line 58] (covered 0)
      ✘ Should handle file not found [line 67] (covered 0)
      ✘ Should handle invalid file (no QR-Code) [line 77] (covered 0)
    programatic.test.ts
      ✓ Programatic mode - integration tests scanFromFile Should read successfully the URL from QR-Code [line 5] (killed 2)

#16. [NoCoverage] BlockStatement
src/cli/execution.ts:29:76
-     return scanFromFileOnCli(filePath, flagsTreated).catch((error: Error) => {
-       console.error(error.message)
-       return yargsInstance.exit(1, error)
-     })
+     return scanFromFileOnCli(filePath, flagsTreated).catch((error: Error) => {})

#5. [Survived] ObjectLiteral
src/cli/execution.ts:12:83
-         ['qrscanner ./qrCode.jpg', greenBox('This message is written in a QR Code', { margin: 1 })],
+         ['qrscanner ./qrCode.jpg', greenBox('This message is written in a QR Code', {})],
Tests ran:
    should execute scanFrom file
    should warn if no argument passed

#8. [Survived] StringLiteral
src/cli/execution.ts:13:42
-         ['qrscanner ./qrCode.jpg --clear', '\nThis message is written in a QR Code'],
+         ['qrscanner ./qrCode.jpg --clear', ""],
Tests ran:
    should execute scanFrom file
    should warn if no argument passed

#14. [Survived] StringLiteral
src/cli/execution.ts:21:18
-       console.warn(`[WARNING] Missing argument file: qrscanner <file>!`)
+       console.warn(``)
Tests ran:
    should warn if no argument passed

#3. [Survived] StringLiteral
src/cli/execution.ts:12:8
-         ['qrscanner ./qrCode.jpg', greenBox('This message is written in a QR Code', { margin: 1 })],
+         ["", greenBox('This message is written in a QR Code', { margin: 1 })],
Tests ran:
    should execute scanFrom file
    should warn if no argument passed

#7. [Survived] StringLiteral
src/cli/execution.ts:13:8
-         ['qrscanner ./qrCode.jpg --clear', '\nThis message is written in a QR Code'],
+         ["", '\nThis message is written in a QR Code'],
Tests ran:
    should execute scanFrom file
    should warn if no argument passed

#1. [Survived] ArrayDeclaration
src/cli/execution.ts:11:14
-       .example([
-         ['qrscanner ./qrCode.jpg', greenBox('This message is written in a QR Code', { margin: 1 })],
-         ['qrscanner ./qrCode.jpg --clear', '\nThis message is written in a QR Code'],
-       ])
+       .example([])
Tests ran:
    should execute scanFrom file
    should warn if no argument passed

#4. [Survived] StringLiteral
src/cli/execution.ts:12:43
-         ['qrscanner ./qrCode.jpg', greenBox('This message is written in a QR Code', { margin: 1 })],
+         ['qrscanner ./qrCode.jpg', greenBox("", { margin: 1 })],
Tests ran:
    should execute scanFrom file
    should warn if no argument passed

#20. [Survived] BooleanLiteral
src/cli/flags.ts:10:14
-       default: false,
+       default: true,
Ran all tests for this mutant.

#24. [Survived] BooleanLiteral
src/cli/flags.ts:15:14
-       boolean: true,
+       boolean: false,
Ran all tests for this mutant.

#21. [Survived] StringLiteral
src/cli/flags.ts:11:12
-       alias: 'c',
+       alias: "",
Ran all tests for this mutant.

#19. [Survived] BooleanLiteral
src/cli/flags.ts:9:14
-       boolean: true,
+       boolean: false,
Ran all tests for this mutant.

#27. [Survived] StringLiteral
src/cli/flags.ts:18:18
-       description: 'Copy the qr code value to your clipboard',
+       description: "",
Ran all tests for this mutant.

#30. [Survived] BooleanLiteral
src/cli/flags.ts:22:14
-       default: false,
+       default: true,
Ran all tests for this mutant.

#25. [Survived] BooleanLiteral
src/cli/flags.ts:16:14
-       default: false,
+       default: true,
Ran all tests for this mutant.

#22. [Survived] StringLiteral
src/cli/flags.ts:12:18
-       description: 'Clear output, just print the QR Code scan result',
+       description: "",
Ran all tests for this mutant.

#26. [Survived] StringLiteral
src/cli/flags.ts:17:12
-       alias: 'p',
+       alias: "",
Ran all tests for this mutant.

#31. [Survived] StringLiteral
src/cli/flags.ts:23:12
-       alias: 'o',
+       alias: "",
Ran all tests for this mutant.

#29. [Survived] BooleanLiteral
src/cli/flags.ts:21:14
-       boolean: true,
+       boolean: false,
Ran all tests for this mutant.

#32. [Survived] StringLiteral
src/cli/flags.ts:24:18
-       description: 'Open the qr code value in any browser or program if support it',
+       description: "",
Ran all tests for this mutant.

#33. [NoCoverage] ArrowFunction
src/cli/helpText.ts:6:8
-     .map(([flagKey, flag]) => `    --${flagKey}, -${flag.alias}  ${flag.description}`)
+     .map(() => undefined)

#34. [NoCoverage] StringLiteral
src/cli/helpText.ts:6:29
-     .map(([flagKey, flag]) => `    --${flagKey}, -${flag.alias}  ${flag.description}`)
+     .map(([flagKey, flag]) => ``)

#35. [NoCoverage] StringLiteral
src/cli/helpText.ts:7:9
-     .join('\n')
+     .join("")

#37. [NoCoverage] StringLiteral
src/cli/helpText.ts:20:16
-       ${greenBox('This message is written in a QR Code', { margin: 1 })}
+       ${greenBox("", { margin: 1 })}

#38. [NoCoverage] ObjectLiteral
src/cli/helpText.ts:20:56
-       ${greenBox('This message is written in a QR Code', { margin: 1 })}
+       ${greenBox('This message is written in a QR Code', {})}

#36. [NoCoverage] StringLiteral
src/cli/helpText.ts:9:29
-   const helpText = stripIndent`
-     Usage
-       $ qrscanner <input file>
-     Options
-   ${flagDescriptions}
-       --version Show installed version
-       --help Show this help
-     Examples
-       $ qrscanner ./qrCode.jpg
-       ${greenBox('This message is written in a QR Code', { margin: 1 })}
-       $ qrscanner ./qrCode.jpg --clear
-       This message is written in a QR Code
-   `
+   const helpText = stripIndent``

#53. [Survived] StringLiteral
src/handlers/error.ts:11:51
-     if (typeof error === 'string' && error.includes('0 patterns found'))
+     if (typeof error === 'string' && error.includes(""))
Tests ran:
    error handler scanFromBitmap should throw warning if "0 patterns found" is received

#68. [Survived] ObjectLiteral
src/handlers/flags.ts:31:16
-   export default {
-     outputText,
-     doFlagClipboard,
-     doOpen,
-   }
+   export default {}
Ran all tests for this mutant.

#77. [Survived] ObjectLiteral
src/infrastructure/jimp.ts:9:16
-   export default {
-     getBitmap,
-   }
+   export default {}
Ran all tests for this mutant.

Ran 4.22 tests per mutant on average.
--------------------|---------|----------|-----------|------------|----------|---------|
File                | % score | # killed | # timeout | # survived | # no cov | # error |
--------------------|---------|----------|-----------|------------|----------|---------|
All files           |   47.27 |       26 |         0 |         22 |        7 |      40 |
 cli                |   18.75 |        6 |         0 |         19 |        7 |       7 |
  execution.ts      |   42.86 |        6 |         0 |          7 |        1 |       3 |
  flags.ts          |    0.00 |        0 |         0 |         12 |        0 |       4 |
  helpText.ts       |    0.00 |        0 |         0 |          0 |        6 |       0 |
 handlers           |   87.50 |       14 |         0 |          2 |        0 |      14 |
  error.ts          |   87.50 |        7 |         0 |          1 |        0 |       9 |
  flags.ts          |   87.50 |        7 |         0 |          1 |        0 |       5 |
 infrastructure     |   85.71 |        6 |         0 |          1 |        0 |       9 |
  boxen.ts          |  100.00 |        4 |         0 |          0 |        0 |       2 |
  jimp.ts           |    0.00 |        0 |         0 |          1 |        0 |       2 |
  qrcode-reader.ts  |  100.00 |        2 |         0 |          0 |        0 |       5 |
 pipelines          |     NaN |        0 |         0 |          0 |        0 |      10 |
  scanFromBitmap.ts |     NaN |        0 |         0 |          0 |        0 |       7 |
  scanFromFile.ts   |     NaN |        0 |         0 |          0 |        0 |       3 |
--------------------|---------|----------|-----------|------------|----------|---------|
github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 2.1.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket: