From 25b201c32bb6188c61e620925d52d75477a08d22 Mon Sep 17 00:00:00 2001 From: Jahed Ahmed <jahed@snyk.io> Date: Thu, 12 Aug 2021 12:35:56 +0000 Subject: [PATCH] test: use common test setup createCLITestHarness has some regressions like using the current working directory (via path.resolve with a relative path) which we know changes due to misuse for process.chdir in other tests. --- .../snyk-test-all-projects-exit-codes.spec.ts | 15 ++++++++----- test/jest/util/snyk-cli-test-harness.ts | 22 ------------------- 2 files changed, 10 insertions(+), 27 deletions(-) delete mode 100644 test/jest/util/snyk-cli-test-harness.ts diff --git a/test/jest/acceptance/snyk-test-all-projects-exit-codes.spec.ts b/test/jest/acceptance/snyk-test-all-projects-exit-codes.spec.ts index 5d8819051e..a99b5c1b03 100644 --- a/test/jest/acceptance/snyk-test-all-projects-exit-codes.spec.ts +++ b/test/jest/acceptance/snyk-test-all-projects-exit-codes.spec.ts @@ -1,14 +1,17 @@ -import { createCLITestHarness } from '../util/snyk-cli-test-harness'; +import { createProject } from '../util/createProject'; +import { runSnykCLI } from '../util/runSnykCLI'; jest.setTimeout(1000 * 60 * 5); describe('snyk test -all-projects with one project that has errors', () => { describe('and another that has issues (vulnerabilities)', () => { it('should exit with exit code 1', async () => { - const test = createCLITestHarness( + const project = await createProject( 'snyk-test-all-projects-exit-codes/project-with-issues-and-project-with-error', ); - const { code, stderr } = await test.test(); + const { code, stderr } = await runSnykCLI(`test --all-projects`, { + cwd: project.path(), + }); expect(code).toEqual(1); expect(stderr).toContain( '1/2 potential projects failed to get dependencies. Run with `-d` for debug output.', @@ -19,10 +22,12 @@ describe('snyk test -all-projects with one project that has errors', () => { describe('and another has no issues (vulnerabilities)', () => { // note: actually, this is a bug. It should really have exit code 2, but that is a big change that we need to do it('should exit with exit code 0', async () => { - const test = createCLITestHarness( + const project = await createProject( 'snyk-test-all-projects-exit-codes/project-with-no-issues-and-project-with-error', ); - const { code, stderr } = await test.test(); + const { code, stderr } = await runSnykCLI(`test --all-projects`, { + cwd: project.path(), + }); expect(code).toEqual(0); expect(stderr).toContain( '1/2 potential projects failed to get dependencies. Run with `-d` for debug output.', diff --git a/test/jest/util/snyk-cli-test-harness.ts b/test/jest/util/snyk-cli-test-harness.ts deleted file mode 100644 index 1d7992ec2a..0000000000 --- a/test/jest/util/snyk-cli-test-harness.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { runSnykCLI } from './runSnykCLI'; -import { RunCommandResult } from './runCommand'; - -import * as path from 'path'; - -type CLITestHarness = { - path: string; - test: () => Promise<RunCommandResult>; -}; - -const createCLITestHarness = (fixture: string): CLITestHarness => { - const fixturePath = path.resolve('test/fixtures', fixture); - return { - path: fixturePath, - test: () => - runSnykCLI(`test --all-projects`, { - cwd: fixturePath, - }), - }; -}; - -export { CLITestHarness, createCLITestHarness };