Skip to content

Commit

Permalink
chore(ci): test v2 against jest acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahed Ahmed committed Apr 26, 2022
1 parent b7666de commit 2642da1
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 16 deletions.
66 changes: 51 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ jobs:
unset SNYK_API_KEY
shellspec -f d -e REGRESSION_TEST=1
test-windows:
parameters:
test_snyk_command:
type: string
executor: win/default
working_directory: C:\Users\circleci\snyk
steps:
Expand All @@ -321,13 +324,16 @@ jobs:
npm_cache_directory: ~\AppData\Local\npm-cache
- run:
name: Configuring artifact
command: C:\Users\circleci\snyk\binary-releases\snyk-win.exe config set "api=$env:SNYK_API_KEY"
command: << parameters.test_snyk_command >> config set "api=$env:SNYK_API_KEY"
- run:
name: Testing artifact
command: npm run test:acceptance
command: npm run test:acceptance -- --selectProjects snyk
environment:
TEST_SNYK_COMMAND: C:\Users\circleci\snyk\binary-releases\snyk-win.exe
TEST_SNYK_COMMAND: << parameters.test_snyk_command >>
test-macos:
parameters:
test_snyk_command:
type: string
executor: macos
working_directory: /Users/distiller/snyk
steps:
Expand All @@ -341,13 +347,16 @@ jobs:
npm_cache_directory: /Users/distiller/.npm
- run:
name: Configuring artifact
command: /Users/distiller/snyk/binary-releases/snyk-macos config set "api=${SNYK_API_KEY}"
command: << parameters.test_snyk_command >> config set "api=${SNYK_API_KEY}"
- run:
name: Testing artifact
command: npm run test:acceptance
command: npm run test:acceptance -- --selectProjects snyk
environment:
TEST_SNYK_COMMAND: /Users/distiller/snyk/binary-releases/snyk-macos
TEST_SNYK_COMMAND: << parameters.test_snyk_command >>
test-linux:
parameters:
test_snyk_command:
type: string
executor: linux
working_directory: /home/circleci/snyk
steps:
Expand All @@ -364,12 +373,12 @@ jobs:
npm_cache_directory: /home/circleci/.npm
- run:
name: Configuring artifact
command: /home/circleci/snyk/binary-releases/snyk-linux config set "api=${SNYK_API_KEY}"
command: << parameters.test_snyk_command >> config set "api=${SNYK_API_KEY}"
- run:
name: Testing artifact
command: npm run test:acceptance
command: npm run test:acceptance -- --selectProjects snyk
environment:
TEST_SNYK_COMMAND: /home/circleci/snyk/binary-releases/snyk-linux
TEST_SNYK_COMMAND: << parameters.test_snyk_command >>
test-linux-arm64:
executor: linux-arm64
working_directory: /home/circleci/snyk
Expand Down Expand Up @@ -687,16 +696,19 @@ workflows:
context: nodejs-install
requires:
- Build Artifacts
test_snyk_command: C:\Users\circleci\snyk\binary-releases\snyk-win.exe
- test-macos:
name: Acceptance Tests (snyk-macos)
context: nodejs-install
requires:
- Build Artifacts
test_snyk_command: /Users/distiller/snyk/binary-releases/snyk-macos
- test-linux:
name: Acceptance Tests (snyk-linux)
context: nodejs-install
requires:
- Build Artifacts
test_snyk_command: /home/circleci/snyk/binary-releases/snyk-linux
- test-linux-arm64:
name: Acceptance Tests (snyk-linux-arm64)
context: nodejs-install
Expand Down Expand Up @@ -744,25 +756,49 @@ workflows:
pattern: '^.*v2.*$'
value: << pipeline.git.branch >>
jobs:
- install:
name: Install Dependencies (npm)
- v2-build-artifacts:
name: Build Artifacts
name: Build Artifacts (v2)
- v2-test-linux-amd64:
name: Integration Tests (linux/amd64)
requires:
- Build Artifacts
- Build Artifacts (v2)
- v2-test-proxy-linux-amd64:
name: Proxy Integration Tests (linux/amd64)
requires:
- Build Artifacts
- Build Artifacts (v2)
- v2-test-darwin-amd64:
name: Integration Tests (darwin/amd64)
requires:
- Build Artifacts
- Build Artifacts (v2)
- v2-test-windows-amd64:
name: Integration Tests (windows/amd64)
requires:
- Build Artifacts
- Build Artifacts (v2)
- v2-test-proxy-windows-amd64:
name: Proxy Integration Tests (windows/amd64)
requires:
- Build Artifacts
- Build Artifacts (v2)
# Tests for backwards compatibility with CLIv1
- test-linux:
name: Jest Acceptance Tests (linux/amd64)
context: nodejs-install
requires:
- Build Artifacts (v2)
- Install Dependencies (npm)
test_snyk_command: /home/circleci/snyk/cliv2/bin/snyk_linux_amd64
- test-windows:
name: Jest Acceptance Tests (windows/amd64)
context: nodejs-install
requires:
- Build Artifacts (v2)
- Install Dependencies (npm)
test_snyk_command: C:\Users\circleci\snyk\cliv2\bin\snyk_windows_amd64.exe
- test-macos:
name: Jest Acceptance Tests (darwin/amd64)
context: nodejs-install
requires:
- Build Artifacts (v2)
- Install Dependencies (npm)
test_snyk_command: /Users/distiller/snyk/cliv2/bin/snyk_darwin_amd64
8 changes: 8 additions & 0 deletions test/jest/acceptance/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import {
createProjectFromWorkspace,
} from '../util/createProject';
import { runSnykCLI } from '../util/runSnykCLI';
import { isCLIV2 } from '../util/isCLIV2';

jest.setTimeout(1000 * 30);

describe('analytics module', () => {
if (isCLIV2()) {
// eslint-disable-next-line jest/no-focused-tests
it.only('CLIv2 not yet supported', () => {
console.warn('Skipping test as CLIv2 does not support it yet.');
});
}

let server;
let env: Record<string, string>;

Expand Down
8 changes: 8 additions & 0 deletions test/jest/acceptance/cli-args.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UnsupportedOptionCombinationError } from '../../../src/lib/errors/unsup
import { runSnykCLI } from '../util/runSnykCLI';
import { fakeServer } from '../../acceptance/fake-server';
import { createProject } from '../util/createProject';
import { isCLIV2 } from '../util/isCLIV2';

const isWindows =
require('os-name')()
Expand All @@ -12,6 +13,13 @@ const isWindows =
jest.setTimeout(1000 * 60 * 5);

describe('cli args', () => {
if (isCLIV2()) {
// eslint-disable-next-line jest/no-focused-tests
it.only('CLIv2 not yet supported', () => {
console.warn('Skipping test as CLIv2 does not support it yet.');
});
}

let server;
let env: Record<string, string>;

Expand Down
8 changes: 8 additions & 0 deletions test/jest/acceptance/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { fakeServer, FakeServer } from '../../acceptance/fake-server';
import { createProjectFromWorkspace } from '../util/createProject';
import { getFixturePath } from '../util/getFixturePath';
import { runSnykCLI } from '../util/runSnykCLI';
import { isCLIV2 } from '../util/isCLIV2';

jest.setTimeout(1000 * 30);

describe('https', () => {
if (isCLIV2()) {
// eslint-disable-next-line jest/no-focused-tests
it.only('CLIv2 not yet supported', () => {
console.warn('Skipping test as CLIv2 does not support it yet.');
});
}

let server: FakeServer;
let env: Record<string, string>;

Expand Down
8 changes: 7 additions & 1 deletion test/jest/acceptance/iac/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export async function run(
const child = exec(
cmd.trim().replace(/^snyk/, snykCommand),
{
env,
env: {
// Home and cache env vars for CLIv2 cache directory
HOME: process.env.HOME,
LocalAppData: process.env.LOCALAPPDATA,
XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
...env,
},
cwd: cwd ?? join(root, 'test/fixtures'),
},
function(err, stdout, stderr) {
Expand Down
2 changes: 2 additions & 0 deletions test/jest/acceptance/iac/iac-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { startMockServer } from './helpers';

const IAC_CLI_OUTPUT_FF = 'iacCliOutput';

jest.setTimeout(1000 * 30);

describe('iac test output', () => {
let server: FakeServer;
let run: (
Expand Down
8 changes: 8 additions & 0 deletions test/jest/acceptance/iac/update-exclude-policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import * as fs from 'fs';
import * as rimraf from 'rimraf';
import * as path from 'path';
import { findAndLoadPolicy } from '../../../../src/lib/policy';
import { isCLIV2 } from '../../util/isCLIV2';

jest.setTimeout(50000);

describe('iac update-exclude-policy', () => {
if (isCLIV2()) {
// eslint-disable-next-line jest/no-focused-tests
it.only('CLIv2 not yet supported', () => {
console.warn('Skipping test as CLIv2 does not support it yet.');
});
}

let run: typeof Run;
let teardown: () => void;

Expand Down
8 changes: 8 additions & 0 deletions test/jest/acceptance/proxy-behavior.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { runSnykCLI } from '../util/runSnykCLI';
import { isCLIV2 } from '../util/isCLIV2';

const fakeServerPort = 12345;
const SNYK_API_HTTPS = 'https://snyk.io/api/v1';
Expand All @@ -8,6 +9,13 @@ const FAKE_HTTP_PROXY = `http://localhost:${fakeServerPort}`;
jest.setTimeout(1000 * 60 * 1);

describe('Proxy configuration behavior', () => {
if (isCLIV2()) {
// eslint-disable-next-line jest/no-focused-tests
it.only('CLIv2 not yet supported', () => {
console.warn('Skipping test as CLIv2 does not support it yet.');
});
}

describe('*_PROXY against HTTPS host', () => {
it('tries to connect to the HTTPS_PROXY when HTTPS_PROXY is set', async () => {
const { code, stderr } = await runSnykCLI(`woof -d`, {
Expand Down
6 changes: 6 additions & 0 deletions test/jest/util/isCLIV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const isCLIV2 = (): boolean => {
return !!(
process.env.TEST_SNYK_COMMAND &&
process.env.TEST_SNYK_COMMAND.includes('cliv2')
);
};

0 comments on commit 2642da1

Please sign in to comment.