Skip to content

Commit

Permalink
test(utils): add coverage for getEnvironmentType
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-skryl committed Oct 15, 2024
1 parent 9b77c9d commit 5bc5d97
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/utils/src/lib/reports/environment-type.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import { getEnvironmentType } from './environment-type';

describe('getEnvironmentType', () => {
it.each([
['TERM_PROGRAM', 'vscode', 'vscode'],
['GITHUB_ACTIONS', 'true', 'github'],
['GITLAB_CI', 'true', 'gitlab'],
])(
'should return the environment type when %s environment variable is set',
(envVarName, envVarValue, expected) => {
// reset potentially interfering environment variables
vi.stubEnv('TERM_PROGRAM', '');
vi.stubEnv('GITHUB_ACTIONS', 'false');
vi.stubEnv('GITLAB_CI', 'false');

vi.stubEnv(envVarName, envVarValue);
expect(getEnvironmentType()).toBe(expected);
},
);

it('should return "other" when no expected environment variables are set', () => {
// reset potentially interfering environment variables
vi.stubEnv('TERM_PROGRAM', '');
vi.stubEnv('GITHUB_ACTIONS', 'false');
vi.stubEnv('GITLAB_CI', 'false');

expect(getEnvironmentType()).toBe('other');
});
});

0 comments on commit 5bc5d97

Please sign in to comment.