Skip to content

Commit

Permalink
feat: [OSM-1040] added acceptance tests for pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
gemaxim committed May 10, 2024
1 parent 7c7c1ab commit 042c986
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 20 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const featureFlagDefaults = (): Map<string, boolean> => {
['cliFailFast', false],
['iacIntegratedExperience', false],
['containerCliAppVulnsEnabled', true],
['enablePnpmCli', false],
]);
};

Expand Down
56 changes: 55 additions & 1 deletion test/jest/acceptance/snyk-test/all-projects.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
});
});
47 changes: 46 additions & 1 deletion test/jest/acceptance/snyk-test/basic-test-all-languages.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 042c986

Please sign in to comment.