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 c9519d2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/acceptance/fake-server.ts
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
@@ -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
@@ -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 c9519d2

Please sign in to comment.