lirantal / lockfile-lint

Lint an npm or yarn lockfile to analyze and detect security issues
Apache License 2.0
781 stars 35 forks source link

Tests fail on Windows #69

Closed XhmikosR closed 4 years ago

XhmikosR commented 4 years ago
yarn run v1.22.0
$ lerna run test
lerna notice cli v3.14.1
lerna info versioning independent
lerna info Executing command in 2 packages: "yarn run test"
lerna info run Ran npm script 'test' in 'lockfile-lint-api' in 2.9s:
$ jest
----------------------------------|----------|----------|----------|----------|-------------------|
File                              |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------------------------|----------|----------|----------|----------|-------------------|
All files                         |    96.32 |    88.73 |    95.65 |    96.32 |                   |
 lockfile-lint-api                |      100 |      100 |      100 |      100 |                   |
  index.js                        |      100 |      100 |      100 |      100 |                   |
 lockfile-lint-api/src            |      100 |    95.24 |      100 |      100 |                   |
  ParseLockfile.js                |      100 |    95.24 |      100 |      100 |               132 |
 lockfile-lint-api/src/common     |    73.68 |       50 |     87.5 |    73.68 |                   |
  PackageError.js                 |        0 |        0 |        0 |        0 |     3,10,11,12,13 |
  ParsingError.js                 |      100 |    83.33 |      100 |      100 |                26 |
  constants.js                    |      100 |      100 |      100 |      100 |                   |
 lockfile-lint-api/src/validators |      100 |       95 |      100 |      100 |                   |
  ValidateHost.js                 |      100 |      100 |      100 |      100 |                   |
  ValidateHttps.js                |      100 |    88.89 |      100 |      100 |                 8 |
  ValidateScheme.js               |      100 |    92.31 |      100 |      100 |                 6 |
----------------------------------|----------|----------|----------|----------|-------------------|
lerna ERR! yarn run test exited 1 in 'lockfile-lint'
lerna ERR! yarn run test stdout:
$ jest
  console.error src/main.js:44
    detected invalid protocol for package: debug@^4.1.1
        expected: https:
        actual: http:

  console.error src/main.js:44
    detected invalid protocol for package: ms@^2.1.1
        expected: https:
        actual: http:

  console.error src/main.js:44
    detected invalid protocol for package: debug@^4.1.1
        expected: https:
        actual: http:

  console.error src/main.js:44
    detected invalid protocol for package: ms@^2.1.1
        expected: https:
        actual: http:

  console.error src/main.js:44
    detected invalid host(s) for package: debug@^4.1.1
        expected: registry.npmjs.org
        actual: registry.yarnpkg.com

  console.error src/main.js:44
    detected invalid host(s) for package: ms@^2.1.1
        expected: registry.npmjs.org
        actual: registry.yarnpkg.com

  console.error src/main.js:44
    detected invalid host(s) for package: metalsmith-permalinks@github:XhmikosR/metalsmith-permalinks#432843d5823a292b2e47397ba46fd761d03eb9d3-23e3afb87f94f6fbb4a2a4dee0e9ad5ae3345557
        expected: registry.npmjs.org
        actual:

  console.error src/main.js:44
    detected invalid host(s) for package: substitute@https://github.com/segment-boneyard/substitute/archive/0.1.0.tar.gz-cac7fab347605af7808679c31e920d7da07e6b0c
        expected: registry.npmjs.org
        actual: github.com

  console.error src/main.js:44
    detected invalid scheme(s) for package: debug@4.1.1-031b0fadad70d901aa76ca1028682c7fc8ed370c
        expected: https
        actual: https:

  console.error src/main.js:44
    detected invalid scheme(s) for package: ms@git+https://github.com/zeit/ms.git#adf1eb282d29fe3c405d205a3854177b86a97c1f-0f7c6a877d7eeaa579752be37c7fd80b9bd02a4a
        expected: https
        actual: git+https:

  console.error src/main.js:44
    detected invalid scheme(s) for package: debug@^4.1.1
        expected: https
        actual: https:

  console.error src/main.js:44
    detected invalid scheme(s) for package: ms@^2.1.1
        expected: https
        actual: https:

  console.error src/main.js:44
    detected invalid scheme(s) for package: ms@git+https://github.com/zeit/ms#master
        expected: https
        actual: git+https:

----------------|----------|----------|----------|----------|-------------------|
File            |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------|----------|----------|----------|----------|-------------------|
All files       |    91.49 |    85.71 |      100 |    91.49 |                   |
 src            |    84.62 |    85.71 |      100 |    84.62 |                   |
  cli.js        |        0 |      100 |      100 |        0 |            3,5,52 |
  main.js       |    95.65 |    85.71 |      100 |    95.65 |                28 |
 src/validators |      100 |      100 |      100 |      100 |                   |
  index.js      |      100 |      100 |      100 |      100 |                   |
----------------|----------|----------|----------|----------|-------------------|
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

lerna ERR! yarn run test stderr:
FAIL __tests__/cli.test.js
  CLI tests
    × Running without parameters should display help (13ms)
    × Running without parameters should display a requirement for the p option (4ms)
    × Linting a file that has wrong host should display an error message and use exit code 1 (4ms)
    × Linting a file that has wrong host should return exit code 1 (4ms)

  ● CLI tests › Running without parameters should display help

    spawn UNKNOWN

       7 | describe('CLI tests', () => {
       8 |   test('Running without parameters should display help', done => {
    >  9 |     const process = childProcess.spawn(cliExecPath, [])
         |                                  ^
      10 |
      11 |     let output = ''
      12 |     process.stderr.on('data', chunk => {

      at Object.spawn (__tests__/cli.test.js:9:34)

  ● CLI tests › Running without parameters should display a requirement for the p option

    spawn UNKNOWN

      23 |
      24 |   test('Running without parameters should display a requirement for the p option', done => {
    > 25 |     const process = childProcess.spawn(cliExecPath, [])
         |                                  ^
      26 |
      27 |     let output = ''
      28 |     process.stderr.on('data', chunk => {

      at Object.spawn (__tests__/cli.test.js:25:34)

  ● CLI tests › Linting a file that has wrong host should display an error message and use exit code 1

    spawn UNKNOWN

      37 |
      38 |   test('Linting a file that has wrong host should display an error message and use exit code 1', done => {
    > 39 |     const process = childProcess.spawn(cliExecPath, [
         |                                  ^
      40 |       '--type',
      41 |       'yarn',
      42 |       '--path',

      at Object.spawn (__tests__/cli.test.js:39:34)

  ● CLI tests › Linting a file that has wrong host should return exit code 1

    spawn UNKNOWN

      67 |
      68 |   test('Linting a file that has wrong host should return exit code 1', done => {
    > 69 |     const process = childProcess.spawn(cliExecPath, [
         |                                  ^
      70 |       '--type',
      71 |       'yarn',
      72 |       '--path',

      at Object.spawn (__tests__/cli.test.js:69:34)

PASS __tests__/main.test.js
  Main CLI logic
    Invoking validators should handle errors and defaults
      √ when no validator function is provided expect to fail (16ms)
      √ should handle exceptions when validators arent provided for runValidators method (5ms)
    validateHttp
      √ a failing validator should return proper validation failed object (2ms)
      √ a successful validator should return proper validation object (1ms)
    validateHosts
      √ a failing validator should return proper validation failed object (3ms)
      √ a failing validator should throw an error if an empty host is not allowed (4ms)
      √ a successful validator should return proper validation object (4ms)
    validateSchemes
      √ should fail validating allowed schemes for a package-lock.json file (2ms)
      √ should succeed validating allowed schemes for a package-lock.json file (2ms)
      √ should fail validating allowed schemes for a yarn.lock file (3ms)
      √ should succeed validating allowed schemes for a yarn.lock file (1ms)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       4 failed, 11 passed, 15 total
Snapshots:   0 total
Time:        1.771s
Ran all test suites.
error Command failed with exit code 1.

lerna ERR! yarn run test exited 1 in 'lockfile-lint'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
XhmikosR commented 4 years ago

OK, after playing around with the source code I think I know why this happens.

The cli spawn should be node script and not script. Shebangs don't work on Windows