Skip to content

Commit 6cab26b

Browse files
test: add unit tests for TEST_SNYK_IGNORE_LIST in createJestConfig
Added tests to verify handling of `TEST_SNYK_IGNORE_LIST` environment variable, ensuring proper merging of patterns into `testPathIgnorePatterns`. Includes cases for empty, single, and multiple comma-separated values.
1 parent dd8cc8e commit 6cab26b

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

test/jest/acceptance/resilience.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,55 @@ interface ResilienceScenario {
5757
skip?: string[]; // Commands to skip for this scenario (not yet consistent)
5858
}
5959

60+
describe('TEST_SNYK_IGNORE_LIST → testPathIgnorePatterns', () => {
61+
// eslint-disable-next-line @typescript-eslint/no-require-imports
62+
const { createJestConfig } = require('../../createJestConfig') as {
63+
createJestConfig: (config?: object) => {
64+
testPathIgnorePatterns: string[];
65+
};
66+
};
67+
let previousIgnoreList: string | undefined;
68+
69+
beforeEach(() => {
70+
previousIgnoreList = process.env.TEST_SNYK_IGNORE_LIST;
71+
});
72+
73+
afterEach(() => {
74+
if (previousIgnoreList === undefined) {
75+
delete process.env.TEST_SNYK_IGNORE_LIST;
76+
} else {
77+
process.env.TEST_SNYK_IGNORE_LIST = previousIgnoreList;
78+
}
79+
});
80+
81+
it('when unset or empty, does not add fragments from TEST_SNYK_IGNORE_LIST', () => {
82+
for (const value of [undefined as string | undefined, '']) {
83+
if (value === undefined) {
84+
delete process.env.TEST_SNYK_IGNORE_LIST;
85+
} else {
86+
process.env.TEST_SNYK_IGNORE_LIST = value;
87+
}
88+
const ignorePathPatterns = createJestConfig({}).testPathIgnorePatterns;
89+
expect(ignorePathPatterns).toContain('/node_modules/');
90+
expect(ignorePathPatterns).not.toContain('happy-path-one');
91+
}
92+
});
93+
94+
it('single comma-separated pattern is merged', () => {
95+
process.env.TEST_SNYK_IGNORE_LIST = 'happy-path-one';
96+
expect(createJestConfig({}).testPathIgnorePatterns).toContain(
97+
'happy-path-one',
98+
);
99+
});
100+
101+
it('two comma-separated patterns are merged', () => {
102+
process.env.TEST_SNYK_IGNORE_LIST = 'happy-path-a, happy-path-b';
103+
const ignorePathPatterns = createJestConfig({}).testPathIgnorePatterns;
104+
expect(ignorePathPatterns).toContain('happy-path-a');
105+
expect(ignorePathPatterns).toContain('happy-path-b');
106+
});
107+
});
108+
60109
const RESILIENCE_SCENARIOS: ResilienceScenario[] = [
61110
// Scenario 1
62111
{

0 commit comments

Comments
 (0)