From 7e1d41d1c595bc2e4b53292885b6c871d1304a97 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Mon, 28 Aug 2023 21:18:40 +0300 Subject: [PATCH] test: add test cases for future regressions --- package-lock.json | 5 +++-- packages/lockfile-lint/__tests__/cli.test.js | 16 ++++++++++++++++ packages/lockfile-lint/package.json | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 82013ec..5728165 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19747,7 +19747,7 @@ } }, "packages/lockfile-lint": { - "version": "4.11.0", + "version": "4.12.0", "license": "Apache-2.0", "dependencies": { "cosmiconfig": "^8.2.0", @@ -19777,7 +19777,8 @@ "eslint-plugin-standard": "^4.1.0", "jest": "29.6.2", "open-cli": "^7.2.0", - "prettier-standard": "16.4.1" + "prettier-standard": "16.4.1", + "semver": "^7.5.4" }, "engines": { "node": ">=16.0.0" diff --git a/packages/lockfile-lint/__tests__/cli.test.js b/packages/lockfile-lint/__tests__/cli.test.js index 85c580f..7871628 100644 --- a/packages/lockfile-lint/__tests__/cli.test.js +++ b/packages/lockfile-lint/__tests__/cli.test.js @@ -1,5 +1,6 @@ 'use strict' +const semver = require('semver') const path = require('path') // eslint-disable-next-line security/detect-child-process const childProcess = require('child_process') @@ -42,6 +43,21 @@ describe('CLI tests', () => { }) }) + test('Checking for version number should be semver compatible and exit with no errors', done => { + const process = childProcess.spawn('node', [cliExecPath, '--version']) + + let output = '' + process.stdout.on('data', chunk => { + output += chunk + }) + + process.on('close', exit => { + expect(semver.valid(output.trim())).toBeTruthy() + expect(exit).toBe(0) + done() + }) + }) + test('Linting a file that has wrong host should display an error message and use exit code 1', done => { const process = childProcess.spawn('node', [ cliExecPath, diff --git a/packages/lockfile-lint/package.json b/packages/lockfile-lint/package.json index 9ccec4f..101e3e3 100644 --- a/packages/lockfile-lint/package.json +++ b/packages/lockfile-lint/package.json @@ -76,7 +76,8 @@ "eslint-plugin-standard": "^4.1.0", "jest": "29.6.2", "open-cli": "^7.2.0", - "prettier-standard": "16.4.1" + "prettier-standard": "16.4.1", + "semver": "^7.5.4" }, "jest": { "testEnvironment": "node",