From 042c986242e46bb55a852644fc4ebd9cd78c2a93 Mon Sep 17 00:00:00 2001 From: Georgiana-Elena Maxim Date: Tue, 23 Apr 2024 17:13:44 +0300 Subject: [PATCH] feat: [OSM-1040] added acceptance tests for pnpm --- package-lock.json | 32 +++++------ package.json | 4 +- test/acceptance/fake-server.ts | 1 + .../acceptance/snyk-test/all-projects.spec.ts | 56 ++++++++++++++++++- .../basic-test-all-languages.spec.ts | 47 +++++++++++++++- 5 files changed, 120 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index b13392c088..755fe74b76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,8 +73,8 @@ "snyk-gradle-plugin": "4.1.0", "snyk-module": "3.1.0", "snyk-mvn-plugin": "3.4.2", - "snyk-nodejs-lockfile-parser": "1.53.3", - "snyk-nodejs-plugin": "1.0.3", + "snyk-nodejs-lockfile-parser": "1.56.0", + "snyk-nodejs-plugin": "1.1.0", "snyk-nuget-plugin": "2.4.5", "snyk-php-plugin": "1.9.2", "snyk-policy": "^1.25.0", @@ -21318,9 +21318,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/snyk-nodejs-lockfile-parser": { - "version": "1.53.3", - "resolved": "https://registry.npmjs.org/snyk-nodejs-lockfile-parser/-/snyk-nodejs-lockfile-parser-1.53.3.tgz", - "integrity": "sha512-IHRPwAoXT2MvYOl8Yo4DUOee+6edHGBwzydV1XQCb1y6mzkeUbBNR5ocsSxjnJzV/u+Pu1UFM7Cc9dkzjVtPgw==", + "version": "1.56.0", + "resolved": "https://registry.npmjs.org/snyk-nodejs-lockfile-parser/-/snyk-nodejs-lockfile-parser-1.56.0.tgz", + "integrity": "sha512-/EaFDmCyCOSsvUsPzhp1A647S8C/Szd29I/wCCgg2zZr5X6URHT27wGXjijXEhb+IFI/94LvcKpSnmOsvulyCw==", "dependencies": { "@snyk/dep-graph": "^2.3.0", "@snyk/error-catalog-nodejs-public": "^5.16.0", @@ -21433,9 +21433,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/snyk-nodejs-plugin": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/snyk-nodejs-plugin/-/snyk-nodejs-plugin-1.0.3.tgz", - "integrity": "sha512-Qn8IZfXH4I/FmVw1NidNudAJudwDZOrBW62M6vec9jS1KQ8oBwF8Tu9W+wPV54gp2JomyRC9If7w8xrCorTQDw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/snyk-nodejs-plugin/-/snyk-nodejs-plugin-1.1.0.tgz", + "integrity": "sha512-KMMYtcvWs+yNJq9QuTyvkLCQeMIASVf2Pex7Pyv6xijIr/6l3lnb1E6aaE7J3vcdJ/eJNmHsaM3EJT4wLCbH4A==", "dependencies": { "@snyk/cli-interface": "^2.13.0", "@snyk/dep-graph": "^2.7.4", @@ -21445,7 +21445,7 @@ "lodash.isempty": "^4.4.0", "lodash.sortby": "^4.7.0", "micromatch": "4.0.2", - "snyk-nodejs-lockfile-parser": "^1.53.3", + "snyk-nodejs-lockfile-parser": "^1.56.0", "snyk-resolve-deps": "4.8.0" }, "engines": { @@ -40868,9 +40868,9 @@ } }, "snyk-nodejs-lockfile-parser": { - "version": "1.53.3", - "resolved": "https://registry.npmjs.org/snyk-nodejs-lockfile-parser/-/snyk-nodejs-lockfile-parser-1.53.3.tgz", - "integrity": "sha512-IHRPwAoXT2MvYOl8Yo4DUOee+6edHGBwzydV1XQCb1y6mzkeUbBNR5ocsSxjnJzV/u+Pu1UFM7Cc9dkzjVtPgw==", + "version": "1.56.0", + "resolved": "https://registry.npmjs.org/snyk-nodejs-lockfile-parser/-/snyk-nodejs-lockfile-parser-1.56.0.tgz", + "integrity": "sha512-/EaFDmCyCOSsvUsPzhp1A647S8C/Szd29I/wCCgg2zZr5X6URHT27wGXjijXEhb+IFI/94LvcKpSnmOsvulyCw==", "requires": { "@snyk/dep-graph": "^2.3.0", "@snyk/error-catalog-nodejs-public": "^5.16.0", @@ -40959,9 +40959,9 @@ } }, "snyk-nodejs-plugin": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/snyk-nodejs-plugin/-/snyk-nodejs-plugin-1.0.3.tgz", - "integrity": "sha512-Qn8IZfXH4I/FmVw1NidNudAJudwDZOrBW62M6vec9jS1KQ8oBwF8Tu9W+wPV54gp2JomyRC9If7w8xrCorTQDw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/snyk-nodejs-plugin/-/snyk-nodejs-plugin-1.1.0.tgz", + "integrity": "sha512-KMMYtcvWs+yNJq9QuTyvkLCQeMIASVf2Pex7Pyv6xijIr/6l3lnb1E6aaE7J3vcdJ/eJNmHsaM3EJT4wLCbH4A==", "requires": { "@snyk/cli-interface": "^2.13.0", "@snyk/dep-graph": "^2.7.4", @@ -40971,7 +40971,7 @@ "lodash.isempty": "^4.4.0", "lodash.sortby": "^4.7.0", "micromatch": "4.0.2", - "snyk-nodejs-lockfile-parser": "^1.53.3", + "snyk-nodejs-lockfile-parser": "^1.56.0", "snyk-resolve-deps": "4.8.0" }, "dependencies": { diff --git a/package.json b/package.json index f8fe5095a3..b227adb607 100644 --- a/package.json +++ b/package.json @@ -121,8 +121,8 @@ "snyk-gradle-plugin": "4.1.0", "snyk-module": "3.1.0", "snyk-mvn-plugin": "3.4.2", - "snyk-nodejs-lockfile-parser": "1.53.3", - "snyk-nodejs-plugin": "1.0.3", + "snyk-nodejs-lockfile-parser": "1.56.0", + "snyk-nodejs-plugin": "1.1.0", "snyk-nuget-plugin": "2.4.5", "snyk-php-plugin": "1.9.2", "snyk-policy": "^1.25.0", diff --git a/test/acceptance/fake-server.ts b/test/acceptance/fake-server.ts index 71c20ce9ff..88c6036f95 100644 --- a/test/acceptance/fake-server.ts +++ b/test/acceptance/fake-server.ts @@ -13,6 +13,7 @@ const featureFlagDefaults = (): Map => { ['cliFailFast', false], ['iacIntegratedExperience', false], ['containerCliAppVulnsEnabled', true], + ['enablePnpmCli', false], ]); }; diff --git a/test/jest/acceptance/snyk-test/all-projects.spec.ts b/test/jest/acceptance/snyk-test/all-projects.spec.ts index 3e85f0219b..6bf471534e 100644 --- a/test/jest/acceptance/snyk-test/all-projects.spec.ts +++ b/test/jest/acceptance/snyk-test/all-projects.spec.ts @@ -1,4 +1,7 @@ -import { createProjectFromWorkspace } from '../../util/createProject'; +import { + createProjectFromFixture, + createProjectFromWorkspace, +} from '../../util/createProject'; import { runSnykCLI } from '../../util/runSnykCLI'; import { fakeServer } from '../../../acceptance/fake-server'; import { getServerPort } from '../../util/getServerPort'; @@ -226,4 +229,55 @@ describe('snyk test --all-projects (mocked server only)', () => { expect(stdout).toMatch('Package manager: composer'); expect(stderr).toEqual(''); }); + + test('`test node workspaces --all-projects`', async () => { + server.setFeatureFlag('enablePnpmCli', false); + const project = await createProjectFromFixture('workspace-multi-type'); + + const { code, stdout } = await runSnykCLI('test --all-projects', { + cwd: project.path(), + env, + }); + + const backendRequests = server.popRequests(1); + expect(backendRequests).toHaveLength(1); + + backendRequests.forEach((req) => { + expect(req.method).toEqual('POST'); + expect(req.headers['x-snyk-cli-version']).not.toBeUndefined(); + expect(req.url).toMatch('/api/v1/test'); + }); + + expect(code).toEqual(0); + + expect(stdout).toMatch('Package manager: npm'); + expect(stdout).toMatch('Package manager: yarn'); + expect(stdout).not.toMatch('Package manager: pnpm'); + }); + + test('`test node workspaces --all-projects with `enablePnpmCli` feature flag`', async () => { + server.setFeatureFlag('enablePnpmCli', true); + + const project = await createProjectFromFixture('workspace-multi-type'); + + const { code, stdout } = await runSnykCLI('test --all-projects', { + cwd: project.path(), + env, + }); + + const backendRequests = server.popRequests(1); + expect(backendRequests).toHaveLength(1); + + backendRequests.forEach((req) => { + expect(req.method).toEqual('POST'); + expect(req.headers['x-snyk-cli-version']).not.toBeUndefined(); + expect(req.url).toMatch('/api/v1/test'); + }); + + expect(code).toEqual(0); + + expect(stdout).toMatch('Package manager: npm'); + expect(stdout).toMatch('Package manager: yarn'); + expect(stdout).toMatch('Package manager: pnpm'); + }); }); diff --git a/test/jest/acceptance/snyk-test/basic-test-all-languages.spec.ts b/test/jest/acceptance/snyk-test/basic-test-all-languages.spec.ts index e9f04161fa..d2c3dd26ff 100644 --- a/test/jest/acceptance/snyk-test/basic-test-all-languages.spec.ts +++ b/test/jest/acceptance/snyk-test/basic-test-all-languages.spec.ts @@ -1,4 +1,7 @@ -import { createProjectFromWorkspace } from '../../util/createProject'; +import { + createProjectFromFixture, + createProjectFromWorkspace, +} from '../../util/createProject'; import { runSnykCLI } from '../../util/runSnykCLI'; import { fakeServer } from '../../../acceptance/fake-server'; import { runCommand } from '../../util/runCommand'; @@ -408,4 +411,46 @@ describe('`snyk test` of basic projects for each language/ecosystem', () => { console.warn('sbt not found, skipping test!'); } }); + + test('run `snyk test` on a pnpm project', async () => { + const project = await createProjectFromFixture('pnpm-app'); + + const { code } = await runSnykCLI('test -d', { + cwd: project.path(), + env, + }); + + expect(code).toEqual(0); + }); + + test('run `snyk test` on a pnpm project without `enablePnpmCli` feature flag enabled', async () => { + server.setFeatureFlag('enablePnpmCli', false); + const project = await createProjectFromFixture('pnpm-app'); + + const { code, stdout } = await runSnykCLI('test -d', { + cwd: project.path(), + env, + }); + + expect(stdout).toMatch('Target file: package.json'); + expect(stdout).toMatch('Package manager: npm'); + + expect(code).toEqual(0); + }); + + test('run `snyk test` on a pnpm project with `enablePnpmCli` feature flag enabled', async () => { + server.setFeatureFlag('enablePnpmCli', true); + + const project = await createProjectFromFixture('pnpm-app'); + + const { code, stdout } = await runSnykCLI('test -d', { + cwd: project.path(), + env, + }); + + expect(stdout).toMatch('Target file: pnpm-lock.yaml'); + expect(stdout).toMatch('Package manager: pnpm'); + + expect(code).toEqual(0); + }); });